Bug 1573566 - Make host libraries more like static libraries. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 16 Aug 2019 14:39:20 +0000
changeset 488590 83033ba2c21f69e8c98974f5802852b4c61ef30e
parent 488589 d55d48534b6f733b37116c886cc3771b09e54ffe
child 488591 8afcc2c2c508708b2383724bae10c407fba0f71d
push id36447
push usernbeleuzu@mozilla.com
push dateSat, 17 Aug 2019 21:50:27 +0000
treeherdermozilla-central@ce8742e6c77b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1573566
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1573566 - Make host libraries more like static libraries. r=froydnj HostLibrary is always an expand lib. HostRustLibrary is always a non-expand lib. But we currently rely on type checking to figure that out, rather than an attribute, like for StaticLibrary. Doing that simplifies existing and upcoming code. Differential Revision: https://phabricator.services.mozilla.com/D42250
python/mozbuild/mozbuild/backend/common.py
python/mozbuild/mozbuild/backend/recursivemake.py
python/mozbuild/mozbuild/frontend/data.py
--- a/python/mozbuild/mozbuild/backend/common.py
+++ b/python/mozbuild/mozbuild/backend/common.py
@@ -246,17 +246,17 @@ class CommonBackend(BuildBackend):
                 # This is slightly odd, but for consistency with the
                 # recursivemake backend we don't replace OBJ_SUFFIX if any
                 # object in a library has `no_pgo` set.
                 if lib.no_pgo_objs or lib.no_pgo:
                     no_pgo_objs.append(o)
 
         def expand(lib, recurse_objs, system_libs):
             if isinstance(lib, (HostLibrary, StaticLibrary)):
-                if not isinstance(lib, HostLibrary) and lib.no_expand_lib:
+                if lib.no_expand_lib:
                     static_libs.append(lib)
                     recurse_objs = False
                 elif recurse_objs:
                     add_objs(lib)
 
                 for l in lib.linked_libraries:
                     expand(l, recurse_objs, system_libs)
 
--- a/python/mozbuild/mozbuild/backend/recursivemake.py
+++ b/python/mozbuild/mozbuild/backend/recursivemake.py
@@ -26,48 +26,46 @@ from mozbuild.frontend.context import (
     RenamedSourcePath,
     SourcePath,
     ObjDirPath,
 )
 from .common import CommonBackend
 from ..frontend.data import (
     BaseLibrary,
     BaseProgram,
+    BaseRustLibrary,
     ChromeManifestEntry,
     ComputedFlags,
     ConfigFileSubstitution,
     ContextDerived,
     Defines,
     DirectoryTraversal,
     ExternalLibrary,
     FinalTargetFiles,
     FinalTargetPreprocessedFiles,
     GeneratedFile,
     GeneratedSources,
     HostDefines,
     HostGeneratedSources,
     HostLibrary,
     HostProgram,
-    HostRustLibrary,
     HostRustProgram,
     HostSimpleProgram,
     HostSources,
     InstallationTarget,
     JARManifest,
     Linkable,
     LocalInclude,
     LocalizedFiles,
     LocalizedPreprocessedFiles,
     ObjdirFiles,
     ObjdirPreprocessedFiles,
     PerSourceFlag,
     Program,
-    RustLibrary,
     HostSharedLibrary,
-    HostRustLibrary,
     RustProgram,
     RustTests,
     SharedLibrary,
     SimpleProgram,
     Sources,
     StaticLibrary,
     TestManifest,
     VariablePassthru,
@@ -674,17 +672,17 @@ class RecursiveMakeBackend(CommonBackend
             self._process_per_source_flag(obj, backend_file)
 
         elif isinstance(obj, ComputedFlags):
             self._process_computed_flags(obj, backend_file)
 
         elif isinstance(obj, InstallationTarget):
             self._process_installation_target(obj, backend_file)
 
-        elif isinstance(obj, (RustLibrary, HostRustLibrary)):
+        elif isinstance(obj, BaseRustLibrary):
             self.backend_input_files.add(obj.cargo_file)
             self._process_rust_library(obj, backend_file)
             # No need to call _process_linked_libraries, because Rust
             # libraries are self-contained objects at this point.
 
             # Hook the library into the compile graph.
             build_target = self._build_target_for_obj(obj)
             self._compile_graph[build_target]
@@ -1471,42 +1469,41 @@ class RecursiveMakeBackend(CommonBackend
                                                          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:
+            assert obj.KIND != 'host'
             backend_file.write_once('SHARED_LIBS += %s\n' %
                                     pretty_relpath(lib, lib.import_name))
 
         # We have to link any Rust libraries after all intermediate static
         # libraries have been listed to ensure that the Rust libraries are
         # searched after the C/C++ objects that might reference Rust symbols.
+        var = 'HOST_LIBS' if obj.KIND == 'host' else 'STATIC_LIBS'
         for lib in chain(
-                (l for l in static_libs if not isinstance(l, RustLibrary)),
-                (l for l in static_libs if isinstance(l, RustLibrary)),
+                (l for l in static_libs if not isinstance(l, BaseRustLibrary)),
+                (l for l in static_libs if isinstance(l, BaseRustLibrary)),
         ):
-            backend_file.write_once('STATIC_LIBS += %s\n' %
-                                    pretty_relpath(lib, lib.import_name))
+            backend_file.write_once('%s += %s\n' %
+                                    (var, pretty_relpath(lib, lib.import_name)))
 
         for lib in os_libs:
             if obj.KIND == 'target':
                 backend_file.write_once('OS_LIBS += %s\n' % lib)
             else:
                 backend_file.write_once('HOST_EXTRA_LIBS += %s\n' % lib)
 
         for lib in obj.linked_libraries:
             if not isinstance(lib, ExternalLibrary):
                 self._compile_graph[build_target].add(
                     self._build_target_for_obj(lib))
-            if isinstance(lib, HostRustLibrary):
-                backend_file.write_once('HOST_LIBS += %s\n' %
-                                        pretty_relpath(lib, lib.import_name))
 
         # Process library-based defines
         self._process_defines(obj.lib_defines, backend_file)
 
     def _process_final_target_files(self, obj, files, backend_file):
         target = obj.install_target
         path = mozpath.basedir(target, (
             'dist/bin',
--- a/python/mozbuild/mozbuild/frontend/data.py
+++ b/python/mozbuild/mozbuild/frontend/data.py
@@ -836,25 +836,27 @@ class ExternalStaticLibrary(StaticLibrar
 class ExternalSharedLibrary(SharedLibrary, ExternalLibrary):
     """Context derived container for shared libraries built by an external
     build system."""
 
 
 class HostLibrary(HostMixin, BaseLibrary):
     """Context derived container object for a host library"""
     KIND = 'host'
+    no_expand_lib = False
 
 
 class HostRustLibrary(HostLibrary, BaseRustLibrary):
     """Context derived container object for a host rust library"""
     KIND = 'host'
     TARGET_SUBST_VAR = 'RUST_HOST_TARGET'
     FEATURES_VAR = 'HOST_RUST_LIBRARY_FEATURES'
     LIB_FILE_VAR = 'HOST_RUST_LIBRARY_FILE'
     __slots__ = BaseRustLibrary.slots
+    no_expand_lib = True
 
     def __init__(self, context, basename, cargo_file, crate_type, dependencies,
                  features, target_dir):
         HostLibrary.__init__(self, context, basename)
         BaseRustLibrary.init(self, context, basename, cargo_file,
                              crate_type, dependencies, features, target_dir)