Skip to content

Commit b239c1e

Browse files
committed
Rust: Force stable toolchain
1 parent 7fda929 commit b239c1e

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")]
@@ -135,9 +137,41 @@ impl Config {
135137
extra_env.insert("RUSTFLAGS".to_owned(), Some("-Awarnings".to_owned()));
136138
}
137139
extra_env.extend(self.cargo_extra_env.clone());
140+
// Always use the latest stable toolchain, irrespective of any toolchain
141+
// file in the project being extracted.
142+
extra_env.insert("RUSTUP_TOOLCHAIN".to_owned(), Some("stable".to_owned()));
138143
extra_env
139144
}
140145

146+
pub(crate) fn apply_extra_env(&self, command: &mut Command) {
147+
for (key, value) in self.get_extra_env() {
148+
match value {
149+
Some(value) => command.env(key, value),
150+
None => command.env_remove(key),
151+
};
152+
}
153+
}
154+
155+
pub(crate) fn log_effective_toolchain(&self, dir: &AbsPath) {
156+
let mut command = Command::new("rustc");
157+
command
158+
.current_dir(dir.as_str())
159+
.args(["--version", "--verbose"]);
160+
self.apply_extra_env(&mut command);
161+
162+
match command.output() {
163+
Ok(output) if output.status.success() => info!(
164+
"effective Rust toolchain:\n{}",
165+
String::from_utf8_lossy(&output.stdout).trim()
166+
),
167+
Ok(output) => warn!(
168+
"unable to determine effective Rust toolchain: {}",
169+
String::from_utf8_lossy(&output.stderr).trim()
170+
),
171+
Err(error) => warn!("unable to determine effective Rust toolchain: {error}"),
172+
}
173+
}
174+
141175
fn sysroot(&self, dir: &AbsPath) -> Sysroot {
142176
let sysroot_input = self.sysroot.as_ref().map(|p| join_path_buf(dir, p));
143177
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
@@ -270,6 +270,7 @@ fn main() -> anyhow::Result<()> {
270270
);
271271
}
272272
let cwd = cwd()?;
273+
cfg.log_effective_toolchain(&cwd);
273274
let (cargo_config, load_cargo_config) = cfg.to_cargo_config(&cwd);
274275
let library_mode = if cfg.extract_dependencies_as_source {
275276
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)