diff --git a/cargo/private/cargo_lints.bzl b/cargo/private/cargo_lints.bzl index 28d6ebfb98..4f3b78f709 100644 --- a/cargo/private/cargo_lints.bzl +++ b/cargo/private/cargo_lints.bzl @@ -67,7 +67,7 @@ extract_cargo_lints = rule( "_cargo_toml_info": attr.label( allow_single_file = True, executable = True, - default = "@rules_rust//cargo/private/cargo_toml_info", + default = Label("//cargo/private/cargo_toml_info:cargo_toml_info"), cfg = "exec", ), }, diff --git a/examples/WORKSPACE.bazel b/examples/WORKSPACE.bazel index b1bb3bd170..ddabbc7451 100644 --- a/examples/WORKSPACE.bazel +++ b/examples/WORKSPACE.bazel @@ -28,6 +28,10 @@ load("@rules_rust//tools/rust_analyzer:deps.bzl", "rust_analyzer_dependencies") rust_analyzer_dependencies() +load("@rules_rust//cargo:deps.bzl", "cargo_dependencies") + +cargo_dependencies() + load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # We need to load rules_java before anything proto-related happens because otherwise it will pull in its own rules_java which isn't compatible with rules_jvm_external. diff --git a/examples/bazel_env/rust/hello_world/BUILD.bazel b/examples/bazel_env/rust/hello_world/BUILD.bazel index 0f5efa03f1..4d39775595 100644 --- a/examples/bazel_env/rust/hello_world/BUILD.bazel +++ b/examples/bazel_env/rust/hello_world/BUILD.bazel @@ -1,5 +1,6 @@ load("@crates//:defs.bzl", "all_crate_deps") -load("@rules_rust//rust:defs.bzl", "rust_binary") +load("@rules_rust//cargo:defs.bzl", "extract_cargo_lints") +load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_lint_config") package(default_visibility = ["//visibility:public"]) @@ -8,8 +9,26 @@ exports_files([ "src/main.rs", ]) +rust_lint_config( + name = "lints", + rustc = {"dead_code": "allow"}, +) + rust_binary( name = "hello_world", srcs = ["src/main.rs"], + lint_config = ":lints", + deps = all_crate_deps(normal = True), +) + +extract_cargo_lints( + name = "cargo_lints", + manifest = "Cargo.toml", +) + +rust_binary( + name = "hello_world_with_lints", + srcs = ["src/main.rs"], + lint_config = ":hello_world_lints", deps = all_crate_deps(normal = True), ) diff --git a/examples/bazel_env/rust/hello_world/Cargo.toml b/examples/bazel_env/rust/hello_world/Cargo.toml index 425434ee15..e2d6a3b9f1 100644 --- a/examples/bazel_env/rust/hello_world/Cargo.toml +++ b/examples/bazel_env/rust/hello_world/Cargo.toml @@ -6,3 +6,6 @@ publish = false [lib] path = "fake.rs" + +[lints.rust] +dead_code = "deny" diff --git a/examples/bazel_env/rust/hello_world/src/main.rs b/examples/bazel_env/rust/hello_world/src/main.rs index 317f564583..4fce12ce67 100644 --- a/examples/bazel_env/rust/hello_world/src/main.rs +++ b/examples/bazel_env/rust/hello_world/src/main.rs @@ -15,3 +15,7 @@ fn main() { println!("Hello, world!"); } + +fn unused(x: usize) -> String { + format!("I am unused {x}") +} diff --git a/examples/cargo_lints/BUILD.bazel b/examples/cargo_lints/BUILD.bazel new file mode 100644 index 0000000000..d3c96124b0 --- /dev/null +++ b/examples/cargo_lints/BUILD.bazel @@ -0,0 +1,26 @@ +load("@rules_rust//cargo:defs.bzl", "extract_cargo_lints") +load("@rules_rust//rust:defs.bzl", "rust_clippy", "rust_doc", "rust_library") + +package(default_visibility = ["//visibility:public"]) + +extract_cargo_lints( + name = "hello_world_lints", + manifest = "Cargo.toml", +) + +rust_library( + name = "hello_world", + srcs = ["src/lib.rs"], + edition = "2021", + lint_config = ":hello_world_lints", +) + +rust_clippy( + name = "hello_world_clippy", + deps = [":hello_world"], +) + +rust_doc( + name = "hello_world_doc", + crate = ":hello_world", +) diff --git a/examples/cargo_lints/Cargo.lock b/examples/cargo_lints/Cargo.lock new file mode 100644 index 0000000000..ce5ee3d097 --- /dev/null +++ b/examples/cargo_lints/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "hello_world" +version = "0.1.0" diff --git a/examples/cargo_lints/Cargo.toml b/examples/cargo_lints/Cargo.toml new file mode 100644 index 0000000000..7ea9159677 --- /dev/null +++ b/examples/cargo_lints/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "hello_world" +version = "0.1.0" +edition = "2021" + +[dependencies] + + +[lints.rust] +unknown_lints = "warn" +dead_code = "deny" + +[lints.clippy] +box_default = "deny" + +[lints.rustdoc] +invalid_html_tags = "deny" diff --git a/examples/cargo_lints/src/lib.rs b/examples/cargo_lints/src/lib.rs new file mode 100644 index 0000000000..8ac1bd95e0 --- /dev/null +++ b/examples/cargo_lints/src/lib.rs @@ -0,0 +1,10 @@ +///