Skip to content

Commit

Permalink
Expost host and target sysroot to build scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
c272 committed Feb 14, 2024
1 parent 7bb7b53 commit 4b6b7af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/cargo/core/compiler/custom_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
//! [instructions]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
use super::{fingerprint, Context, Job, Unit, Work};
use crate::core::compiler::artifact;
use crate::core::compiler::{artifact, CompileKind};
use crate::core::compiler::context::Metadata;
use crate::core::compiler::job_queue::JobState;
use crate::core::{profiles::ProfileRoot, PackageId, Target};
Expand Down Expand Up @@ -316,6 +316,15 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
cmd.env("CARGO_TRIM_PATHS", trim_paths.to_string());
}

// Pass along sysroots used by the host/target.
let host_sysroot = &bcx.target_data.info(CompileKind::Host).sysroot;
let target_sysroot = match unit.kind {
CompileKind::Host => host_sysroot,
CompileKind::Target(_) => &bcx.target_data.info(unit.kind).sysroot
};
cmd.env("RUSTC_HOST_SYSROOT", host_sysroot);
cmd.env("RUSTC_TARGET_SYSROOT", target_sysroot);

// Be sure to pass along all enabled features for this package, this is the
// last piece of statically known information that we have.
for feat in &unit.features {
Expand Down
2 changes: 2 additions & 0 deletions src/doc/src/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ let out_dir = env::var("OUT_DIR").unwrap();
changed by editing `.cargo/config.toml`; see the documentation
about [cargo configuration][cargo-config] for more
information.
* `RUSTC_HOST_SYSROOT` --- The path to the `rustc` sysroot for the host.
* `RUSTC_TARGET_SYSROOT` --- The path to the `rustc` sysroot for the target.
* `CARGO_ENCODED_RUSTFLAGS` --- extra flags that Cargo invokes `rustc` with,
separated by a `0x1f` character (ASCII Unit Separator). See
[`build.rustflags`]. Note that since Rust 1.55, `RUSTFLAGS` is removed from
Expand Down

0 comments on commit 4b6b7af

Please sign in to comment.