Bug 1515843 - Stop building host static libraries. r=ted

The build system has skipped creating target static libraries for very
long, except in very specific cases.

We can actually do the same for host static libraries, for which we
don't even need the escape hatch to still allow to create static
libraries.

Depends on D15171

Differential Revision: https://phabricator.services.mozilla.com/D15172

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mike Hommey 2018-12-21 23:00:00 +00:00
parent a43e675e76
commit d3856a0bf1
5 changed files with 81 additions and 87 deletions

View File

@ -38,7 +38,7 @@ $(foreach var,$1,$(call print_var,$(var)))
endef
showtargs:
ifneq (,$(filter $(PROGRAM) $(HOST_PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_LIBRARY) $(LIBRARY) $(SHARED_LIBRARY),$(TARGETS)))
ifneq (,$(filter $(PROGRAM) $(HOST_PROGRAM) $(SIMPLE_PROGRAMS) $(LIBRARY) $(SHARED_LIBRARY),$(TARGETS)))
@echo --------------------------------------------------------------------------------
$(call print_vars,\
PROGRAM \
@ -112,7 +112,6 @@ showhost:
HOST_PROGRAM \
HOST_OBJS \
HOST_PROGOBJS \
HOST_LIBRARY \
)
INCLUDED_DEBUGMAKE_MK = 1

View File

