Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only set RUSTFLAGS when absolutely neccessary #887

Merged
merged 1 commit into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 9 additions & 3 deletions src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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");
}
}
}
Expand Down Expand Up @@ -207,16 +209,20 @@ 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())
// We can't get colored human and json messages from rustc as they are mutually exclusive,
// 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)
Expand Down