Skip to content

Commit f93256c

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

18 files changed

Lines changed: 277 additions & 361 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
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
fncurrent_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‎

Lines changed: 7 additions & 7 deletions
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
constRUST_1_75:Version = Version::new(1,75,0);
7171
letmut cmd = match config.run_build_script_command.as_deref(){
@@ -75,7 +75,7 @@ impl WorkspaceBuildScripts {
7575
cmd
7676
}
7777
_ => {
78-
letmut cmd = Sysroot::tool(sysroot,Tool::Cargo);
78+
letmut 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:&dynFn(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
letmut 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-
letmut cargo_config = Sysroot::tool(sysroot,Tool::Cargo);
423+
letmut 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
ifletOk(it) = utf8_stdout(cargo_config){
430430
returnOk(it);
431431
}
432-
letmut cmd = Sysroot::tool(sysroot,Tool::Rustc);
432+
letmut 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‎

Lines changed: 7 additions & 7 deletions
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:&dynFn(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
letmut 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
fnfind_list_of_build_targets(
537537
config:&CargoConfig,
538538
cargo_toml:&ManifestPath,
539-
sysroot:Option<&Sysroot>,
539+
sysroot:&Sysroot,
540540
) -> Vec<String>{
541541
ifletSome(target) = &config.target{
542542
return[target.into()].to_vec();
@@ -553,9 +553,9 @@ fn find_list_of_build_targets(
553553
fnrustc_discover_host_triple(
554554
cargo_toml:&ManifestPath,
555555
extra_env:&FxHashMap<String,String>,
556-
sysroot:Option<&Sysroot>,
556+
sysroot:&Sysroot,
557557
) -> Option<String>{
558-
letmut rustc = Sysroot::tool(sysroot,Tool::Rustc);
558+
letmut 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
fncargo_config_build_target(
582582
cargo_toml:&ManifestPath,
583583
extra_env:&FxHashMap<String,String>,
584-
sysroot:Option<&Sysroot>,
584+
sysroot:&Sysroot,
585585
) -> Vec<String>{
586-
letmut cargo_config = Sysroot::tool(sysroot,Tool::Cargo);
586+
letmut 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‎

Lines changed: 2 additions & 2 deletions
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)fncargo_config_env(
6363
manifest:&ManifestPath,
6464
extra_env:&FxHashMap<String,String>,
65-
sysroot:Option<&Sysroot>,
65+
sysroot:&Sysroot,
6666
) -> FxHashMap<String,String>{
67-
letmut cargo_config = Sysroot::tool(sysroot,Tool::Cargo);
67+
letmut 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‎

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

1919
pub(crate)fnget(
@@ -65,7 +65,7 @@ fn get_rust_cfgs(
6565
) -> anyhow::Result<String>{
6666
let sysroot = match config {
6767
RustcCfgConfig::Cargo(sysroot, cargo_toml) => {
68-
letmut cmd = Sysroot::tool(sysroot,Tool::Cargo);
68+
letmut 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-
letmut cmd = Sysroot::tool(sysroot,Tool::Rustc);
89+
letmut cmd = sysroot.tool(Tool::Rustc);
9090
cmd.envs(extra_env);
9191
cmd.args(["--print","cfg","-O"]);
9292
ifletSome(target) = target {

0 commit comments

Comments
 (0)