Skip to content

Commit

Permalink
Workaround rustup env issue when setting toolchain #702
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Aug 29, 2022
1 parent 2a86548 commit 32fc95b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### v0.36.0

* Enhancement: Workaround rustup env issue when setting toolchain #702

### v0.35.16 (2022-08-08)

* Enhancement: Create task definition in runtime and invoke it via plugin #677
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions examples/toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ dependencies = [
"rustc-version-nightly",
]

[tasks.echo-cargo-stable]
toolchain = "stable"
[tasks.echo-cargo-env]
script = '''
echo ${CARGO}
echo CARGO=${CARGO}
echo RUSTC=${RUSTC}
echo RUSTDOC=${RUSTDOC}
echo RUSTFLAGS=${RUSTFLAGS}
'''

[tasks.echo-cargo-stable]
extend = "echo-cargo-env"
toolchain = "stable"

[tasks.stable]
alias = "echo-cargo-stable"

[tasks.echo-cargo-nightly]
extend = "echo-cargo-env"
toolchain = "nightly"
script = '''
echo ${CARGO}
'''

[tasks.nightly]
alias = "echo-cargo-nightly"

[tasks.echo-cargo-all]
dependencies = ["echo-cargo-stable", "echo-cargo-nightly"]
4 changes: 4 additions & 0 deletions src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::profile;
use crate::recursion_level;
use crate::runner;
use crate::time_summary;
use crate::toolchain;
use crate::types::{CliArgs, GlobalConfig};
use crate::version;
use std::time::SystemTime;
Expand Down Expand Up @@ -52,6 +53,9 @@ fn run(cli_args: CliArgs, global_config: &GlobalConfig) {
version::check();
}

// clear env vars (see https://github.com/rust-lang/rustup/issues/3029)
toolchain::remove_rust_env_vars();

let cwd_string_option = match cli_args.cwd.clone() {
Some(value) => Some(value),
None => match global_config.search_project_root {
Expand Down
8 changes: 6 additions & 2 deletions src/lib/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#[path = "toolchain_test.rs"]
mod toolchain_test;

use semver::{Prerelease, Version};

use crate::types::{CommandSpec, ToolchainSpecifier};
use envmnt;
use semver::{Prerelease, Version};
use std::process::{Command, Stdio};

pub(crate) fn wrap_command(
Expand Down Expand Up @@ -128,3 +128,7 @@ pub(crate) fn get_cargo_binary_path(toolchain: &ToolchainSpecifier) -> Option<St
Some(binary_path.to_string())
}
}

pub(crate) fn remove_rust_env_vars() {
envmnt::remove_all(&vec!["RUSTC", "RUSTDOC", "RUSTFLAGS"]);
}
17 changes: 17 additions & 0 deletions src/lib/toolchain_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,20 @@ fn get_cargo_binary_path_valid() {
assert!(binary_path_value.find("bin").is_some());
assert!(binary_path_value.find("cargo").is_some());
}

#[test]
fn remove_rust_env_vars_existed() {
envmnt::set("RUSTC", "bad1");
envmnt::set("RUSTDOC", "bad2");
envmnt::set("RUSTFLAGS", "bad3");

assert!(envmnt::exits("RUSTC"));
assert!(envmnt::exits("RUSTDOC"));
assert!(envmnt::exits("RUSTFLAGS"));

remove_rust_env_vars();

assert!(!envmnt::exits("RUSTC"));
assert!(!envmnt::exits("RUSTDOC"));
assert!(!envmnt::exits("RUSTFLAGS"));
}

0 comments on commit 32fc95b

Please sign in to comment.