pypa / pypa/setuptools

Building Rust code and shipping binary wheels

Open
#435 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug major
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Originally reported by: SimonSapin (Bitbucket: SimonSapin, GitHub: SimonSapin)


This is an assistance request more than a bug report, please let me know if this is not the place to ask.

Rust libraries can provide a C-compatible API that can be used from C or other languages that can call into C like Python. Cargo produces a dynamic/shared library (e.g. a .so file on Linux), and that file can be used with ctypes or CFFI.

This works, but I’d like to package it all in a Python library that integrates with setuptools so that users can pip install it without thinking about Rust. Installing from source would build the Rust code automatically as long as cargo and rustc are somewhere in the user’s PATH. Ideally, I’d also ship platform-specific binary wheels that contain the compiled .so file so that most users don’t even need to have a Rust compiler.

I think I mostly have the first part so far, using a distutils.setup_keywords entry point (inspired by CFFI):

pip install -e . (which uses python setup.py develop) and tox (which uses python setup.py sdist and pip install with the generated .zip file) seem to work, but pip install . (which in recent versions uses python setup.py bdist_wheel) doesn’t: the .whl file (when opened as a ZIP) does not contain the .so file.

I’d appreciate any suggestion on:

  • What is the right place to hook into setuptools for doing this kind of thing? I’ve also tried overriding the build_ext command instead of distutils.setup_keywords.
  • How can I convince bdist_wheel to ship a .so file so that it’s available at run time once the package is installed?
  • Bonus: I’ve managed to make the suffix change from py3-none-any.whl to cp34-cp34m-linux_x86_64.whl by monkey-patching Distribution.is_pure to return false. Can I make it something like any-none-linux_x86_64.whl to make wheels platform-specific (for the binary .so) but independent of the Python version or implementation?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with setup.py and setuptools_ext, then trace the build_ext and bdist_wheel paths used by pip install . and tox. Compare the generated wheel contents and filename with the installed .so and the cargo/rustc build outputs. Done means source installation builds Rust code and the wheel contains the runtime library with appropriate platform and compatibility tags.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.