Allow lint configuration on PyO3 extensions (#4256)
`pyo3_extension` forwards its remaining `**kwargs` to both
`rust_shared_library` and `py_pyo3_library`. As a result, the valid Rust
`lint_config` attribute reaches the generated Python target and is
rejected during analysis.
Make `lint_config` an explicit argument and forward it only to the Rust
shared library. The existing PyO3 integration test now supplies a
`rust_lint_config`, covering both attribute acceptance and successful
extension compilation/import.
Fixes #4255.
Validation:
- `bazelisk test //...` from `extensions/pyo3` (20 passed, 3
platform-specific tests skipped)
- Buildifier formatting and lint checks on the changed Starlark and
BUILD files
diff --git a/extensions/pyo3/private/pyo3.bzl b/extensions/pyo3/private/pyo3.bzl
index dff1998..0bd0e3b 100644
--- a/extensions/pyo3/private/pyo3.bzl
+++ b/extensions/pyo3/private/pyo3.bzl
@@ -249,6 +249,7 @@
data = [],
deps = [],
edition = None,
+ lint_config = None,
imports = [],
proc_macro_deps = [],
rustc_env = {},
@@ -284,6 +285,8 @@
For more details see [rust_shared_library][rsl].
edition (str, optional): The rust edition to use for this crate. Defaults to the edition specified in the rust_toolchain.
For more details see [rust_shared_library][rsl].
+ lint_config (Label, optional): A target providing the lint configuration for the Rust shared library.
+ For more details see [rust_shared_library][rsl].
imports (list, optional): List of import directories to be added to the `PYTHONPATH`.
For more details see [py_library.imports][pli].
proc_macro_deps (list, optional): List of `rust_proc_macro` targets used to help build this library target.
@@ -335,6 +338,7 @@
Label("//private:current_rust_pyo3_toolchain"),
] + deps,
edition = edition,
+ lint_config = lint_config,
proc_macro_deps = proc_macro_deps,
rustc_env = rustc_env,
rustc_env_files = rustc_env_files,
diff --git a/extensions/pyo3/test/string_sum/BUILD.bazel b/extensions/pyo3/test/string_sum/BUILD.bazel
index 8a14cad..1bf678c 100644
--- a/extensions/pyo3/test/string_sum/BUILD.bazel
+++ b/extensions/pyo3/test/string_sum/BUILD.bazel
@@ -1,10 +1,17 @@
load("@rules_python//python:defs.bzl", "py_test")
+load("@rules_rust//rust:defs.bzl", "rust_lint_config")
load("//:defs.bzl", "pyo3_extension")
+rust_lint_config(
+ name = "lints",
+ rustc = {"unknown_lints": "allow"},
+)
+
pyo3_extension(
name = "string_sum",
srcs = ["string_sum.rs"],
edition = "2021",
+ lint_config = ":lints",
)
py_test(