Skip to content
Draft
Changes from 1 commit
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: 11 additions & 0 deletions tests/testsuite/rustup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ fn real_rustc_wrapper(bin_dir: &Path, message: &str) -> PathBuf {
// The toolchain rustc needs to call the real rustc. In order to do that,
// it needs to restore or clear the RUSTUP environment variables so that
// if rustup is installed, it will call the correct rustc.
let rustup_toolchain_source_setup = match std::env::var_os("RUSTUP_TOOLCHAIN_SOURCE") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should be doing anything based on the rustup we are running in

See also #16131 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the risk of sounding like an excuse, I was following the example of the code just below this:

let rustup_toolchain_setup = match std::env::var_os("RUSTUP_TOOLCHAIN") {
Some(t) => format!(
".env(\"RUSTUP_TOOLCHAIN\", \"{}\")",
t.into_string().unwrap()
),
None => format!(".env_remove(\"RUSTUP_TOOLCHAIN\")"),
};

Should that following code be modified?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems suspicious and I'd like to better understand why we do this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, I'm willing to make changes not directly related #11036.

Copy link
Contributor Author

@smoelius smoelius Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would you feel about rustc's path being determined in Cargo's build script rather than via environment variables in this function?

That is, I'm proposing that real_rustc_wrapper look something like this:

/// Creates an executable which prints a message and then runs the *real* rustc.
fn real_rustc_wrapper(bin_dir: &Path, message: &str) -> PathBuf {
    let real_rustc = PathBuf::from(env!("RUSTC"));
    let env = vec![("CARGO_RUSTUP_TEST_real_rustc", real_rustc)];
    make_exe(
        bin_dir,
        "rustc",
        &format!(
            r#"
                eprintln!("{message}");
                let r = std::process::Command::new(env!("CARGO_RUSTUP_TEST_real_rustc"))
                    .args(std::env::args_os().skip(1))
                    .status();
                std::process::exit(r.unwrap().code().unwrap_or(2));
            "#
        ),
        &env,
    )
}

EDIT: Also, please tell me whether you think a separate PR would be appropriate.

Some(t) => format!(
".env(\"RUSTUP_TOOLCHAIN_SOURCE\", \"{}\")",
t.into_string().unwrap()
),
None => format!(".env_remove(\"RUSTUP_TOOLCHAIN_SOURCE\")"),
};
let rustup_toolchain_setup = match std::env::var_os("RUSTUP_TOOLCHAIN") {
Some(t) => format!(
".env(\"RUSTUP_TOOLCHAIN\", \"{}\")",
Expand All @@ -78,6 +85,7 @@ fn real_rustc_wrapper(bin_dir: &Path, message: &str) -> PathBuf {
eprintln!("{message}");
let r = std::process::Command::new(env!("CARGO_RUSTUP_TEST_real_rustc"))
.args(std::env::args_os().skip(1))
{rustup_toolchain_source_setup}
{rustup_toolchain_setup}
{rustup_home_setup}
.status();
Expand Down Expand Up @@ -162,6 +170,7 @@ fn typical_rustup() {
// `~/.cargo/bin/rustc to use our custom rustup proxies.
let path = prepend_path(&cargo_bin);
p.cargo("check")
.env("RUSTUP_TOOLCHAIN_SOURCE", "default")
.env("RUSTUP_TOOLCHAIN", "test-toolchain")
.env("RUSTUP_HOME", &rustup_home)
.env("PATH", &path)
Expand All @@ -179,6 +188,7 @@ real rustc running
p.build_dir().rm_rf();

p.cargo("check")
.env("RUSTUP_TOOLCHAIN_SOURCE", "default")
.env("RUSTUP_TOOLCHAIN", "test-toolchain")
.env("RUSTUP_HOME", &rustup_home)
.env("PATH", &path)
Expand Down Expand Up @@ -249,6 +259,7 @@ fn custom_calls_other_cargo() {
// Set these to simulate what would happen when running under rustup.
// We want to make sure that cargo-custom does not try to use the
// rustup proxies.
.env("RUSTUP_TOOLCHAIN_SOURCE", "default")
.env("RUSTUP_TOOLCHAIN", "test-toolchain")
.env("RUSTUP_HOME", &rustup_home)
.with_stderr_data(str![[r#"
Expand Down