diff --git a/build/moz.configure/bindgen.configure b/build/moz.configure/bindgen.configure index 06ba0fdbefbf..0a823106c018 100644 --- a/build/moz.configure/bindgen.configure +++ b/build/moz.configure/bindgen.configure @@ -370,3 +370,13 @@ def bindgen_cflags(base_flags, extra_flags): set_config("BINDGEN_SYSTEM_FLAGS", bindgen_cflags) + + +# Force the target down to all bindgen callers, even those that may not +# read BINDGEN_SYSTEM_FLAGS some way or another. +@depends(bindgen_cflags) +def bindgen_extra_clang_args(flags): + return [f for f in flags or [] if f.startswith("--target=")] + + +set_config("BINDGEN_EXTRA_CLANG_ARGS", bindgen_extra_clang_args) diff --git a/build/moz.configure/rust.configure b/build/moz.configure/rust.configure index b2983974892c..b5083cd73928 100644 --- a/build/moz.configure/rust.configure +++ b/build/moz.configure/rust.configure @@ -611,6 +611,9 @@ set_define("MOZ_DEBUG_RUST", debug_rust) option(env="RUSTFLAGS", nargs=1, help="Rust compiler flags") set_config("RUSTFLAGS", depends("RUSTFLAGS")(lambda flags: flags)) +option(env="CARGOFLAGS", nargs=1, help="Flags to pass to cargo") +set_config("CARGOFLAGS", depends("CARGOFLAGS")(lambda flags: flags)) + # Rust compiler flags # ============================================================== @@ -954,3 +957,18 @@ def clippy_wrapper(build_env, host_os_arch): set_config("MOZ_CARGO_CLIPPY_WRAPPER", clippy_wrapper) + + +# Enable link-time optimization for release builds, but not when doing +# cross-language LTO. +# Never enable when sancov is enabled to work around https://github.com/rust-lang/rust/issues/90300. +# Never enable when coverage is enabled to work around https://github.com/rust-lang/rust/issues/90045. +set_config( + "RUST_LTO_ELIGIBLE", + True, + when=~developer_options + & ~debug_rust + & ~lto.rust_lto + & ~rust_sancov_flags + & ~code_coverage, +) diff --git a/config/makefiles/rust.mk b/config/makefiles/rust.mk index 0a7413d3eebf..eebada5a02ae 100644 --- a/config/makefiles/rust.mk +++ b/config/makefiles/rust.mk @@ -81,25 +81,15 @@ 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 +ifdef RUST_LTO_ELIGIBLE # Enable link-time optimization for release builds, but not when linking -# gkrust_gtest. And not when doing cross-language LTO. -ifndef MOZ_LTO_RUST_CROSS -# Never enable when sancov is enabled to work around https://github.com/rust-lang/rust/issues/90300. -ifeq (,$(RUST_SANCOV_FLAGS)) -# Never enable when coverage is enabled to work around https://github.com/rust-lang/rust/issues/90045. -ifndef MOZ_CODE_COVERAGE +# gkrust_gtest. ifeq (,$(findstring gkrust_gtest,$(RUST_LIBRARY_FILE))) -cargo_rustc_flags += -Clto$(if $(filter full,$(MOZ_LTO_RUST_CROSS)),=fat) +cargo_rustc_flags += -Clto endif # We need -Cembed-bitcode=yes for all crates when using -Clto. RUSTFLAGS += -Cembed-bitcode=yes endif -endif -endif -endif -endif ifdef CARGO_INCREMENTAL export CARGO_INCREMENTAL @@ -243,9 +233,7 @@ endef $(foreach san,ASAN TSAN UBSAN,$(eval $(call sanitizer_options,$(san)))) endif -# Force the target down to all bindgen callers, even those that may not -# read BINDGEN_SYSTEM_FLAGS some way or another. -export BINDGEN_EXTRA_CLANG_ARGS:=$(filter --target=%,$(BINDGEN_SYSTEM_FLAGS)) +export BINDGEN_EXTRA_CLANG_ARGS export CARGO_TARGET_DIR export RUSTFLAGS export RUSTC