Bug 1411081 - Use opt-level=1 for rustc for default builds; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Tue, 24 Oct 2017 16:48:58 -0700
changeset 685630 295161d8b756216e969923b713bd5862d4cdaa80
parent 685629 88a3dee5f1792dd4aa020c39970ae7ca26609031
child 737220 97461a5ff8705e89983690b9ab9c84f9e2652457
push id86007
push usergszorc@mozilla.com
push dateTue, 24 Oct 2017 23:50:58 +0000
Bug 1411081 - Use opt-level=1 for rustc for default builds; r?glandium As the data in the bug shows, the current default of opt-level=2 is several minutes slower at compiling than opt-level=1. This slows down builds significantly and the added benefits of running opt-level=2 for local development can't be justified for the common/default case. This commit changes the default for local builds from opt-level=2 to opt-level=1. --enable-release (what we use for builds shipped to users) will imply opt-level=2. --enable-optimize (the default) will use opt-level=1, and --disable-optimize will use opt-level=0. The RUSTC_OPT_LEVEL environment variable in mozconfigs can be used to set an explicit opt-level leval, regardless of what other configure options are set. This includes the other potential values, "s" and "z." MozReview-Commit-ID: 67KX5qScnFc
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1267,46 +1267,58 @@ def developer_options(value):
 add_old_configure_assignment('DEVELOPER_OPTIONS', developer_options)
 set_config('DEVELOPER_OPTIONS', developer_options)
 # Rust compiler flags
 # ===================
-@depends(moz_optimize, debug_rust, '--enable-debug-symbols')
+          nargs=1,
+          help='Rust compiler optimization level (-C opt-level=%s)')
+@depends('RUSTC_OPT_LEVEL', debug_rust, '--enable-debug-symbols',
+         '--enable-release', moz_optimize)
 @checking('for Rust compiler flags',
           callback=lambda x: ' '.join(x.flags))
-def rust_compiler_opts(moz_optimize, debug_rust, debug_symbols):
-    optimize = moz_optimize.optimize
+def rust_compiler_opts(opt_level_option, debug_rust, debug_symbols,
+                       release_option, moz_optimize):
     # Cargo currently supports only two interesting profiles for building:
     # development and release. Those map (roughly) to --enable-debug and
     # --disable-debug in Gecko, respectively.
     # But we'd also like to support an additional axis of control for
     # optimization level. Since Cargo only supports 2 profiles, we're in
     # a bit of a bind.
     # Code here derives various compiler options given other configure options.
     # The options defined here effectively override defaults specified in
     # Cargo.toml files.
     # opt-level=0 implies -C debug-assertions, which may not be desired
     # unless Rust debugging is enabled.
-    if debug_rust:
-        opt_level = '1'
-        debug_assertions = True
+    if opt_level_option.origin != 'default':
+        opt_level = opt_level_option[0]
-        if optimize:
+        if debug_rust and release_option:
+            die('--enable-rust-debug and --enable-release are mutually incompatible')
+        # Release builds get full optimizations.
+        if release_option:
             opt_level = '2'
+        elif moz_optimize.optimize:
+            opt_level = '1'
             opt_level = '0'
+    if debug_rust:
+        debug_assertions = True
+    else:
         debug_assertions = False
     if debug_symbols:
         debug_info = '2'
     elif debug_rust:
         debug_info = '1'
         debug_info = '0'