diff --git a/Changelog.md b/Changelog.md index d56ea103c..a9f3aa734 100644 --- a/Changelog.md +++ b/Changelog.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] * Re-export `__all__` for pure Rust projects in [#886](https://github.com/PyO3/maturin/pull/886) +* Stop setting `RUSTFLAGS` environment variable to an empty string [#887](https://github.com/PyO3/maturin/pull/887) ## [0.12.14] - 2022-04-25 diff --git a/src/compile.rs b/src/compile.rs index 153d41574..ef75dfd24 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -131,7 +131,7 @@ fn compile_target( .map(String::as_str) .collect(); - let mut rust_flags = env::var_os("RUSTFLAGS").unwrap_or_default(); + let mut rust_flags = env::var_os("RUSTFLAGS"); // We need to pass --bins / --lib to set the rustc extra args later // TODO: What do we do when there are multiple bin targets? @@ -143,7 +143,9 @@ fn compile_target( // We must only do this for libraries as it breaks binaries // For some reason this value is ignored when passed as rustc argument if context.target.is_musl_target() { - rust_flags.push(" -C target-feature=-crt-static"); + rust_flags + .get_or_insert_with(Default::default) + .push(" -C target-feature=-crt-static"); } } } @@ -207,9 +209,9 @@ fn compile_target( }; build.target = vec![zig_triple]; } + let mut build_command = build.build_command("rustc")?; build_command - .env("RUSTFLAGS", rust_flags) .args(&build_args) // We need to capture the json messages .stdout(Stdio::piped()) @@ -217,6 +219,10 @@ fn compile_target( // but forwarding stderr is still useful in case there some non-json error .stderr(Stdio::inherit()); + if let Some(flags) = rust_flags { + build_command.env("RUSTFLAGS", flags); + } + if let BridgeModel::BindingsAbi3(_, _) = bindings_crate { let is_pypy = python_interpreter .map(|p| p.interpreter_kind == InterpreterKind::PyPy)