Skip to content

Feat: Python version support for pycross_wheel_builder#178

Open
LaurenceTews wants to merge 2 commits intojvolkman:mainfrom
LaurenceTews:ltews-python_version_transition
Open

Feat: Python version support for pycross_wheel_builder#178
LaurenceTews wants to merge 2 commits intojvolkman:mainfrom
LaurenceTews:ltews-python_version_transition

Conversation

@LaurenceTews
Copy link
Contributor

Context

My team is looking to build wheels with multiple version of Python. We've been using the transition in this PR to add python_version support to the pycross_wheel_build rule. It uses the rules_python flag so that Bazel resolves the correct toolchain for the corresponding python_version. This only works for toolchains of type @rules_python//python:toolchain_type and not //pycross:toolchain_type.

Happy to add some tests and update the docs for this if it's something folks would be interested in.

@jvolkman
Copy link
Owner

jvolkman commented Aug 2, 2025

This seems pretty useful. I put together a demo one time, but only setting flags via the CLI: https://github.com/jvolkman/bazel-pycross-zstandard-example

I wonder though whether there's a more composable way to accomplish this? Have you looked at something like https://github.com/fmeum/with_cfg.bzl? I think that should allow creating different version-specific pycross_wheel_build rules.

This only works for toolchains of type @rules_python//python:toolchain_type and not //pycross:toolchain_type

I guess this means this won't support cross-platform builds? What's preventing support for the pycross toolchain?

@LaurenceTews
Copy link
Contributor Author

@jvolkman thanks for your response. with_cfg looks really interesting, it seems like a great option for modifying rules from external repos. In terms of using it inside of rules_pycross, it does create a slightly awkward invocation pattern, since it has to be called from a .bzl file. It would look something like this -

# defs.bzl
pycross_wheel_build_3_10 = versioned_pycross_wheel_build(python_version = "3.10.11")
# BUILD.bazel
load(":defs.bzl", "pycross_wheel_build_3_10")

pycross_wheel_build_3_10(
    name = "zstandard_build",
    config_settings = {
        "--build-option": [
            "--no-cffi-backend",
            "--system-zstd",
        ],
    },
    copts = ["-Wl,-s"],
    native_deps = [
        "//third_party/zstd",
    ],
    post_build_hooks = [
        "@rules_pycross//pycross/hooks:repair_wheel",
    ],
    sdist = "@uv//zstandard:sdist",
    tags = ["manual"],
    deps = [
        "@uv//:setuptools",
        "@uv//:wheel",
    ],
)

Regarding the pycross toolchain, the transition does in fact work for that toolchain type. I didn't realise it uses the same config setting as rules_python. So that's definitely a win.

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.

2 participants