Skip to content

Commit acc63d7

Browse files
committed
Extend relative path dep test to include Cargo workspace
1 parent 4d11c0b commit acc63d7

13 files changed

Lines changed: 103 additions & 20 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
external_crate/
2+
external_crate_b/
3+
external_workspace/

test/integration/external_relative_path_deps/MODULE.bazel

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,31 @@ use_repo(rust, "rust_toolchains")
1717

1818
register_toolchains("@rust_toolchains//:all")
1919

20-
# Test: crate_universe with Cargo workspace where a member has a path dependency
21-
# that goes OUTSIDE the Cargo workspace root (but still inside the Bazel workspace).
20+
# Test: crate_universe with Cargo workspace where a member has path dependencies
21+
# that go OUTSIDE the Cargo workspace root (but still inside the Bazel workspace).
2222
#
2323
# Structure:
24-
# external_crate/ <- Outside Cargo workspace
25-
# cargo_workspace/ <- Cargo workspace root
26-
# Cargo.toml <- [workspace] members = ["member"]
24+
# external_crate/ <- Outside Cargo workspace (standalone)
25+
# external_crate_b/ <- Outside Cargo workspace (standalone)
26+
# external_workspace/ <- Separate Cargo workspace
27+
# ext_ws_crate/ <- Member of external_workspace
28+
# cargo_workspace/ <- Primary Cargo workspace
29+
# Cargo.toml <- [workspace] with [workspace.dependencies] for external_crate + ext_ws_crate
2730
# member/
28-
# Cargo.toml <- external_crate = { path = "../../external_crate" }
31+
# Cargo.toml <- external_crate via workspace = true,
32+
# external_crate_b via direct path dep,
33+
# ext_ws_crate via workspace = true
2934
#
30-
# This should work but currently fails because crate_universe doesn't copy
31-
# the external path dependency into the temp splicing directory.
35+
# Tests three code paths: workspace-inherited external path deps, direct
36+
# external path deps declared inline in a member, and external path deps
37+
# from a crate that belongs to a different Cargo workspace.
3238
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
3339
crate.from_cargo(
3440
name = "crates",
3541
cargo_lockfile = "//cargo_workspace:Cargo.lock",
36-
manifests = ["//cargo_workspace:Cargo.toml"],
42+
manifests = [
43+
"//cargo_workspace:Cargo.toml",
44+
"//:external_workspace/ext_ws_crate/Cargo.toml",
45+
],
3746
)
3847
use_repo(crate, "crates")

test/integration/external_relative_path_deps/MODULE.bazel.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/integration/external_relative_path_deps/cargo_workspace/Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[workspace]
22
members = ["member"]
33
resolver = "2"
4+
5+
[workspace.dependencies]
6+
external_crate = { path = "../external_crate" }
7+
ext_ws_crate = { path = "../external_workspace/ext_ws_crate" }

test/integration/external_relative_path_deps/cargo_workspace/member/BUILD.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ rust_library(
44
name = "member",
55
srcs = ["src/lib.rs"],
66
deps = [
7-
# The external_crate dependency should be resolved by crate_universe
8-
# even though it's located outside the Cargo workspace via path = "../../external_crate"
7+
# Workspace dep: declared in [workspace.dependencies] with a path outside the workspace.
98
"@crates//:external_crate",
9+
# Direct dep: declared inline with a path outside the workspace.
10+
"@crates//:external_crate_b",
11+
# Workspace dep from a different Cargo workspace.
12+
"@crates//:ext_ws_crate",
1013
],
1114
)
1215

test/integration/external_relative_path_deps/cargo_workspace/member/Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ edition = "2021"
66
[lib]
77

88
[dependencies]
9-
# This path dependency goes OUTSIDE the Cargo workspace root.
10-
# This is the scenario from issue #3089.
11-
external_crate = { path = "../../external_crate" }
9+
# Inherited from [workspace.dependencies]. Path goes outside the workspace.
10+
external_crate.workspace = true
11+
# Direct path dep that also goes outside the workspace.
12+
external_crate_b = { path = "../../external_crate_b" }
13+
# Inherited from [workspace.dependencies]. Path goes to a crate in a different Cargo workspace.
14+
ext_ws_crate.workspace = true
Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
1-
use external_crate;
2-
3-
/// Re-exports the greeting from external_crate.
1+
/// Re-exports the greeting from external_crate (workspace dep).
42
pub fn say_hello() -> &'static str {
53
external_crate::greet()
64
}
5+
6+
/// Re-exports the greeting from external_crate_b (direct dep).
7+
pub fn say_hello_b() -> &'static str {
8+
external_crate_b::greet()
9+
}
10+
11+
/// Re-exports the greeting from ext_ws_crate (belongs to a different Cargo workspace).
12+
pub fn say_hello_ext_ws() -> &'static str {
13+
ext_ws_crate::greet()
14+
}
15+
16+
#[cfg(test)]
17+
mod tests {
18+
use super::*;
19+
20+
#[test]
21+
fn test_workspace_dep() {
22+
assert_eq!(say_hello(), "Hello from external_crate!");
23+
}
24+
25+
#[test]
26+
fn test_direct_dep() {
27+
assert_eq!(say_hello_b(), "Hello from external_crate_b!");
28+
}
29+
30+
#[test]
31+
fn test_ext_workspace_dep() {
32+
assert_eq!(say_hello_ext_ws(), "Hello from ext_ws_crate!");
33+
}
34+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "external_crate_b"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Returns a greeting from external_crate_b.
2+
pub fn greet() -> &'static str {
3+
"Hello from external_crate_b!"
4+
}

0 commit comments

Comments
 (0)