Skip to content

Commit ccb1138

Browse files
Merge pull request #21272 from ShoyuVanilla/sysroot-target
fix: Prefix json target file with workspace root for sysroot metadata
2 parents 764552c + 564034e commit ccb1138

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

crates/project-model/src/workspace.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ impl ProjectWorkspace {
391391
sysroot.load_workspace(
392392
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
393393
config,
394+
workspace_dir,
394395
&targets,
395396
toolchain.clone(),
396397
)),
@@ -500,6 +501,7 @@ impl ProjectWorkspace {
500501
sysroot.load_workspace(
501502
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
502503
config,
504+
project_json.project_root(),
503505
&targets,
504506
toolchain.clone(),
505507
)),
@@ -555,6 +557,7 @@ impl ProjectWorkspace {
555557
let loaded_sysroot = sysroot.load_workspace(
556558
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
557559
config,
560+
dir,
558561
&targets,
559562
toolchain.clone(),
560563
)),
@@ -1907,12 +1910,28 @@ fn add_dep_inner(graph: &mut CrateGraphBuilder, from: CrateBuilderId, dep: Depen
19071910

19081911
fn sysroot_metadata_config(
19091912
config: &CargoConfig,
1913+
workspace_root: &AbsPath,
19101914
targets: &[String],
19111915
toolchain_version: Option<Version>,
19121916
) -> CargoMetadataConfig {
1917+
// If the target is a JSON path, prefix it with workspace root directory.
1918+
// Since `cargo metadata` command for sysroot is run inside sysroots dir, it may fail to
1919+
// locate the target file if it is given as a relative path.
1920+
let targets = targets
1921+
.iter()
1922+
.map(|target| {
1923+
if target.ends_with(".json") {
1924+
// If `target` is an absolute path, this will replace the whole path.
1925+
workspace_root.join(target).to_string()
1926+
} else {
1927+
target.to_owned()
1928+
}
1929+
})
1930+
.collect();
1931+
19131932
CargoMetadataConfig {
19141933
features: Default::default(),
1915-
targets: targets.to_vec(),
1934+
targets,
19161935
extra_args: Default::default(),
19171936
extra_env: config.extra_env.clone(),
19181937
toolchain_version,

0 commit comments

Comments
 (0)