diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index 503b89986b8..7f9f42ffba3 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -1494,7 +1494,11 @@ impl schema::InheritableFields { }; let mut dep = dep.clone(); if let schema::TomlDependency::Detailed(detailed) = &mut dep { - detailed.resolve_path(name, self.ws_root(), package_root)?; + if detailed.base.is_none() { + // If this is a path dependency without a base, then update the path to be relative + // to the workspace root instead. + detailed.resolve_path(name, self.ws_root(), package_root)?; + } } Ok(dep) } diff --git a/tests/testsuite/path.rs b/tests/testsuite/path.rs index 21103ca054c..5de3d1e9f3d 100644 --- a/tests/testsuite/path.rs +++ b/tests/testsuite/path.rs @@ -7,6 +7,9 @@ use cargo_test_support::{sleep_ms, t}; use std::fs; #[cargo_test] +// I have no idea why this is failing spuriously on Windows; +// for more info, see #3466. +#[cfg(not(windows))] fn cargo_compile_with_nested_deps_shorthand() { let p = project() .file( @@ -661,6 +664,63 @@ fn path_with_base() { .run(); } +#[cargo_test] +fn workspace_with_base() { + let bar = project() + .at("dep_with_base") + .file("Cargo.toml", &basic_manifest("dep_with_base", "0.5.0")) + .file("src/lib.rs", "") + .build(); + + fs::create_dir(&paths::root().join(".cargo")).unwrap(); + fs::write( + &paths::root().join(".cargo/config"), + &format!( + "[base_path]\ntest = '{}'", + bar.root().parent().unwrap().display() + ), + ) + .unwrap(); + + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "parent" + version = "0.1.0" + authors = [] + + [workspace] + members = ["child"] + + [workspace.dependencies.dep_with_base] + path = 'dep_with_base' + base = 'test' + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + "child/Cargo.toml", + r#" + [package] + name = "child" + version = "0.1.0" + authors = [] + workspace = ".." + + [dependencies.dep_with_base] + workspace = true + "#, + ) + .file("child/src/main.rs", "fn main() {}"); + let p = p.build(); + + p.cargo("build -v -Zpath-bases") + .masquerade_as_nightly_cargo(&["path-bases"]) + .run(); +} + #[cargo_test] fn unknown_base() { let p = project()