Skip to content

Conversation

@andyscott
Copy link

Adds support for specifying the module name + module prefix for pyo3 extensions.

@andyscott andyscott force-pushed the ags/pyo3-module-path branch from 7a660ad to 3a98fed Compare November 13, 2025 01:56
@andyscott andyscott changed the title pyo3: support module prefix + naming feat: pyo3 support module prefix + naming Nov 13, 2025
@andyscott andyscott force-pushed the ags/pyo3-module-path branch from 35bc452 to e19bd9c Compare November 15, 2025 05:43
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just one question

load("//:defs.bzl", "pyo3_extension")

pyo3_extension(
name = "module_prefix",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why add these attributes and not change the target name to foo/bar?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that first, e.g. for string_sum:

pyo3_extension(
    name = "foo/string_sum",
    srcs = ["string_sum.rs"],
    edition = "2021",
)

Building that target yields this error:

Error in fail: Crate name 'foo/string_sum' contains invalid character(s): /

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were several quirks with getting the names to line up (pymodule <-> output binary <-> crate name) + getting the outputs in the right directory so Python registers it as nested module rather than a top level module. Adding these (hopefully simple) knobs seemed like the cleanest approach.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm nervous about the amount of indirection this introduces. What is the use case here that directory structure can't be made to what you want?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants