Skip to content

Commit 4b6b7af

Browse files
committed
Expost host and target sysroot to build scripts.
1 parent 7bb7b53 commit 4b6b7af

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/cargo/core/compiler/custom_build.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
//! [instructions]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
3333
3434
use super::{fingerprint, Context, Job, Unit, Work};
35-
use crate::core::compiler::artifact;
35+
use crate::core::compiler::{artifact, CompileKind};
3636
use crate::core::compiler::context::Metadata;
3737
use crate::core::compiler::job_queue::JobState;
3838
use crate::core::{profiles::ProfileRoot, PackageId, Target};
@@ -316,6 +316,15 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
316316
cmd.env("CARGO_TRIM_PATHS", trim_paths.to_string());
317317
}
318318

319+
// Pass along sysroots used by the host/target.
320+
let host_sysroot = &bcx.target_data.info(CompileKind::Host).sysroot;
321+
let target_sysroot = match unit.kind {
322+
CompileKind::Host => host_sysroot,
323+
CompileKind::Target(_) => &bcx.target_data.info(unit.kind).sysroot
324+
};
325+
cmd.env("RUSTC_HOST_SYSROOT", host_sysroot);
326+
cmd.env("RUSTC_TARGET_SYSROOT", target_sysroot);
327+
319328
// Be sure to pass along all enabled features for this package, this is the
320329
// last piece of statically known information that we have.
321330
for feat in &unit.features {

src/doc/src/reference/environment-variables.md

+2
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ let out_dir = env::var("OUT_DIR").unwrap();
392392
changed by editing `.cargo/config.toml`; see the documentation
393393
about [cargo configuration][cargo-config] for more
394394
information.
395+
* `RUSTC_HOST_SYSROOT` --- The path to the `rustc` sysroot for the host.
396+
* `RUSTC_TARGET_SYSROOT` --- The path to the `rustc` sysroot for the target.
395397
* `CARGO_ENCODED_RUSTFLAGS` --- extra flags that Cargo invokes `rustc` with,
396398
separated by a `0x1f` character (ASCII Unit Separator). See
397399
[`build.rustflags`]. Note that since Rust 1.55, `RUSTFLAGS` is removed from

0 commit comments

Comments
 (0)