Bug 1496853 - Enable link time optimization for rust in tup for --enable-release builds. r=mshal
authorChris Manchester <cmanchester@mozilla.com>
Mon, 08 Oct 2018 17:51:34 +0000
changeset 495724 e3d243f3ff07fa45ae97858db2e0ccf07822918f
parent 495723 d8ce6780e0f558c0360cbeaf2a183875ce38042e
child 495744 df860e79a6a3cc41712cfd86ffbd18cf84fce626
child 495746 7de7e0e7ed1ac3feeb34544a3fd5c891ee47c137
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs1496853
milestone64.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 1496853 - Enable link time optimization for rust in tup for --enable-release builds. r=mshal Differential Revision: https://phabricator.services.mozilla.com/D7951
python/mozbuild/mozbuild/backend/tup.py
--- a/python/mozbuild/mozbuild/backend/tup.py
+++ b/python/mozbuild/mozbuild/backend/tup.py
@@ -824,16 +824,22 @@ class TupBackend(CommonBackend):
             env['MOZ_AUTOMATION'] = os.environ['MOZ_AUTOMATION']
 
         return env
 
     def _gen_cargo_rules(self, obj,  build_plan, cargo_env, output_group):
         invocations = build_plan['invocations']
         processed = set()
 
+        # Enable link-time optimization for release builds.
+        cargo_library_flags = []
+        if (not obj.config.substs.get('DEVELOPER_OPTIONS') and
+            not obj.config.substs.get('MOZ_DEBUG_RUST')):
+            cargo_library_flags += ['-C', 'lto']
+
         rust_build_home = mozpath.join(self.environment.topobjdir,
                                        'toolkit/library/rust')
 
         def display_name(invocation):
             output_str = ''
             if invocation['outputs']:
                 outputs = [os.path.basename(f) for f in invocation['outputs']]
                 output_str = ' -> [%s]' % self._trim_outputs(outputs)
@@ -868,16 +874,24 @@ class TupBackend(CommonBackend):
             ]
             envvars = invocation.get('env')
             for k, v in itertools.chain(cargo_env.iteritems(),
                                         envvars.iteritems()):
                 command.append("%s=%s" % (k, cargo_quote(v)))
             command.append(invocation['program'])
             command.extend(cargo_quote(a.replace('dep-info,', ''))
                            for a in invocation['args'])
+
+            # This is equivalent to `cargo_rustc_flags` in the make backend,
+            # which are passed to the top-level crate's rustc invocation, in
+            # our case building the static lib.
+            if (invocation['target_kind'][0] == 'staticlib' and
+                obj.basename == shortname):
+                command += cargo_library_flags
+
             outputs = invocation['outputs']
 
             invocation['full-deps'] = set()
 
             if os.path.basename(invocation['program']) == 'build-script-build':
                 out_dir = invocation['env']['OUT_DIR']
                 for output in cargo_extra_outputs.get(shortname, []):
                     outputs.append(os.path.join(out_dir, output))