Bug 1386371 - Disable LTO by default, but enable in automation. r?froydnj
MozReview-Commit-ID: 2DIY9ex3Mch
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1121,16 +1121,17 @@ js_option('--enable-release',
'options. This may slow down builds.')
@depends('--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)
# Linker detection
# ==============================================================
@depends(target)
def build_not_win_mac(target):
if target.kernel not in ('Darwin', 'WINNT'):
return True
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -857,16 +857,26 @@ endif # BUILD_VERBOSE_LOG
# aren't already present. This essentially restores the default behavior
# of cargo when running via `mach`.
ifdef MACH_STDOUT_ISATTY
ifeq (,$(findstring --color,$(cargo_build_flags)))
cargo_build_flags += --color=always
endif
endif
+# These flags are passed via `cargo rustc` and only apply to the final rustc
+# invocation (i.e., only the top-level crate, not its dependencies).
+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.)
@@ -934,17 +944,17 @@ endef
# This function is intended to be called by:
#
# $(call CARGO_BUILD,EXTRA_ENV_VAR1=X EXTRA_ENV_VAR2=Y ...)
#
# but, given the idiosyncracies of make, can also be called without arguments:
#
# $(call CARGO_BUILD)
define CARGO_BUILD
-$(call RUN_CARGO,build,$(1))
+$(call RUN_CARGO,rustc,$(1))
endef
define CARGO_CHECK
$(call RUN_CARGO,check,$(1))
endef
cargo_linker_env_var := CARGO_TARGET_$(RUST_TARGET_ENV_NAME)_LINKER
@@ -979,17 +989,17 @@ endif
# Assume any system libraries rustc links against are already in the target's LIBS.
#
# We need to run cargo unconditionally, because cargo is the only thing that
# has full visibility into how changes in Rust sources might affect the final
# build.
force-cargo-library-build:
$(REPORT_BUILD)
- $(call CARGO_BUILD,$(target_cargo_env_vars)) --lib $(cargo_target_flag) $(rust_features_flag)
+ $(call CARGO_BUILD,$(target_cargo_env_vars)) --lib $(cargo_target_flag) $(rust_features_flag) -- $(cargo_rustc_flags)
$(RUST_LIBRARY_FILE): force-cargo-library-build
force-cargo-library-check:
$(call CARGO_CHECK,$(target_cargo_env_vars)) --lib $(cargo_target_flag) $(rust_features_flag)
else
force-cargo-library-check:
@true
--- a/python/mozbuild/mozbuild/frontend/emitter.py
+++ b/python/mozbuild/mozbuild/frontend/emitter.py
@@ -475,17 +475,16 @@ class TreeMetadataEmitter(LoggingMixin):
'debug-assertions': True,
'codegen-units': 4,
'panic': 'abort',
}
else:
expected_profile = {
'opt-level': 2,
'rpath': False,
- 'lto': True,
'debug-assertions': False,
'panic': 'abort',
}
if profile != expected_profile:
raise SandboxValidationError(
'Cargo profile.%s for %s is incorrect' % (profile_name, libname),
context)
--- a/toolkit/library/gtest/rust/Cargo.toml
+++ b/toolkit/library/gtest/rust/Cargo.toml
@@ -37,11 +37,10 @@ rpath = false
lto = false
debug-assertions = true
codegen-units = 4
panic = "abort"
[profile.release]
opt-level = 2
rpath = false
-lto = true
debug-assertions = false
panic = "abort"
--- a/toolkit/library/rust/Cargo.toml
+++ b/toolkit/library/rust/Cargo.toml
@@ -35,11 +35,10 @@ rpath = false
lto = false
debug-assertions = true
codegen-units = 4
panic = "abort"
[profile.release]
opt-level = 2
rpath = false
-lto = true
debug-assertions = false
panic = "abort"