Skip to content

Commit

Permalink
Add pyo3-mixed-legacy crate to test cross-compilation with older pyo3…
Browse files Browse the repository at this point in the history
… (for Python 3.6 support).
  • Loading branch information
Ashley Anderson committed Dec 3, 2021
1 parent 0013ef2 commit 83482c1
Show file tree
Hide file tree
Showing 17 changed files with 395 additions and 12 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,19 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
crate:
# this crate depends on a current/new version of pyo3
- name: pyo3-mixed
lib_dir: ""
# this crate depends on an older version of pyo3 (0.15.1)
# previous versions of pyo3 required PYO3_CROSS_LIB_DIR to have /lib at the end
- name: pyo3-mixed-legacy
lib_dir: /lib
platform:
# CPython
- target: aarch64-unknown-linux-gnu
arch: aarch64
abi: cp37-cp37m
abi: cp36-cp36m
- target: armv7-unknown-linux-gnueabihf
arch: armv7
abi: cp39-cp39
Expand All @@ -229,14 +237,23 @@ jobs:
- target: aarch64-unknown-linux-gnu
arch: aarch64
abi: pp38-pypy38_pp73
exclude:
# pyo3-mixed-legacy depends on older pyo3 which does not support pypy cross-compilation
- crate: { name: pyo3-mixed-legacy }
platform: { abi: pp37-pypy37_pp73 }
- crate: { name: pyo3-mixed-legacy }
platform: { abi: pp38-pypy38_pp73 }
# pyo3-mixed depends on newer pyo3 which does not support Python 3.6
- crate: { name: pyo3-mixed }
platform: { abi: cp36-cp36m }
steps:
- uses: actions/checkout@v2
- name: Build Wheels
run: |
echo 'curl -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable --profile minimal
source ~/.cargo/env
rustup target add ${{ matrix.platform.target }}
export PYO3_CROSS_LIB_DIR=/opt/python/${{ matrix.platform.abi }}
cargo run --target x86_64-unknown-linux-gnu -- build -i python3.9 --release --out dist --no-sdist --target ${{ matrix.platform.target }} -m test-crates/pyo3-mixed/Cargo.toml
export PYO3_CROSS_LIB_DIR=/opt/python/${{ matrix.platform.abi }}${{ matrix.crate.lib_dir }}
cargo run --target x86_64-unknown-linux-gnu -- build -i python3.9 --release --out dist --no-sdist --target ${{ matrix.platform.target }} -m test-crates/${{ matrix.crate.name }}/Cargo.toml
' > build-wheel.sh
docker run --rm -v "$PWD":/io -w /io messense/manylinux2014-cross:${{ matrix.platform.arch }} bash build-wheel.sh
2 changes: 1 addition & 1 deletion Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ ignore = "0.4.18"
dialoguer = "0.9.0"
console = "0.15.0"
minijinja = "0.8.2"
pyo3-build-config = { git = "https://github.com/aganders3/pyo3", branch = "expose-cross-compiling" }
pyo3-build-config = { git = "https://github.com/aganders3/pyo3", branch = "expose-cross-compiling" } # TODO: update after merge/release in pyo3
# pyo3-build-config = { path = "/io/pyo3/pyo3-build-config" } # for local dev TODO: remove this line

[dev-dependencies]
indoc = "1.0.3"
Expand Down
4 changes: 3 additions & 1 deletion src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ impl Target {
///
/// Fails if the target triple isn't supported
pub fn from_target_triple(target_triple: Option<String>) -> Result<Self> {
let host = get_host_target()?;
let (platform, triple) = if let Some(ref target_triple) = target_triple {
let platform: Triple = target_triple
.parse()
.map_err(|_| format_err!("Unknown target triple {}", target_triple))?;
(platform, target_triple.to_string())
} else {
let target_triple = get_host_target()?;
let target_triple = host; // get_host_target()?;
let platform: Triple = target_triple
.parse()
.map_err(|_| format_err!("Unknown target triple {}", target_triple))?;
Expand Down Expand Up @@ -184,6 +185,7 @@ impl Target {
triple,
cross_compiling: false,
};
// TODO: replace with pyo3-build-config::cross_compiling
target.cross_compiling = is_cross_compiling(&target)?;
Ok(target)
}
Expand Down
257 changes: 257 additions & 0 deletions test-crates/pyo3-mixed-legacy/Cargo.lock

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

14 changes: 14 additions & 0 deletions test-crates/pyo3-mixed-legacy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
authors = ["konstin <[email protected]>"]
name = "pyo3-mixed"
version = "2.1.3"
description = "Implements a dummy function combining rust and python"
readme = "Readme.md"
edition = "2018"

[dependencies]
pyo3 = { version = "0.15.1", features = ["extension-module"] }

[lib]
name = "pyo3_mixed"
crate-type = ["cdylib"]
30 changes: 30 additions & 0 deletions test-crates/pyo3-mixed-legacy/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# pyo3-mixed

A package for testing maturin with a mixed pyo3/python project.

## Usage

```bash
pip install .
```

```python
import pyo3_mixed
assert pyo3_mixed.get_42() == 42
```

## Testing

Install tox:

```bash
pip install tox
```

Run it:

```bash
tox
```

The tests are in `test_pyo3_mixed.py`, while the configuration is in tox.ini
Loading

0 comments on commit 83482c1

Please sign in to comment.