Skip to content

Commit e5f8808

Browse files
committed
Rust: Force stable toolchain
1 parent e76361b commit e5f8808

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

rust/extractor/src/config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ use std::collections::HashSet;
2323
use std::fmt::Debug;
2424
use std::ops::Not;
2525
use std::path::{Path, PathBuf};
26+
use std::process::Command;
27+
use tracing::{info, warn};
2628

2729
#[derive(Debug, PartialEq, Eq, Default, Serialize, Deserialize, Clone, Copy, clap::ValueEnum)]
2830
#[serde(rename_all = "lowercase")]
@@ -140,9 +142,41 @@ impl Config {
140142
);
141143
}
142144
extra_env.extend(self.cargo_extra_env.clone());
145+
// Always use the latest stable toolchain, irrespective of any toolchain
146+
// file in the project being extracted.
147+
extra_env.insert("RUSTUP_TOOLCHAIN".to_owned(), Some("stable".to_owned()));
143148
extra_env
144149
}
145150

151+
pub(crate) fn apply_extra_env(&self, command: &mut Command) {
152+
for (key, value) in self.get_extra_env() {
153+
match value {
154+
Some(value) => command.env(key, value),
155+
None => command.env_remove(key),
156+
};
157+
}
158+
}
159+
160+
pub(crate) fn log_effective_toolchain(&self, dir: &AbsPath) {
161+
let mut command = Command::new("rustc");
162+
command
163+
.current_dir(dir.as_str())
164+
.args(["--version", "--verbose"]);
165+
self.apply_extra_env(&mut command);
166+
167+
match command.output() {
168+
Ok(output) if output.status.success() => info!(
169+
"effective Rust toolchain:\n{}",
170+
String::from_utf8_lossy(&output.stdout).trim()
171+
),
172+
Ok(output) => warn!(
173+
"unable to determine effective Rust toolchain: {}",
174+
String::from_utf8_lossy(&output.stderr).trim()
175+
),
176+
Err(error) => warn!("unable to determine effective Rust toolchain: {error}"),
177+
}
178+
}
179+
146180
fn sysroot(&self, dir: &AbsPath) -> Sysroot {
147181
let sysroot_input = self.sysroot.as_ref().map(|p| join_path_buf(dir, p));
148182
let sysroot_src_input = self.sysroot_src.as_ref().map(|p| join_path_buf(dir, p));

rust/extractor/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ fn main() -> anyhow::Result<()> {
269269
);
270270
}
271271
let cwd = cwd()?;
272+
cfg.log_effective_toolchain(&cwd);
272273
let (cargo_config, load_cargo_config) = cfg.to_cargo_config(&cwd);
273274
let library_mode = if cfg.extract_dependencies_as_source {
274275
SourceKind::Source

rust/extractor/src/qltest.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,7 @@ fn cargo_check(config: &Config) -> anyhow::Result<()> {
9494
let mut command = Command::new("cargo");
9595
command.env("CARGO_TARGET_DIR", config.cargo_target_dir());
9696
// Pass the extra environment variables to the initial `cargo check`.
97-
for (key, value) in config.get_extra_env() {
98-
match value {
99-
Some(value) => command.env(key, value),
100-
None => command.env_remove(key),
101-
};
102-
}
97+
config.apply_extra_env(&mut command);
10398
let status = command
10499
.arg("check")
105100
.arg("-q")

0 commit comments

Comments
 (0)