@ -107,12 +107,6 @@ endif
endif
endif
ifndef HOST_LIBRARY
ifdef HOST_LIBRARY_NAME
HOST_LIBRARY := $(LIB_PREFIX)$(HOST_LIBRARY_NAME).$(LIB_SUFFIX)
endif
endif
ifdef FORCE_SHARED_LIB
ifdef MKSHLIB
@ -188,7 +182,7 @@ endif
ifdef COMPILE_ENVIRONMENT
ifndef TARGETS
TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_LIBRARY) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY)
TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_SHARED_LIBRARY)
endif
ifdef MOZ_PROFILE_GENERATE
@ -225,7 +219,6 @@ IMPORT_LIBRARY :=
REAL_LIBRARY :=
PROGRAM :=
SIMPLE_PROGRAMS :=
HOST_LIBRARY :=
HOST_SHARED_LIBRARY :=
HOST_PROGRAM :=
HOST_SIMPLE_PROGRAMS :=
@ -452,7 +445,7 @@ OBJ_TARGETS = $(OBJS) $(PROGOBJS) $(HOST_OBJS) $(HOST_PROGOBJS)
compile:: host target
host:: $(HOST_LIBRARY) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
host:: $(HOST_OBJS) $(HOST_PROGRAM) $(HOST_SIMPLE_PROGRAMS) $(HOST_RUST_PROGRAMS) $(HOST_RUST_LIBRARY_FILE) $(HOST_SHARED_LIBRARY)
target:: $(filter-out $(MOZBUILD_NON_DEFAULT_TARGETS),$(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(SIMPLE_PROGRAMS) $(RUST_LIBRARY_FILE) $(RUST_PROGRAMS))
@ -598,7 +591,7 @@ endif
$(HOST_PROGRAM): $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS) $(call mkdir_deps,$(DEPTH)/dist/host/bin)
$(REPORT_BUILD)
ifeq (_WINNT,$(GNU_CC)_$(HOST_OS_ARCH))
$(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $(HOST_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
ifdef MSMANIFEST_TOOL
@if test -f $@.manifest; then \
if test -f '$(srcdir)/$(notdir $@).manifest'; then \
@ -615,9 +608,9 @@ ifdef MSMANIFEST_TOOL
endif # MSVC with manifest tool
else
ifeq ($(HOST_CPP_PROG_LINK),1)
$(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_CXX) -o $@ $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
else
$(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $(HOST_PROGOBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_CC) -o $@ $(HOST_C_LDFLAGS) $(HOST_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
endif # HOST_CPP_PROG_LINK
endif
ifndef CROSS_COMPILE
@ -656,15 +649,15 @@ ifdef MOZ_POST_PROGRAM_COMMAND
$(MOZ_POST_PROGRAM_COMMAND) $@
endif
$(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): host_%.$(_OBJ_SUFFIX) $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
$(HOST_SIMPLE_PROGRAMS): host_%$(HOST_BIN_SUFFIX): $(HOST_LIBS) $(HOST_EXTRA_DEPS) $(GLOBAL_DEPS)
$(REPORT_BUILD)
ifeq (WINNT_,$(HOST_OS_ARCH)_$(GNU_CC))
$(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $< $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_LINKER) -NOLOGO -OUT:$@ -PDB:$(HOST_PDBFILE) $($(notdir $@)_OBJS) $(WIN32_EXE_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
else
ifneq (,$(HOST_CPPSRCS)$(USE_HOST_CXX))
$(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $< $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_CXX_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
else
$(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $< $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_CC) $(HOST_OUTOPTION)$@ $(HOST_C_LDFLAGS) $($(notdir $@)_OBJS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
endif
endif
ifndef CROSS_COMPILE
@ -687,18 +680,13 @@ ifeq ($(OS_ARCH),WINNT)
$(IMPORT_LIBRARY): $(SHARED_LIBRARY) ;
endif
$(HOST_LIBRARY): $(HOST_OBJS) Makefile
$(REPORT_BUILD)
$(RM) $@
$(HOST_AR) $(HOST_AR_FLAGS) $(HOST_OBJS)
$(HOST_SHARED_LIBRARY): $(HOST_OBJS) Makefile
$(HOST_SHARED_LIBRARY): Makefile
$(REPORT_BUILD)
$(RM) $@
ifdef _MSC_VER
$(HOST_LINKER) -NOLOGO -DLL -OUT:$@ $(HOST_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_LINKER) -NOLOGO -DLL -OUT:$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
else
$(HOST_CXX) $(HOST_OUTOPTION)$@ $(HOST_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
$(HOST_CXX) $(HOST_OUTOPTION)$@ $($(notdir $@)_OBJS) $(HOST_CXX_LDFLAGS) $(HOST_LDFLAGS) $(HOST_LIBS) $(HOST_EXTRA_LIBS)
endif
# On Darwin (Mac OS X), dwarf2 debugging uses debug info left in .o files,

View File

@ -251,8 +251,8 @@ class CommonBackend(BuildBackend):
no_pgo_objs.append(o)
def expand(lib, recurse_objs, system_libs):
if isinstance(lib, StaticLibrary):
if lib.no_expand_lib:
if isinstance(lib, (HostLibrary, StaticLibrary)):
if not isinstance(lib, HostLibrary) and lib.no_expand_lib:
static_libs.append(lib)
recurse_objs = False
elif recurse_objs:
@ -274,11 +274,11 @@ class CommonBackend(BuildBackend):
add_objs(input_bin)
system_libs = not isinstance(input_bin, StaticLibrary)
system_libs = not isinstance(input_bin, (HostLibrary, StaticLibrary))
for lib in input_bin.linked_libraries:
if isinstance(lib, RustLibrary):
continue
elif isinstance(lib, StaticLibrary):
elif isinstance(lib, (HostLibrary, StaticLibrary)):
expand(lib, True, system_libs)
elif isinstance(lib, SharedLibrary):
if lib not in seen_libs:
@ -293,10 +293,20 @@ class CommonBackend(BuildBackend):
return (objs, sorted(seen_pgo_gen_only_objs), no_pgo_objs, \
shared_libs, os_libs, static_libs)
def _make_list_file(self, objdir, objs, name):
def _make_list_file(self, kind, objdir, objs, name):
if not objs:
return None
list_style = self.environment.substs.get('EXPAND_LIBS_LIST_STYLE')
if kind == 'target':
list_style = self.environment.substs.get('EXPAND_LIBS_LIST_STYLE')
else:
# The host compiler is not necessarily the same kind as the target
# compiler, so we can't be sure EXPAND_LIBS_LIST_STYLE is the right
# style to use ; however, all compilers support the `list` type, so
# use that. That doesn't cause any practical problem because where
# it really matters to use something else than `list` is when
# linking tons of objects (because of command line argument limits),
# which only really happens for libxul.
list_style = 'list'
list_file_path = mozpath.join(objdir, name)
objs = [os.path.relpath(o, objdir) for o in objs]
if list_style == 'linkerscript':

View File

@ -695,7 +695,6 @@ class RecursiveMakeBackend(CommonBackend):
self._process_linked_libraries(obj, backend_file)
elif isinstance(obj, HostLibrary):
self._process_host_library(obj, backend_file)
self._process_linked_libraries(obj, backend_file)
elif isinstance(obj, HostSharedLibrary):
@ -1349,9 +1348,6 @@ class RecursiveMakeBackend(CommonBackend):
if libdef.output_category:
self._process_non_default_target(libdef, libdef.import_name, backend_file)
def _process_host_library(self, libdef, backend_file):
backend_file.write('HOST_LIBRARY_NAME = %s\n' % libdef.basename)
def _process_host_shared_library(self, libdef, backend_file):
backend_file.write('HOST_SHARED_LIBRARY = %s\n' % libdef.lib_name)
@ -1375,13 +1371,14 @@ class RecursiveMakeBackend(CommonBackend):
objs, pgo_gen_objs, no_pgo_objs, shared_libs, os_libs, static_libs = self._expand_libs(obj)
if obj.KIND == 'target':
obj_target = obj.name
if isinstance(obj, Program):
obj_target = self._pretty_path(obj.output_path, backend_file)
obj_target = obj.name
if isinstance(obj, Program):
obj_target = self._pretty_path(obj.output_path, backend_file)
profile_gen_objs = []
if obj.KIND == 'target':
is_unit_test = isinstance(obj, BaseProgram) and obj.is_unit_test
profile_gen_objs = []
doing_pgo = self.environment.substs.get('MOZ_PGO')
obj_suffix_change_needed = (self.environment.substs.get('GNU_CC') or
@ -1397,50 +1394,50 @@ class RecursiveMakeBackend(CommonBackend):
profile_gen_objs += ['%s.%s' % (mozpath.splitext(o)[0], 'i_o')
for o in pgo_gen_objs]
def write_obj_deps(target, objs_ref, pgo_objs_ref):
if pgo_objs_ref:
backend_file.write('ifdef MOZ_PROFILE_GENERATE\n')
backend_file.write('%s: %s\n' % (target, pgo_objs_ref))
backend_file.write('else\n')
backend_file.write('%s: %s\n' % (target, objs_ref))
backend_file.write('endif\n')
else:
backend_file.write('%s: %s\n' % (target, objs_ref))
def write_obj_deps(target, objs_ref, pgo_objs_ref):
if pgo_objs_ref:
backend_file.write('ifdef MOZ_PROFILE_GENERATE\n')
backend_file.write('%s: %s\n' % (target, pgo_objs_ref))
backend_file.write('else\n')
backend_file.write('%s: %s\n' % (target, objs_ref))
backend_file.write('endif\n')
else:
backend_file.write('%s: %s\n' % (target, objs_ref))
objs_ref = ' \\\n '.join(os.path.relpath(o, obj.objdir)
for o in objs)
pgo_objs_ref = ' \\\n '.join(os.path.relpath(o, obj.objdir)
for o in profile_gen_objs)
# Don't bother with a list file if we're only linking objects built
# in this directory or building a real static library. This
# accommodates clang-plugin, where we would otherwise pass an
# incorrect list file format to the host compiler as well as when
# creating an archive with AR, which doesn't understand list files.
if (objs == obj.objs and not isinstance(obj, StaticLibrary) or
isinstance(obj, StaticLibrary) and obj.no_expand_lib):
backend_file.write_once('%s_OBJS := %s\n' % (obj.name,
objs_ref))
if profile_gen_objs:
backend_file.write_once('%s_PGO_OBJS := %s\n' % (obj.name,
pgo_objs_ref))
write_obj_deps(obj_target, objs_ref, pgo_objs_ref)
elif not isinstance(obj, StaticLibrary):
list_file_path = '%s.list' % obj.name.replace('.', '_')
list_file_ref = self._make_list_file(obj.objdir, objs,
list_file_path)
backend_file.write_once('%s_OBJS := %s\n' %
(obj.name, list_file_ref))
backend_file.write_once('%s: %s\n' % (obj_target, list_file_path))
if profile_gen_objs:
pgo_list_file_path = '%s_pgo.list' % obj.name.replace('.', '_')
pgo_list_file_ref = self._make_list_file(obj.objdir,
profile_gen_objs,
pgo_list_file_path)
backend_file.write_once('%s_PGO_OBJS := %s\n' %
(obj.name, pgo_list_file_ref))
backend_file.write_once('%s: %s\n' % (obj_target,
pgo_list_file_path))
write_obj_deps(obj_target, objs_ref, pgo_objs_ref)
objs_ref = ' \\\n '.join(os.path.relpath(o, obj.objdir)
for o in objs)
pgo_objs_ref = ' \\\n '.join(os.path.relpath(o, obj.objdir)
for o in profile_gen_objs)
# Don't bother with a list file if we're only linking objects built
# in this directory or building a real static library. This
# accommodates clang-plugin, where we would otherwise pass an
# incorrect list file format to the host compiler as well as when
# creating an archive with AR, which doesn't understand list files.
if (objs == obj.objs and not isinstance(obj, (HostLibrary, StaticLibrary)) or
isinstance(obj, StaticLibrary) and obj.no_expand_lib):
backend_file.write_once('%s_OBJS := %s\n' % (obj.name,
objs_ref))
if profile_gen_objs:
backend_file.write_once('%s_PGO_OBJS := %s\n' % (obj.name,
pgo_objs_ref))
write_obj_deps(obj_target, objs_ref, pgo_objs_ref)
elif not isinstance(obj, (HostLibrary, StaticLibrary)):
list_file_path = '%s.list' % obj.name.replace('.', '_')
list_file_ref = self._make_list_file(obj.KIND, obj.objdir, objs,
list_file_path)
backend_file.write_once('%s_OBJS := %s\n' %
(obj.name, list_file_ref))
backend_file.write_once('%s: %s\n' % (obj_target, list_file_path))
if profile_gen_objs:
pgo_list_file_path = '%s_pgo.list' % obj.name.replace('.', '_')
pgo_list_file_ref = self._make_list_file(obj.KIND, obj.objdir,
profile_gen_objs,
pgo_list_file_path)
backend_file.write_once('%s_PGO_OBJS := %s\n' %
(obj.name, pgo_list_file_ref))
backend_file.write_once('%s: %s\n' % (obj_target,
pgo_list_file_path))
write_obj_deps(obj_target, objs_ref, pgo_objs_ref)
for lib in shared_libs:
backend_file.write_once('SHARED_LIBS += %s\n' %
@ -1458,7 +1455,7 @@ class RecursiveMakeBackend(CommonBackend):
if not isinstance(lib, ExternalLibrary):
self._compile_graph[build_target].add(
self._build_target_for_obj(lib))
if isinstance(lib, (HostLibrary, HostRustLibrary)):
if isinstance(lib, HostRustLibrary):
backend_file.write_once('HOST_LIBS += %s\n' %
pretty_relpath(lib, lib.import_name))

View File

@ -415,7 +415,7 @@ class TupBackend(CommonBackend):
shared_libs = self._lib_paths(backend_file.objdir, shared_libs)
list_file_name = '%s.list' % shlib.name.replace('.', '_')
list_file = self._make_list_file(backend_file.objdir, objs, list_file_name)
list_file = self._make_list_file(shlib.KIND, backend_file.objdir, objs, list_file_name)
rust_linked = [l for l in backend_file.shared_lib.linked_libraries
if isinstance(l, RustLibrary)]
@ -486,7 +486,7 @@ class TupBackend(CommonBackend):
static_libs += self._lib_paths(backend_file.objdir, rust_linked)
list_file_name = '%s.list' % prog.name.replace('.', '_')
list_file = self._make_list_file(backend_file.objdir, objs, list_file_name)
list_file = self._make_list_file(prog.KIND, backend_file.objdir, objs, list_file_name)
if isinstance(prog, SimpleProgram):
outputs = [prog.name]