Skip to content

Conversation

@emmatyping
Copy link
Owner

@emmatyping emmatyping commented Nov 14, 2025

This PR introduces a plausible approach for introducing Rust as an optional build dependency for CPython. A few changes are necessary to accomplish this:

  • Configure detects cargo
  • maksetup is updated to handle Rust extension modules modules
  • A Cargo workspace is introduced for all CPython modules.
  • Bindings of the C API via bindgen are generated in Modules/cpython-sys. This isn't super well integrated into the Makefile right now. It requires running make regen-rust-wrapper-h to generate the wrapper first, then you can run make normally.
  • An example extension module _base64 is added, which has a single function standard_b64encode

There are also a lot of other caveats and limitations. I tested this with gcc and clang on a Linux system, with a GIL-ful build. There's no Mac or Windows support yet, or support for other platforms, but I believe Mac WASI Android and iOS may not be too hard since they share the same build system as Linux..

Windows will require a different approach. I'm not sure yet on how exactly we should do that.

Rough series of commands to get things working:
Install Rust and make sure cargo is available.

./configure --with-rust-base64
make regen-rust-wrapper-h
make -j$(nproc)

@emmatyping emmatyping changed the title MVP of Rust in CPython Proof of Concept of Rust in CPython Nov 17, 2025
emmatyping and others added 3 commits November 16, 2025 23:59
This commit updates the build system to automatically detect cargo and
enable/disable _base64 without needing to pass a flag. If cargo is unavailable, _base64 is disabled.

It also updates cpython-sys to use a hand written header (which is what
Linux seems to do) and splits off the parser bindings to be handled in
the future (since the files are included differently).
There are still some issues with compilation, but those can be sorted out in a future PR.
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.

4 participants