Skip to content

Commit f5ae457

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

14 files changed

Lines changed: 234 additions & 20 deletions

File tree

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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
###############################################################################
2+
# @generated
3+
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
4+
# regenerate this file, run the following:
5+
#
6+
# bazel mod show_repo 'external_relative_path_deps_test'
7+
###############################################################################
8+
9+
load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars")
10+
11+
load("@rules_rust//rust:defs.bzl", "rust_library")
12+
13+
# buildifier: disable=bzl-visibility
14+
load("@rules_rust//crate_universe/private:selects.bzl", "selects")
15+
16+
package(default_visibility = ["//visibility:public"])
17+
18+
cargo_toml_env_vars(
19+
name = "cargo_toml_env_vars",
20+
src = "Cargo.toml",
21+
)
22+
23+
rust_library(
24+
name = "external_crate_b",
25+
compile_data = glob(
26+
allow_empty = True,
27+
include = ["**"],
28+
exclude = [
29+
"**/* *",
30+
".tmp_git_root/**/*",
31+
"BUILD",
32+
"BUILD.bazel",
33+
"WORKSPACE",
34+
"WORKSPACE.bazel",
35+
],
36+
),
37+
crate_root = "src/lib.rs",
38+
edition = "2021",
39+
rustc_env_files = [
40+
":cargo_toml_env_vars",
41+
],
42+
rustc_flags = [
43+
"--cap-lints=allow",
44+
],
45+
srcs = glob(
46+
allow_empty = True,
47+
include = ["**/*.rs"],
48+
),
49+
tags = [
50+
"cargo-bazel",
51+
"crate-name=external_crate_b",
52+
"manual",
53+
"noclippy",
54+
"norustfmt",
55+
],
56+
target_compatible_with = select({
57+
"@rules_rust//rust/platform:aarch64-apple-darwin": [],
58+
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [],
59+
"@rules_rust//rust/platform:wasm32-unknown-unknown": [],
60+
"@rules_rust//rust/platform:wasm32-wasip1": [],
61+
"@rules_rust//rust/platform:x86_64-pc-windows-msvc": [],
62+
"@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [],
63+
"@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [],
64+
"//conditions:default": ["@platforms//:incompatible"],
65+
}),
66+
version = "0.1.0",
67+
)
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)