Skip to content

Commit 44ffd4d

Browse files
committed
Rust: Force stable toolchain
1 parent 8203f08 commit 44ffd4d

3 files changed

Lines changed: 59 additions & 6 deletions

File tree

rust/extractor/src/config.rs

Lines changed: 36 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,42 @@ impl Config {
140142
);
141143
}
142144
extra_env.extend(self.cargo_extra_env.clone());
145+
extra_env.insert(
146+
"RUSTUP_TOOLCHAIN".to_owned(),
147+
Some(crate::select_toolchain().to_owned()),
148+
);
143149
extra_env
144150
}
145151

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

187222
pub fn to_cargo_config(&self, dir: &AbsPath) -> (CargoConfig, LoadCargoConfig) {
188223
let sysroot = self.sysroot(dir);
224+
info!("Using sysroot: {:?}", sysroot.root());
189225
(
190226
CargoConfig {
191227
all_targets: self.cargo_all_targets,

rust/extractor/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,27 @@ mod rust_analyzer;
3535
mod translate;
3636
pub mod trap;
3737

38+
/// The toolchain target by the extractor. When rust-analyzer is updated this
39+
/// number should be bumped to the last Rust toolchain release that preceedes
40+
/// the rust-analyzer release.
41+
const DEFAULT_RUST_TOOLCHAIN: &str = "1.97.0";
42+
43+
fn select_toolchain() -> &'static str {
44+
let uses_nightly = std::process::Command::new("rustup")
45+
.args(["show", "active-toolchain"])
46+
.output()
47+
.ok()
48+
.filter(|output| output.status.success())
49+
.and_then(|output| String::from_utf8(output.stdout).ok())
50+
.is_some_and(|toolchain| toolchain.starts_with("nightly"));
51+
52+
if uses_nightly {
53+
"nightly"
54+
} else {
55+
DEFAULT_RUST_TOOLCHAIN
56+
}
57+
}
58+
3859
struct Extractor<'a> {
3960
archiver: &'a Archiver,
4061
traps: &'a trap::TrapFileProvider,
@@ -269,6 +290,7 @@ fn main() -> anyhow::Result<()> {
269290
);
270291
}
271292
let cwd = cwd()?;
293+
cfg.log_effective_toolchain(&cwd);
272294
let (cargo_config, load_cargo_config) = cfg.to_cargo_config(&cwd);
273295
let library_mode = if cfg.extract_dependencies_as_source {
274296
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)