Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions generation_tests/deleted_file/BUILD.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

rust_library(
name = "lib",
srcs = [
"deleted.rs",
"lib.rs",
],
)
6 changes: 6 additions & 0 deletions generation_tests/deleted_file/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

rust_library(
name = "lib",
srcs = ["lib.rs"],
)
2 changes: 2 additions & 0 deletions generation_tests/deleted_file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Files that no longer exist on disk are removed from existing rules.
Empty file.
1 change: 1 addition & 0 deletions generation_tests/deleted_file/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn lib() {}
Empty file.
11 changes: 11 additions & 0 deletions generation_tests/module_discovery/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

rust_library(
name = "lib",
srcs = [
"bar.rs",
"foo.rs",
"lib.rs",
],
crate_root = "lib.rs",
)
2 changes: 2 additions & 0 deletions generation_tests/module_discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

lib.rs crate roots discover their modules via mod declarations.
Empty file.
1 change: 1 addition & 0 deletions generation_tests/module_discovery/bar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn bar() {}
1 change: 1 addition & 0 deletions generation_tests/module_discovery/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub fn foo() {}
2 changes: 2 additions & 0 deletions generation_tests/module_discovery/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod foo;
mod bar;
Empty file.
10 changes: 10 additions & 0 deletions generation_tests/subdir_module/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

rust_library(
name = "lib",
srcs = [
"lib.rs",
"subdir/mod.rs",
],
crate_root = "lib.rs",
)
9 changes: 9 additions & 0 deletions generation_tests/subdir_module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

When lib.rs declares `mod subdir;` pointing to subdir/mod.rs, the module file
should be included in the parent crate's srcs and NOT get its own rust_library
target in the subdirectory.

This tests that:
1. lib.rs crate roots discover modules in subdirectories.
2. Subdirectory BUILD files don't create rust rules for files claimed by a parent crate.
3. Unclaimed files in the subdirectory still get their own rules.
Empty file.
3 changes: 3 additions & 0 deletions generation_tests/subdir_module/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod subdir;

pub use subdir::greet;
Empty file.
6 changes: 6 additions & 0 deletions generation_tests/subdir_module/subdir/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_test")

rust_test(
name = "standalone_test",
srcs = ["standalone_test.rs"],
)
3 changes: 3 additions & 0 deletions generation_tests/subdir_module/subdir/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn greet() -> &'static str {
"Hello from subdir module"
}
4 changes: 4 additions & 0 deletions generation_tests/subdir_module/subdir/standalone_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_standalone() {
assert!(true);
}
Empty file.
12 changes: 12 additions & 0 deletions generation_tests/subdir_module_adjacent/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("@rules_rust//rust:defs.bzl", "rust_library")

rust_library(
name = "lib",
srcs = [
"lib.rs",
"parent.rs",
"parent/child.rs",
"parent/child/grandchild.rs",
],
crate_root = "lib.rs",
)
14 changes: 14 additions & 0 deletions generation_tests/subdir_module_adjacent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

Tests the adjacent file module style (introduced in Rust 2018) where modules use
parent.rs instead of parent/mod.rs.

Structure:
- lib.rs declares `mod parent;`
- parent.rs (adjacent file style) declares `mod child;`
- parent/child.rs declares `mod grandchild;`
- parent/child/grandchild.rs is claimed by the root lib.rs crate

This tests that:
1. Adjacent file module discovery works (parent.rs instead of parent/mod.rs).
2. Deeply nested modules are correctly claimed through intermediate adjacent-style modules.
3. Unclaimed files in subdirectories still get their own rules.
Empty file.
3 changes: 3 additions & 0 deletions generation_tests/subdir_module_adjacent/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod parent;

pub use parent::greet;
4 changes: 4 additions & 0 deletions generation_tests/subdir_module_adjacent/parent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mod child;

pub use child::greet;
pub use child::nested_greet;
Empty file.
11 changes: 11 additions & 0 deletions generation_tests/subdir_module_adjacent/parent/BUILD.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

rust_test(
name = "standalone_test",
srcs = ["standalone_test.rs"],
)

rust_library(
name = "util",
srcs = ["util.rs"],
)
7 changes: 7 additions & 0 deletions generation_tests/subdir_module_adjacent/parent/child.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
mod grandchild;

pub use grandchild::nested_greet;

pub fn greet() -> &'static str {
"Hello from child module"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
load("@rules_rust//rust:defs.bzl", "rust_test")

rust_test(
name = "standalone_test",
srcs = ["standalone_test.rs"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn nested_greet() -> &'static str {
"Hello from grandchild module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_deep_standalone() {
assert!(true);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#[test]
fn test_standalone() {
assert!(true);
}
3 changes: 3 additions & 0 deletions generation_tests/subdir_module_adjacent/parent/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn helper() -> i32 {
42
}
Loading