Skip to content

feat(pypi): support cross-compiling C/C++ sdists in py_sdist_wheel - #4591

Open
rsartor-cmd wants to merge 1 commit into
rsartor-cmd/consume-sdist-part-1-sdist-wheelfrom
rsartor-cmd/consume-sdist-part-2-cross-compile
Open

rsartor-cmd wants to merge 1 commit into
rsartor-cmd/consume-sdist-part-1-sdist-wheelfrom
rsartor-cmd/consume-sdist-part-2-cross-compile

Conversation

@rsartor-cmd

Copy link
Copy Markdown
Collaborator

Stacked on #4590 (rsartor-cmd/consume-sdist-part-1-sdist-wheel).

Currently, py_sdist_wheel refuses to build when the target platform
differs from the host platform, preventing cross-compilation of C/C++
extensions from source distributions.

This change wires the target CC and Python C-header toolchains into
py_sdist_wheel and sdist_wheel_builder.py so C/C++ sdists can be
cross-compiled inside Bazel build actions:

  • Extracts target CC/C++/AR tool paths, compile/link flags, static
    runtime libraries, target SOABI, and target Python.h include
    directories in py_sdist_wheel.

  • Absolutizes execroot-relative paths in compiler/linker flags, strips
    redacted date/time macros, prefers link-action -resource-dir=, and
    synthesizes target _sysconfigdata with target INCLUDEPY.

  • Generates meson-cross.ini for meson-python builds (including
    longdouble_format and a Zig ar-no-thin wrapper for
    hermetic_cc_toolchain), isolates PKG_CONFIG_LIBDIR for mesonpy
    builds so host pkg-config does not shadow hermetic Python headers,
    and exposes sibling bin/ directories from classic whl_library
    build dependencies.

  • Adds unit tests for flag absolutization/sanitization in
    tests/pypi/py_sdist_wheel/sdist_wheel_builder_test.py.

  • Adds a standalone examples/sdist_cross_compile/ workspace verifying
    native x86_64 and x86_64 -> aarch64 (hermetic-llvm) builds of
    setuptools C and meson-python C/C++17 sdists.

Currently, `py_sdist_wheel` refuses to build when the target platform
differs from the host platform, preventing cross-compilation of C/C++
extensions from source distributions.

This change wires the target CC and Python C-header toolchains into
`py_sdist_wheel` and `sdist_wheel_builder.py` so C/C++ sdists can be
cross-compiled inside Bazel build actions:

* Extracts target CC/C++/AR tool paths, compile/link flags, static
  runtime libraries, target `SOABI`, and target `Python.h` include
  directories in `py_sdist_wheel`.
* Absolutizes execroot-relative paths in compiler/linker flags, strips
  redacted date/time macros, prefers link-action `-resource-dir=`, and
  synthesizes target `_sysconfigdata` with target `INCLUDEPY`.
* Generates `meson-cross.ini` for `meson-python` builds (including
  `longdouble_format` and a Zig `ar-no-thin` wrapper for
  `hermetic_cc_toolchain`), isolates `PKG_CONFIG_LIBDIR` for `mesonpy`
  builds so host `pkg-config` does not shadow hermetic Python headers,
  and exposes sibling `bin/` directories from classic `whl_library`
  build dependencies.

* Adds unit tests for flag absolutization/sanitization in
  `tests/pypi/py_sdist_wheel/sdist_wheel_builder_test.py`.
* Adds a standalone `examples/sdist_cross_compile/` workspace verifying
  native `x86_64` and `x86_64 -> aarch64` (`hermetic-llvm`) builds of
  setuptools C and `meson-python` C/C++17 sdists.
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

This branch has not been deployed

No deployments
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.

1 participant