Skip to content

Commit

Permalink
Vendor Rust crates into source distributions
Browse files Browse the repository at this point in the history
`vendor_rust()` takes an existing sdist tar ball and creates a new sdist
with all Rust crates vendored. This allows offline compilation without
downloading any Rust crates at build time.

Switch from `tomli` to `toml`. The `tomli` package does not have write
support.

I have successfully wheel builds with vendored crates for

- `cryptography-42.0.7.tar.gz`
- `maturin-1.5.1.tar.gz`
- `pydantic_core-2.18.4.tar.gz`
- `setuptools-rust-1.9.0.tar.gz`

with `CARGO_NET_OFFLINE=true python3 -m build -w`.

Signed-off-by: Christian Heimes <[email protected]>
  • Loading branch information
tiran committed Jun 5, 2024
1 parent 9ac8e68 commit 04331f1
Show file tree
Hide file tree
Showing 14 changed files with 546 additions and 3 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
rust-version:
# RHEL 9.4 has rustc 1.75
- "1.75"

steps:
- name: Get source
Expand All @@ -26,12 +29,23 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set up Rust ${{ matrix.rust-version }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust-version }}
default: true
override: true

- name: Install dependencies
run: python -m pip install tox

- name: Run tests
run: tox -e py

- name: Run tests for pyo3_test
working-directory: ./e2e/pyo3_test/
run: tox -e py

e2e:
name: e2e
runs-on: ubuntu-latest
Expand All @@ -43,6 +57,9 @@ jobs:
- "3.10"
- "3.11"
- "3.12"
rust-version:
# RHEL 9.4 has rustc 1.75
- "1.75"
test-script:
- bootstrap
- report_missing_dependency
Expand All @@ -58,6 +75,13 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Set up Rust ${{ matrix.rust-version }}
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust-version }}
default: true
override: true

- name: Install dependencies
run: python -m pip install tox

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ __pycache__/
/package.json
/e2e-output/
/dist/
/e2e/pyo3_test/.cargo
/e2e/pyo3_test/build
/e2e/pyo3_test/dist
/e2e/pyo3_test/target
/e2e/pyo3_test/vendor
295 changes: 295 additions & 0 deletions e2e/pyo3_test/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions e2e/pyo3_test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "pyo3_test"
version = "1.0.0"
edition = "2021"

[dependencies]
pyo3 = { version = "0.21.2", features = ["gil-refs"] }

[lib]
name = "_lib"
crate-type = ["cdylib"]
path = "rust/lib.rs"
4 changes: 4 additions & 0 deletions e2e/pyo3_test/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
graft python
graft rust
include Cargo.toml Cargo.lock tests.py tox.ini
exclude .cargo vendor
13 changes: 13 additions & 0 deletions e2e/pyo3_test/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[build-system]
requires = ["setuptools", "setuptools-rust"]
build-backend = "setuptools.build_meta"

[project]
name = "pyo3_test"
version = "1.0.0"

[tool.setuptools.packages]
find = { where = ["python"] }

[[tool.setuptools-rust.ext-modules]]
target = "pyo3_test._lib"
3 changes: 3 additions & 0 deletions e2e/pyo3_test/python/pyo3_test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._lib import add

__all__ = ["add"]
Loading

0 comments on commit 04331f1

Please sign in to comment.