Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21272 from ShoyuVanilla/sysroot-target
fix: Prefix json target file with workspace root for sysroot metadata
Chayim Refael Friedman 4 months ago
parent 764552c · parent 564034e · commit ccb1138
-rw-r--r--crates/project-model/src/workspace.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/crates/project-model/src/workspace.rs b/crates/project-model/src/workspace.rs
index 10abb21ace..747aa68f08 100644
--- a/crates/project-model/src/workspace.rs
+++ b/crates/project-model/src/workspace.rs
@@ -391,6 +391,7 @@ impl ProjectWorkspace {
sysroot.load_workspace(
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
config,
+ workspace_dir,
&targets,
toolchain.clone(),
)),
@@ -500,6 +501,7 @@ impl ProjectWorkspace {
sysroot.load_workspace(
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
config,
+ project_json.project_root(),
&targets,
toolchain.clone(),
)),
@@ -555,6 +557,7 @@ impl ProjectWorkspace {
let loaded_sysroot = sysroot.load_workspace(
&RustSourceWorkspaceConfig::CargoMetadata(sysroot_metadata_config(
config,
+ dir,
&targets,
toolchain.clone(),
)),
@@ -1907,12 +1910,28 @@ fn add_dep_inner(graph: &mut CrateGraphBuilder, from: CrateBuilderId, dep: Depen
fn sysroot_metadata_config(
config: &CargoConfig,
+ workspace_root: &AbsPath,
targets: &[String],
toolchain_version: Option<Version>,
) -> CargoMetadataConfig {
+ // If the target is a JSON path, prefix it with workspace root directory.
+ // Since `cargo metadata` command for sysroot is run inside sysroots dir, it may fail to
+ // locate the target file if it is given as a relative path.
+ let targets = targets
+ .iter()
+ .map(|target| {
+ if target.ends_with(".json") {
+ // If `target` is an absolute path, this will replace the whole path.
+ workspace_root.join(target).to_string()
+ } else {
+ target.to_owned()
+ }
+ })
+ .collect();
+
CargoMetadataConfig {
features: Default::default(),
- targets: targets.to_vec(),
+ targets,
extra_args: Default::default(),
extra_env: config.extra_env.clone(),
toolchain_version,