Bug 1411081 - Derive Rust compiler flags in configure; r?glandium
Before this commit, RUSTFLAGS was derived in rules.mk by consulting
various variables set by configure. It isn't clear to me why things
are implemented this way. We don't appear to have moz.build level
overrides for Rust compiler flags. So there doesn't appear to be a
compelling reason why we can't derive these values in configure.
So, this commit ports the code for deriving default RUSTFLAGS from
rules.mk to toolchain.configure.
The port is pretty straightforward as far as the logic goes.
MozReview-Commit-ID: JhAE9Qlo8SK
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1293,16 +1293,64 @@ js_option('--enable-release',
def developer_options(value):
if not value:
return True
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):
+ 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
+ # 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 = None
+ debug_assertions = None
+ debug_info = None
+
+ if not optimize:
+ opt_level = '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'
+
+ flags = []
+
+ if opt_level is not None:
+ flags.append('-Copt-level=%s' % opt_level)
+ if debug_assertions is not None:
+ flags.append('-Cdebug-assertions=%s' %
+ ('yes' if debug_assertions else 'no'))
+ if debug_info is not None:
+ flags.append('-Cdebuginfo=%s' % debug_info)
+
+ return flags
+
+set_config('MOZ_RUST_DEFAULT_FLAGS', rust_compiler_flags)
+
# Linker detection
# ==============================================================
@depends(target)
def is_linker_option_enabled(target):
if target.kernel not in ('Darwin', 'WINNT', 'SunOS'):
return True
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -870,34 +870,17 @@ endif
cargo_rustc_flags = $(CARGO_RUSTCFLAGS)
ifndef DEVELOPER_OPTIONS
ifndef MOZ_DEBUG_RUST
# Enable link-time optimization for release builds.
cargo_rustc_flags += -C lto
endif
endif
-# 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 there's another axis that we'd
-# like to support: --{disable,enable}-optimize. Since that would be four
-# choices, and Cargo only supports two, we choose to enable various
-# optimization levels in our Cargo.toml files all the time, and override the
-# optimization level here, if necessary. (The Cargo.toml files already
-# specify debug-assertions appropriately for --{disable,enable}-debug.)
-default_rustflags =
-ifndef MOZ_OPTIMIZE
-default_rustflags = -C opt-level=0
-# Unfortunately, -C opt-level=0 implies -C debug-assertions, so we need
-# to explicitly disable them when MOZ_DEBUG_RUST is not set.
-ifndef MOZ_DEBUG_RUST
-default_rustflags += -C debug-assertions=no
-endif
-endif
-rustflags_override = RUSTFLAGS='$(default_rustflags) $(RUSTFLAGS)'
+rustflags_override = RUSTFLAGS='$(MOZ_RUST_DEFAULT_FLAGS) $(RUSTFLAGS)'
ifdef MOZ_MSVCBITS
# If we are building a MozillaBuild shell, we want to clear out the
# vcvars.bat environment variables for cargo builds. This is because
# a 32-bit MozillaBuild shell on a 64-bit machine will try to use
# the 32-bit compiler/linker for everything, while cargo/rustc wants
# to use the 64-bit linker for build.rs scripts. This conflict results
# in a build failure (see bug 1350001). So we clear out the environment
@@ -914,20 +897,16 @@ rust_unlock_unstable =
ifdef MOZ_RUST_SIMD
rust_unlock_unstable += RUSTC_BOOTSTRAP=1
endif
ifdef MOZ_USING_SCCACHE
sccache_wrap := RUSTC_WRAPPER='$(CCACHE)'
endif
-ifdef MOZ_DEBUG_SYMBOLS
-default_rustflags += -C debuginfo=2
-endif
-
# We use the + prefix to pass down the jobserver fds to cargo, but we
# don't use the prefix when make -n is used, so that cargo doesn't run
# in that case)
define RUN_CARGO
$(if $(findstring n,$(filter-out --%, $(MAKEFLAGS))),,+)env $(environment_cleaner) $(rust_unlock_unstable) $(rustflags_override) $(sccache_wrap) \
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
RUSTC=$(RUSTC) \
MOZ_SRC=$(topsrcdir) \