Bug 1411081 - Use opt-level=1 for rustc in default configuration; r?glandium draft
authorGregory Szorc <gps@mozilla.com>
Tue, 24 Oct 2017 16:48:58 -0700
changeset 686264 516c86e51e688414ef66dcdcd46c5e8a0d8a6bd8
parent 686263 5c88a73c97b14c6b6ce5578a0c42bee17e57c39e
child 737345 570d2a684a1a0b2013f54aacafc9e3014982def5
push id86146
push usergszorc@mozilla.com
push dateWed, 25 Oct 2017 16:57:28 +0000
reviewersglandium
bugs1411081
milestone58.0a1
Bug 1411081 - Use opt-level=1 for rustc in default configuration; 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 level, regardless of what other configure options are set. This includes the other potential values, "s" and "z." A side-effect of this change is that -Copt-level is now *always* specified by the build system. Before, it was only specified if the value was adjusted to 0 for --disable-optimize builds. MozReview-Commit-ID: 67KX5qScnFc
build/moz.configure/toolchain.configure
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1296,18 +1296,27 @@ 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')
-def rust_compiler_flags(moz_optimize, debug_rust, debug_symbols):
+js_option(env='RUSTC_OPT_LEVEL',
+          nargs=1,
+          help='Rust compiler optimization level (-C opt-level=%s)')
+
+# --enable-release kicks in full optimizations.
+imply_option('RUSTC_OPT_LEVEL', '2', when='--enable-release')
+
+@depends('RUSTC_OPT_LEVEL', debug_rust, '--enable-debug-symbols',
+         moz_optimize)
+def rust_compiler_flags(opt_level_option, debug_rust, debug_symbols,
+                        moz_optimize):
     optimize = moz_optimize.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
@@ -1316,18 +1325,20 @@ def rust_compiler_flags(moz_optimize, de
     # Code here derives various compiler options given other configure options.
     # The options defined here effectively override defaults specified in
     # Cargo.toml files.
 
     opt_level = None
     debug_assertions = None
     debug_info = None
 
-    if not optimize:
-        opt_level = '0'
+    if opt_level_option.origin != 'default':
+        opt_level = opt_level_option[0]
+    else:
+        opt_level = '1' if optimize else '0'
 
     # opt-level=0 implies -C debug-assertions, which may not be desired
     # unless Rust debugging is enabled.
     if opt_level == '0' and not debug_rust:
         debug_assertions = False
 
     if debug_symbols:
         debug_info = '2'