Skip to content

Commit d6b4a06

Browse files
author
Jon Gjengset
committed
Also set RUSTC_WORKSPACE_WRAPPER for build.rs
1 parent f927d2a commit d6b4a06

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
255255
} else {
256256
cmd.env_remove("RUSTC_WRAPPER");
257257
}
258+
cmd.env_remove("RUSTC_WORKSPACE_WRAPPER");
259+
if cx.bcx.ws.is_member(&unit.pkg) {
260+
if let Some(wrapper) = bcx.rustc().workspace_wrapper.as_ref() {
261+
cmd.env("RUSTC_WORKSPACE_WRAPPER", wrapper);
262+
}
263+
}
258264
cmd.env(
259265
"CARGO_ENCODED_RUSTFLAGS",
260266
bcx.rustflags_args(unit).join("\x1f"),

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ let out_dir = env::var("OUT_DIR").unwrap();
342342
use it as well.
343343
* `RUSTC_WRAPPER` — the `rustc` wrapper, if any, that Cargo is using.
344344
See [`build.rustc-wrapper`].
345+
* `RUSTC_WORKSPACE_WRAPPER` — the `rustc` wrapper, if any, that Cargo is
346+
using for workspace members. See
347+
[`build.rustc-workspace-wrapper`].
345348
* `RUSTC_LINKER` — The path to the linker binary that Cargo has resolved to use
346349
for the current target, if specified. The linker can be
347350
changed by editing `.cargo/config.toml`; see the documentation

tests/testsuite/build_script.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ fn custom_build_env_vars() {
119119
assert_eq!(rustdoc, "rustdoc");
120120
121121
assert!(env::var("RUSTC_WRAPPER").is_err());
122+
assert!(env::var("RUSTC_WORKSPACE_WRAPPER").is_err());
122123
123124
assert!(env::var("RUSTC_LINKER").is_err());
124125
@@ -250,6 +251,32 @@ fn custom_build_env_var_rustc_wrapper() {
250251
.run();
251252
}
252253

254+
#[cargo_test]
255+
fn custom_build_env_var_rustc_workspace_wrapper() {
256+
let wrapper = tools::echo_wrapper();
257+
let p = project()
258+
.file(
259+
"build.rs",
260+
r#"
261+
use std::env;
262+
263+
fn main() {{
264+
assert_eq!(
265+
env::var("RUSTC_WORKSPACE_WRAPPER").unwrap(),
266+
env::var("CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK").unwrap()
267+
);
268+
}}
269+
"#,
270+
)
271+
.file("src/lib.rs", "")
272+
.build();
273+
274+
p.cargo("check")
275+
.env("CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER", &wrapper)
276+
.env("CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK", &wrapper)
277+
.run();
278+
}
279+
253280
#[cargo_test]
254281
fn custom_build_env_var_rustc_linker() {
255282
if cross_compile::disabled() {

0 commit comments

Comments
 (0)