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

Include Cargo rustc configuration in probe #157

Merged
merged 1 commit into from Aug 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 25 additions & 5 deletions build.rs
Expand Up @@ -67,17 +67,37 @@ fn compile_probe() -> Option<ExitStatus> {
let out_dir = env::var_os("OUT_DIR")?;
let probefile = Path::new(&out_dir).join("probe.rs");
fs::write(&probefile, PROBE).ok()?;
Command::new(rustc)
.stderr(Stdio::null())

// Make sure to pick up Cargo rustc configuration.
let mut cmd = env::var_os("CARGO_RUSTC_WRAPPER").map_or_else(
|| Command::new(&rustc),
|wrapper| {
let mut cmd = Command::new(wrapper);
// The wrapper's first argument should always be the path to rustc.
cmd.arg(&rustc);
cmd
},
);

cmd.stderr(Stdio::null())
.arg("--edition=2018")
.arg("--crate-name=anyhow_build")
.arg("--crate-type=lib")
.arg("--emit=metadata")
.arg("--out-dir")
.arg(out_dir)
.arg(probefile)
.status()
.ok()
.arg(probefile);

// If Cargo wants to set RUSTFLAGS, use that.
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
if !rustflags.is_empty() {
for arg in rustflags.split('\x1f') {
cmd.arg(arg);
}
}
}

cmd.status().ok()
}

fn rustc_minor_version() -> Option<u32> {
Expand Down