Skip to content

Commit f93256c

Browse files
committed
Allow sysroots to only consist of the source root dir
1 parent 616fdd0 commit f93256c

File tree

18 files changed

+277
-361
lines changed

18 files changed

+277
-361
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/layout/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use chalk_ir::{AdtId, TyKind};
22
use either::Either;
33
use hir_def::db::DefDatabase;
4-
use project_model::target_data_layout::RustcDataLayoutConfig;
4+
use project_model::{target_data_layout::RustcDataLayoutConfig, Sysroot};
55
use rustc_hash::FxHashMap;
66
use test_fixture::WithFixture;
77
use triomphe::Arc;
@@ -17,7 +17,7 @@ mod closure;
1717

1818
fn current_machine_data_layout() -> String {
1919
project_model::target_data_layout::get(
20-
RustcDataLayoutConfig::Rustc(None),
20+
RustcDataLayoutConfig::Rustc(&Sysroot::empty()),
2121
None,
2222
&FxHashMap::default(),
2323
)

src/tools/rust-analyzer/crates/project-model/src/build_scripts.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl WorkspaceBuildScripts {
6565
allowed_features: &FxHashSet<String>,
6666
manifest_path: &ManifestPath,
6767
toolchain: Option<&Version>,
68-
sysroot: Option<&Sysroot>,
68+
sysroot: &Sysroot,
6969
) -> io::Result<Command> {
7070
const RUST_1_75: Version = Version::new(1, 75, 0);
7171
let mut cmd = match config.run_build_script_command.as_deref() {
@@ -75,7 +75,7 @@ impl WorkspaceBuildScripts {
7575
cmd
7676
}
7777
_ => {
78-
let mut cmd = Sysroot::tool(sysroot, Tool::Cargo);
78+
let mut cmd = sysroot.tool(Tool::Cargo);
7979

8080
cmd.args(["check", "--quiet", "--workspace", "--message-format=json"]);
8181
cmd.args(&config.extra_args);
@@ -149,7 +149,7 @@ impl WorkspaceBuildScripts {
149149
workspace: &CargoWorkspace,
150150
progress: &dyn Fn(String),
151151
toolchain: Option<&Version>,
152-
sysroot: Option<&Sysroot>,
152+
sysroot: &Sysroot,
153153
) -> io::Result<WorkspaceBuildScripts> {
154154
let current_dir = match &config.invocation_location {
155155
InvocationLocation::Root(root) if config.run_build_script_command.is_some() => {
@@ -195,7 +195,7 @@ impl WorkspaceBuildScripts {
195195
// This is not gonna be used anyways, so just construct a dummy here
196196
&ManifestPath::try_from(workspace_root.clone()).unwrap(),
197197
None,
198-
None,
198+
&Sysroot::empty(),
199199
)?;
200200
// NB: Cargo.toml could have been modified between `cargo metadata` and
201201
// `cargo check`. We shouldn't assume that package ids we see here are
@@ -412,15 +412,15 @@ impl WorkspaceBuildScripts {
412412
rustc: &CargoWorkspace,
413413
current_dir: &AbsPath,
414414
extra_env: &FxHashMap<String, String>,
415-
sysroot: Option<&Sysroot>,
415+
sysroot: &Sysroot,
416416
) -> Self {
417417
let mut bs = WorkspaceBuildScripts::default();
418418
for p in rustc.packages() {
419419
bs.outputs.insert(p, BuildScriptOutput::default());
420420
}
421421
let res = (|| {
422422
let target_libdir = (|| {
423-
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
423+
let mut cargo_config = sysroot.tool(Tool::Cargo);
424424
cargo_config.envs(extra_env);
425425
cargo_config
426426
.current_dir(current_dir)
@@ -429,7 +429,7 @@ impl WorkspaceBuildScripts {
429429
if let Ok(it) = utf8_stdout(cargo_config) {
430430
return Ok(it);
431431
}
432-
let mut cmd = Sysroot::tool(sysroot, Tool::Rustc);
432+
let mut cmd = sysroot.tool(Tool::Rustc);
433433
cmd.envs(extra_env);
434434
cmd.args(["--print", "target-libdir"]);
435435
utf8_stdout(cmd)

src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,12 @@ impl CargoWorkspace {
258258
cargo_toml: &ManifestPath,
259259
current_dir: &AbsPath,
260260
config: &CargoConfig,
261-
sysroot: Option<&Sysroot>,
261+
sysroot: &Sysroot,
262262
progress: &dyn Fn(String),
263263
) -> anyhow::Result<cargo_metadata::Metadata> {
264264
let targets = find_list_of_build_targets(config, cargo_toml, sysroot);
265265

266-
let cargo = Sysroot::tool(sysroot, Tool::Cargo);
266+
let cargo = sysroot.tool(Tool::Cargo);
267267
let mut meta = MetadataCommand::new();
268268
meta.cargo_path(cargo.get_program());
269269
cargo.get_envs().for_each(|(var, val)| _ = meta.env(var, val.unwrap_or_default()));
@@ -536,7 +536,7 @@ impl CargoWorkspace {
536536
fn find_list_of_build_targets(
537537
config: &CargoConfig,
538538
cargo_toml: &ManifestPath,
539-
sysroot: Option<&Sysroot>,
539+
sysroot: &Sysroot,
540540
) -> Vec<String> {
541541
if let Some(target) = &config.target {
542542
return [target.into()].to_vec();
@@ -553,9 +553,9 @@ fn find_list_of_build_targets(
553553
fn rustc_discover_host_triple(
554554
cargo_toml: &ManifestPath,
555555
extra_env: &FxHashMap<String, String>,
556-
sysroot: Option<&Sysroot>,
556+
sysroot: &Sysroot,
557557
) -> Option<String> {
558-
let mut rustc = Sysroot::tool(sysroot, Tool::Rustc);
558+
let mut rustc = sysroot.tool(Tool::Rustc);
559559
rustc.envs(extra_env);
560560
rustc.current_dir(cargo_toml.parent()).arg("-vV");
561561
tracing::debug!("Discovering host platform by {:?}", rustc);
@@ -581,9 +581,9 @@ fn rustc_discover_host_triple(
581581
fn cargo_config_build_target(
582582
cargo_toml: &ManifestPath,
583583
extra_env: &FxHashMap<String, String>,
584-
sysroot: Option<&Sysroot>,
584+
sysroot: &Sysroot,
585585
) -> Vec<String> {
586-
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
586+
let mut cargo_config = sysroot.tool(Tool::Cargo);
587587
cargo_config.envs(extra_env);
588588
cargo_config
589589
.current_dir(cargo_toml.parent())

src/tools/rust-analyzer/crates/project-model/src/env.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ pub(crate) fn inject_rustc_tool_env(env: &mut Env, cargo_name: &str, kind: Targe
6262
pub(crate) fn cargo_config_env(
6363
manifest: &ManifestPath,
6464
extra_env: &FxHashMap<String, String>,
65-
sysroot: Option<&Sysroot>,
65+
sysroot: &Sysroot,
6666
) -> FxHashMap<String, String> {
67-
let mut cargo_config = Sysroot::tool(sysroot, Tool::Cargo);
67+
let mut cargo_config = sysroot.tool(Tool::Cargo);
6868
cargo_config.envs(extra_env);
6969
cargo_config
7070
.current_dir(manifest.parent())

src/tools/rust-analyzer/crates/project-model/src/rustc_cfg.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use crate::{cfg::CfgFlag, utf8_stdout, ManifestPath, Sysroot};
1010
pub(crate) enum RustcCfgConfig<'a> {
1111
/// Use `rustc --print cfg`, either from with the binary from the sysroot or by discovering via
1212
/// [`toolchain::rustc`].
13-
Rustc(Option<&'a Sysroot>),
13+
Rustc(&'a Sysroot),
1414
/// Use `cargo --print cfg`, either from with the binary from the sysroot or by discovering via
1515
/// [`toolchain::cargo`].
16-
Cargo(Option<&'a Sysroot>, &'a ManifestPath),
16+
Cargo(&'a Sysroot, &'a ManifestPath),
1717
}
1818

1919
pub(crate) fn get(
@@ -65,7 +65,7 @@ fn get_rust_cfgs(
6565
) -> anyhow::Result<String> {
6666
let sysroot = match config {
6767
RustcCfgConfig::Cargo(sysroot, cargo_toml) => {
68-
let mut cmd = Sysroot::tool(sysroot, Tool::Cargo);
68+
let mut cmd = sysroot.tool(Tool::Cargo);
6969

7070
cmd.envs(extra_env);
7171
cmd.current_dir(cargo_toml.parent())
@@ -86,7 +86,7 @@ fn get_rust_cfgs(
8686
RustcCfgConfig::Rustc(sysroot) => sysroot,
8787
};
8888

89-
let mut cmd = Sysroot::tool(sysroot, Tool::Rustc);
89+
let mut cmd = sysroot.tool(Tool::Rustc);
9090
cmd.envs(extra_env);
9191
cmd.args(["--print", "cfg", "-O"]);
9292
if let Some(target) = target {

0 commit comments

Comments
 (0)