Skip to content

Commit

Permalink
Use maturin as build-backend and update Release PyPi GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
yvan-sraka committed Feb 4, 2025
1 parent b3ff7b7 commit 32877df
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 94 deletions.
83 changes: 14 additions & 69 deletions .github/workflows/release_pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,25 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, macos-14, macos-15, windows-latest]
os: [ubuntu-latest, macos-14, macos-15, windows-latest]

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
image: tonistiigi/binfmt:qemu-v8.1.5

- name: Install cibuildwheel
run: python -m pip install cibuildwheel==2.21.3

- name: Set up Rust
uses: actions-rs/toolchain@v1
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build wheels with Maturin
uses: PyO3/maturin-action@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Build wheels
run: python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: cp39-* cp310-* cp311-* cp312-*
CIBW_SKIP: "*musllinux*"
CIBW_ARCHS_LINUX: x86_64 aarch64
CIBW_ARCHS_WINDOWS: AMD64 x86
CIBW_ARCHS_MACOS: x86_64 arm64
CIBW_BEFORE_ALL_LINUX: |
curl -sSf https://sh.rustup.rs | sh -s -- -y
# From https://github.com/Intreecom/scyllapy/blob/05fdab32dd7468c26533de5fdfe9627fa3e38445/.github/workflows/release.yaml#L38
if command -v yum &> /dev/null; then
yum update -y && yum install -y perl-core openssl openssl-devel pkgconfig libatomic
# If we're running on i686 we need to symlink libatomic
# in order to build openssl with -latomic flag.
if [[ ! -d "/usr/lib64" ]]; then
ln -s /usr/lib/libatomic.so.1 /usr/lib/libatomic.so
fi
elif command -v apt &> /dev/null; then
apt update -y && apt-get install -y libssl-dev openssl pkg-config
fi
CIBW_BEFORE_ALL_MACOS: |
curl -sSf https://sh.rustup.rs | sh -s -- -y
rustup target add aarch64-apple-darwin x86_64-apple-darwin
CIBW_BEFORE_ALL_WINDOWS: rustup target add i686-pc-windows-msvc
CIBW_BEFORE_BUILD: pip install setuptools-rust
CIBW_ENVIRONMENT: PATH="$HOME/.cargo/bin:$PATH"
CIBW_ENVIRONMENT_MACOS: MACOSX_DEPLOYMENT_TARGET=10.12
CIBW_TEST_COMMAND: python -c "import outlines_core; print(outlines_core.__version__)"
CMAKE_PREFIX_PATH: ./dist

command: build
args: --release --out dist --features python-bindings
- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/*.whl
path: dist/*.whl
name: wheels

build_sdist:
Expand All @@ -84,13 +41,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build setuptools-rust
- name: Build sdist
run: python -m build --sdist
python-version: '3.10'
- name: Build sdist with Maturin
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- uses: actions/upload-artifact@v4
with:
path: dist/*.tar.gz
Expand All @@ -101,17 +57,6 @@ jobs:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools setuptools-rust
- name: Generate egg-info
run: python setup.py egg_info
- uses: actions/download-artifact@v4
with:
name: wheels
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ __pycache__
benchmarks/results
build
Cargo.lock
dist
docs/build
logs
rust-coverage
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2", "setuptools-rust"]
build-backend = "setuptools.build_meta"
requires = ["maturin>=1.0,<2.0"]
build-backend = "maturin"

[project]
name = "outlines_core"
Expand Down Expand Up @@ -42,7 +42,7 @@ test = [
"scipy",
"asv",
"psutil",
"setuptools-rust",
"maturin",
]

[project.urls]
Expand Down Expand Up @@ -115,3 +115,6 @@ show_missing = true
[tool.diff_cover]
compare_branch = "origin/main"
diff_range_notation = ".."

[tool.maturin]
features = ["python-bindings"]
21 changes: 0 additions & 21 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/python_bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ pub fn build_regex_from_schema_py(
}

#[pymodule]
fn outlines_core_rs(m: &Bound<'_, PyModule>) -> PyResult<()> {
fn outlines_core(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add("BOOLEAN", json_schema::BOOLEAN)?;
m.add("DATE", json_schema::DATE)?;
m.add("DATE_TIME", json_schema::DATE_TIME)?;
Expand Down

0 comments on commit 32877df

Please sign in to comment.