Skip to content

Commit

Permalink
(Fix): Improve compatibility of python bindings (#147)
Browse files Browse the repository at this point in the history
Adds features [abi3-py39](https://pyo3.rs/v0.14.5/features.html#abi3-py36--abi3-py37--abi3-py38--abi3-py39), to support more python versions, and [extension-module](https://pyo3.rs/v0.14.5/features.html#extension-module), to skip linking against `libpython.so`. `extension-module` can only be applied on Linux. Also fixes the version to be compatible on Glue (see [openssl note](openssl/openssl#25366)).

Works in our CI setup
  • Loading branch information
TylerJang27 authored Nov 1, 2024
1 parent 046e34b commit 0452ac0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/pyo3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.10"
python-version: "3.9"
- uses: trunk-io/trunk-action/setup@v1
- name: Setup Rust & Cargo
uses: ./.github/actions/setup_rust_cargo
Expand All @@ -44,18 +44,18 @@ jobs:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter --manifest-path ./context-py/Cargo.toml
manylinux: auto
container: "2_28"
# Required version in order to support Glue
container: "2_17"
before-script-linux: |
# Needed for `openssl-sys`:
# https://docs.rs/openssl/latest/openssl/
if [ -f /usr/bin/dnf ]; then
# quay.io/pypa/manylinux_2_28_x86_64:latest
/usr/bin/dnf -y upgrade
/usr/bin/dnf -y install pkgconf perl-IPC-Cmd openssl-devel python3-pip
if [ -f /usr/bin/yum ]; then
# quay.io/pypa/manylinux2014_x86_64:latest
/usr/bin/yum -y upgrade
/usr/bin/yum -y install perl-IPC-Cmd perl-List-MoreUtils openssl-devel python3-pip
/usr/bin/ln -s /usr/bin/pip3 /usr/bin/pip
/usr/bin/ln -sf /usr/bin/python3.11 /usr/bin/python3
elif [ -f /usr/bin/apt ]; then
# ghcr.io/rust-cross/manylinux_2_28-cross:aarch64
# ghcr.io/rust-cross/manylinux2014-cross:aarch64
/usr/bin/apt update
/usr/bin/apt install -y pkg-config libssl-dev
fi
Expand Down
6 changes: 4 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ codeowners = { path = "../codeowners" }
xcresult = { path = "../xcresult" }
sentry = { version = "0.34.0", features = ["debug-images"] }
openssl = { version = "0.10.66", features = ["vendored"] }
openssl-src = "=300.3.1+3.3.1"
uuid = { version = "1.10.0", features = ["v5"] }
quick-junit = "0.5.0"
colored = "2.1.0"
Expand Down
7 changes: 6 additions & 1 deletion context-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,10 @@ path = "bin/stub_gen.rs"

[dependencies]
context = { path = "../context", features = ["git-access", "pyo3"] }
pyo3 = "0.22.5"
pyo3-stub-gen = "0.6.0"

[target.'cfg(target_os = "linux")'.dependencies]
pyo3 = { version = "0.22.5", features = ["abi3-py39", "extension-module"] }

[target.'cfg(target_os = "macos")'.dependencies]
pyo3 = { version = "0.22.5", features = ["abi3-py39"] }
11 changes: 10 additions & 1 deletion context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gix = { version = "0.63.0", default-features = false, features = [
], optional = true }
js-sys = { version = "0.3.70", optional = true }
openssl = { version = "0.10.66", features = ["vendored"], optional = true }
pyo3 = { version = "0.22.5", optional = true }
openssl-src = { version = "=300.3.1+3.3.1", optional = true }
pyo3-stub-gen = { version = "0.6.0", optional = true }
quick-junit = "0.5.0"
quick-xml = "0.36.2"
Expand All @@ -28,6 +28,15 @@ thiserror = "1.0.63"
uuid = { version = "1.10.0", features = ["v5"] }
wasm-bindgen = { version = "0.2.84", optional = true }

[target.'cfg(target_os = "linux")'.dependencies]
pyo3 = { version = "0.22.5", optional = true, features = [
"abi3-py39",
"extension-module",
] }

[target.'cfg(target_os = "macos")'.dependencies]
pyo3 = { version = "0.22.5", optional = true, features = ["abi3-py39"] }

[features]
default = ["git-access"]
git-access = ["dep:gix", "dep:openssl"]
Expand Down

0 comments on commit 0452ac0

Please sign in to comment.