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

feat: Expost host and target sysroot to build scripts. #13443

Closed
wants to merge 1 commit into from
Closed
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
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,10 +32,10 @@
//! [instructions]: https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script

use super::{fingerprint, BuildRunner, Job, Unit, Work};
use crate::core::compiler::artifact;
use crate::core::compiler::build_runner::Metadata;
use crate::core::compiler::fingerprint::DirtyReason;
use crate::core::compiler::job_queue::JobState;
use crate::core::compiler::{artifact, CompileKind};
use crate::core::{profiles::ProfileRoot, PackageId, Target};
use crate::util::errors::CargoResult;
use crate::util::machine_message::{self, Message};
Expand Down Expand Up @@ -317,6 +317,15 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
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