Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: increase range of python FFI support #870

Merged
merged 23 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 41 additions & 22 deletions .github/workflows/build-python-release.reusable.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: Release language_client_python

on:
workflow_call: {}
push:
branches: [sam/glibc-aarch64]

concurrency:
# suffix is important to prevent a concurrency deadlock with the calling workflow
Expand All @@ -14,28 +16,41 @@ jobs:
fail-fast: false
matrix:
_:
- runs_on: ubuntu-latest
target: x86_64
name: x86_64-unknown-linux-gnu
manylinux: 'auto'
- target: x86_64-unknown-linux-gnu
runs_on: ubuntu-latest

- runs_on: ubuntu-latest
target: aarch64
name: aarch64-unknown-linux-gnu
manylinux: '2_28'
- target: aarch64-unknown-linux-gnu
runs_on: ubuntu-latest
manylinux: 2_24
# I'm not sure if this actually works; I can't 'pip install ./local-path.whl'
# from inside a container based off quay.io/pypa/manylinux2014_aarch64
# see https://github.com/astral-sh/uv/issues/3439#issuecomment-2110448346
# manylinux: 2_28
# env:
# # Workaround ring 0.17 build issue
# # see https://github.com/briansmith/ring/issues/1728
# CFLAGS_aarch64_unknown_linux_gnu: "-D__ARM_ARCH=8"

- runs_on: macos-latest
target: x86_64
name: x86_64-apple-darwin
- target: x86_64-unknown-linux-musl
runs_on: ubuntu-latest
# see https://github.com/astral-sh/uv/blob/9bb55c4ac0582e05d1a7a5bbd99cc7b2c82f1847/.github/workflows/build-binaries.yml#L594
manylinux: musllinux_1_1

- runs_on: macos-latest
target: aarch64
name: aarch64-apple-darwin

- runs_on: windows-latest
target: x64
name: x86_64-pc-windows-msvc
- target: aarch64-unknown-linux-musl
runs_on: ubuntu-latest
# see https://github.com/astral-sh/uv/blob/9bb55c4ac0582e05d1a7a5bbd99cc7b2c82f1847/.github/workflows/build-binaries.yml#L594
manylinux: musllinux_1_1

- target: x86_64-apple-darwin
runs_on: macos-latest

- target: aarch64-apple-darwin
runs_on: macos-latest

- target: x86_64-pc-windows-msvc
runs_on: windows-latest

name: ${{ matrix._.target }}
runs-on: ${{ matrix._.runs_on }}
steps:
- uses: actions/checkout@v4
Expand All @@ -46,23 +61,27 @@ jobs:

- name: Build wheels
uses: PyO3/maturin-action@v1
env: ${{ matrix._.env || fromJSON('{}') }}
with:
target: ${{ matrix._.target }}
command: build
args: --release --out engine/language_client_python/dist --manifest-path engine/language_client_python/Cargo.toml
# building in engine/ ensures that we pick up .cargo/config.toml
working-directory: engine
args: --release --out language_client_python/dist --manifest-path language_client_python/Cargo.toml
sccache: "true"
manylinux: ${{ matrix._.manylinux }}
before-script-linux: |
if command -v yum &> /dev/null; then
yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic
else
# If we're running on debian-based system.
apt update -y && apt-get install -y libssl-dev openssl pkg-config
# sudo apt update -y && apt-get install -y libssl-dev openssl pkg-config
:
fi

- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix._.name }}
name: wheels-${{ matrix._.target }}
path: engine/language_client_python/dist
if-no-files-found: error
if-no-files-found: error
4 changes: 3 additions & 1 deletion engine/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# https://github.com/rust-lang/cargo/issues/8607
[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=-crt-static"]
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM quay.io/pypa/manylinux2014_aarch64 as base
RUN yum install python3-pip -y

ADD ../baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
RUN pip3 install ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

ENV RUST_LOG=trace
RUN baml-cli --help
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ghcr.io/rust-cross/rust-musl-cross:aarch64-musl as base
RUN yum install python3-pip -y

ADD ../baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
RUN pip3 install ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

ENV RUST_LOG=trace
RUN baml-cli --help
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Add a newline at the end of the file for better formatting.

10 changes: 10 additions & 0 deletions integ-tests/python/docker-tests/python-3_10.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG PYTHON_VERSION=3.10
FROM python:${PYTHON_VERSION} as base

RUN apt-get update

ADD ../baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
RUN pip install ./baml_py-0.53.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

ENV RUST_LOG=trace
RUN baml-cli --help
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Add a newline at the end of the file for better formatting.

22 changes: 11 additions & 11 deletions integ-tests/python/poetry.lock

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

63 changes: 63 additions & 0 deletions tools/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env /bin/bash

set -euo pipefail

show_help() {
cat <<EOF
Usage: install [dep ...]

Options:
--help Display this help message and exit.
EOF
}

_help_mode=0
_watch_mode=0
_test_mode=0

while [ $# -gt 0 ]; do
case "$1" in
--help)
_help_mode=1
shift
;;
poetry)
install_poetry=1
shift
;;
rustup)
install_rustup=1
shift
;;
--) # End of all options
shift
break
;;
*) # No more options
break
;;
esac
done

if [ "$_help_mode" -eq 1 ]; then
show_help
exit 0
fi

if [ "${install_poetry:-0}" -eq 1 ]; then
curl -sSL https://install.python-poetry.org | python3 -
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding error handling for the Poetry installation command to catch and report any issues during the installation process.

echo 'export PATH=$HOME/.local/bin:$PATH'
path_add='$HOME/.local/bin:'"${path_add:-}"
fi

if [ "${install_rustup:-0}" -eq 1 ]; then
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding error handling for the Rustup installation command to catch and report any issues during the installation process.

path_add='$HOME/.cargo/bin:'"${path_add:-}"
fi

if [ -n "${path_add:-}" ]; then
echo
echo -e "\033[36mRun the following to add the above installed deps to your PATH:\033[0m"
echo
echo "export PATH=$path_add:"'$PATH'
fi
Loading