Bug 1350001 - Run cargo in a clean environment when running in a MozillaBuild shell. r?ted
This prevents the variables set in vcvars.bat from causing build failures when
cargo tries to process build scripts in an environment where the default rust
toolchain doesn't match the MozillaBuild shell (in terms of 32-bit or 64-bit).
MozReview-Commit-ID: 5VRnQToYUYf
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -916,17 +916,30 @@ rustflags = -C opt-level=0
# Unfortunately, -C opt-level=0 implies -C debug-assertions, so we need
# to explicitly disable them when MOZ_DEBUG is not set.
ifndef MOZ_DEBUG
rustflags += -C debug-assertions=no
endif
rustflags_override = RUSTFLAGS='$(rustflags)'
endif
-CARGO_BUILD = env $(rustflags_override) \
+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). Clearing out *just* the changes
+# from vcvars.bat is hard, so we just clear out the whole environment.
+environment_cleaner = -i
+else
+environment_cleaner =
+endif
+
+CARGO_BUILD = env $(environment_cleaner) $(rustflags_override) \
CARGO_TARGET_DIR=$(CARGO_TARGET_DIR) \
RUSTC=$(RUSTC) \
MOZ_DIST=$(ABS_DIST) \
LIBCLANG_PATH=$(MOZ_LIBCLANG_PATH) \
CLANG_PATH=$(MOZ_CLANG_PATH) \
PKG_CONFIG_ALLOW_CROSS=1 \
RUST_BACKTRACE=1 \
$(CARGO) build $(cargo_build_flags)