From b8f7ae246a782f5331ced0b4328d3fd48fc4382e Mon Sep 17 00:00:00 2001 From: Randolf Jung Date: Thu, 24 Sep 2026 00:43:01 -0700 Subject: [PATCH] cargo: isolate lint extraction tests from production package --- cargo/private/cargo_toml_info/BUILD.bazel | 9 --------- cargo/tests/cargo_toml_info/BUILD.bazel | 10 ++++++++++ .../cargo_toml_info/declared_manifests_test.py | 0 test/integration/cargo_lints/BUILD.bazel | 9 +++++++++ test/integration/cargo_lints/Cargo.toml | 7 +++++++ test/integration/cargo_lints/MODULE.bazel | 7 +++++++ 6 files changed, 33 insertions(+), 9 deletions(-) create mode 100644 cargo/tests/cargo_toml_info/BUILD.bazel rename cargo/{private => tests}/cargo_toml_info/declared_manifests_test.py (100%) create mode 100644 test/integration/cargo_lints/BUILD.bazel create mode 100644 test/integration/cargo_lints/Cargo.toml create mode 100644 test/integration/cargo_lints/MODULE.bazel diff --git a/cargo/private/cargo_toml_info/BUILD.bazel b/cargo/private/cargo_toml_info/BUILD.bazel index 285f002720..bc689230e6 100644 --- a/cargo/private/cargo_toml_info/BUILD.bazel +++ b/cargo/private/cargo_toml_info/BUILD.bazel @@ -1,6 +1,5 @@ """BUILD file for cargo info helper binary.""" -load("@rules_python//python:defs.bzl", "py_test") load("//rust:defs.bzl", "rust_binary", "rust_test") rust_binary( @@ -15,11 +14,3 @@ rust_test( name = "unit_test", crate = ":cargo_toml_info", ) - -py_test( - name = "declared_manifests_test", - srcs = ["declared_manifests_test.py"], - args = ["$(rlocationpath :cargo_toml_info)"], - data = [":cargo_toml_info"], - deps = ["@rules_python//python/runfiles"], -) diff --git a/cargo/tests/cargo_toml_info/BUILD.bazel b/cargo/tests/cargo_toml_info/BUILD.bazel new file mode 100644 index 0000000000..a502e12526 --- /dev/null +++ b/cargo/tests/cargo_toml_info/BUILD.bazel @@ -0,0 +1,10 @@ +load("@rules_python//python:defs.bzl", "py_test") + +# Keep dev-only test rules out of the helper package loaded by downstream users. +py_test( + name = "declared_manifests_test", + srcs = ["declared_manifests_test.py"], + args = ["$(rlocationpath //cargo/private/cargo_toml_info)"], + data = ["//cargo/private/cargo_toml_info"], + deps = ["@rules_python//python/runfiles"], +) diff --git a/cargo/private/cargo_toml_info/declared_manifests_test.py b/cargo/tests/cargo_toml_info/declared_manifests_test.py similarity index 100% rename from cargo/private/cargo_toml_info/declared_manifests_test.py rename to cargo/tests/cargo_toml_info/declared_manifests_test.py diff --git a/test/integration/cargo_lints/BUILD.bazel b/test/integration/cargo_lints/BUILD.bazel new file mode 100644 index 0000000000..bc1ca19730 --- /dev/null +++ b/test/integration/cargo_lints/BUILD.bazel @@ -0,0 +1,9 @@ +load("@rules_rust//cargo:defs.bzl", "extract_cargo_lints") + +# Building this from a downstream module must not load rules_rust's dev dependencies. +# Manual check from this directory: bazel build --lockfile_mode=off //:lints +# Root-module tests cannot reproduce the pruning of dependency dev_dependencies. +extract_cargo_lints( + name = "lints", + manifest = "Cargo.toml", +) diff --git a/test/integration/cargo_lints/Cargo.toml b/test/integration/cargo_lints/Cargo.toml new file mode 100644 index 0000000000..e085c62a18 --- /dev/null +++ b/test/integration/cargo_lints/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "cargo-lints-consumer" +version = "0.1.0" +edition = "2021" + +[lints.rust] +unsafe_code = "forbid" diff --git a/test/integration/cargo_lints/MODULE.bazel b/test/integration/cargo_lints/MODULE.bazel new file mode 100644 index 0000000000..3bbe9506e4 --- /dev/null +++ b/test/integration/cargo_lints/MODULE.bazel @@ -0,0 +1,7 @@ +module(name = "cargo_lints_consumer") + +bazel_dep(name = "rules_rust", version = "0.0.0") +local_path_override( + module_name = "rules_rust", + path = "../../..", +)