Skip to content

wildcard use don't seem to work for pyo3_library? #3673

@dougthor42

Description

@dougthor42

Note: this issue was manually migrated from abrisco/rules_pyo3#44

Summary

It seems like wildcard use statements from pyo3 fail when migrating a rust_shared_library to a pyo3_library target.

If I go through the code base and replace all wildcard use statements with explicit ones (use pyo3::prelude::{PyModule, Py, ...}) then I can get things working, but that's not really a viable long-term solution.

Given:

use pyo3::prelude::*;

...

let loader = Py::new(py, Self::new(name))?;  // and similar.

rust_shared_library works:

# rust/rupyle/BUILD.bazel
load("@rules_rust//rust:defs.bzl", "rust_shared_library")
rust_shared_library(
    name = "rupyle",
    ...,
)
$ bazel build //rust/rupyle --experimental_ui_max_stdouterr_bytes=3000000
INFO: Invocation ID: d106bba8-faf2-4dff-b634-2ffe840d14c0
INFO: Analyzed target //rust/rupyle:rupyle (1 packages loaded, 55 targets configured).
INFO: Found 1 target...
Target //rust/rupyle:rupyle up-to-date:
  bazel-bin/rust/rupyle/librupyle.so
INFO: Elapsed time: 1.819s, Critical Path: 1.49s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

pyo3_extension doesn't work:

load("@rules_pyo3//pyo3:defs.bzl", "pyo3_extension")
pyo3_extension(
    name = "rupyle",
    ...,
)

No other changes made:

--- a/rust/rupyle/BUILD.bazel
+++ b/rust/rupyle/BUILD.bazel
@@ -1,6 +1,7 @@
 load("@rules_python//python:defs.bzl", "py_library")
 load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
-load("@rules_rust//rust:defs.bzl", "rust_shared_library", "rust_test")
+load("@rules_rust//rust:defs.bzl", "rust_test")
+load("@rules_rust_pyo3//:defs.bzl", "pyo3_extension")
 
 # Don't generate targets for files in the python directory - they should all be .pyi type
 # stub files and do not need targets. Including a target for, say, the __init__.py file results
@@ -10,7 +11,7 @@ load("@rules_rust//rust:defs.bzl", "rust_shared_library", "rust_test")
 # when running gazelle generation on it (which is done for all @pypi// deps).
 # gazelle:exclude python
 
-rust_shared_library(
+pyo3_extension(
     name = "rupyle",
     srcs = glob(["src/**/*.rs"]),
     compile_data = [

Error:

$ bazel build //rust/rupyle --experimental_ui_max_stdouterr_bytes=3000000
...
error[E0433]: failed to resolve: use of undeclared type `PyModule`
   --> bazel-out/k8-opt/bin/rust/rupyle/src/wsupp.rs:184:13
    |
184 |     let m = PyModule::new(py, "wsupp")?;
    |             ^^^^^^^^ use of undeclared type `PyModule`

error[E0433]: failed to resolve: use of undeclared type `PyModule`
   --> bazel-out/k8-opt/bin/rust/rupyle/src/xeb.rs:308:13
    |
308 |     let m = PyModule::new(py, "xeb")?;
    |             ^^^^^^^^ use of undeclared type `PyModule`

error[E0433]: failed to resolve: use of undeclared type `Py`
  --> bazel-out/k8-opt/bin/rust/rupyle/src/lib.rs:70:22
   |
70 |         let loader = Py::new(py, Self::new(name))?;
   |                      ^^ use of undeclared type `Py`

error: aborting due to 3412 previous errors; 1 warning emitted

Some errors have detailed explanations: E0106, E0119, E0223, E0405, E0412, E0432, E0433, E0464, E0599.
For more information about an error, try `rustc --explain E0106`.
Target //rust/rupyle:rupyle failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 57.701s, Critical Path: 57.02s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully

Other Info:

  • Using bzlmod
  • pyo3 version in our Cargo.toml: 0.25.1
    • However, we're using the default toolchains (I'm currently trying to test using a custom toolchain):
      # MODULE.bazel
      register_toolchains(
          "@rules_rust_pyo3//toolchains:toolchain",
          "@rules_rust_pyo3//toolchains:rust_toolchain",
      )
      
  • rules_rust version: 0.66.0
  • rules_rust_pyo3 version: 0.66.0 (Feb 22, 2025)
  • rust Edition: 2024
  • rust Version: 1.88.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions