Skip to content

Commit 30a6fca

Browse files
committed
chore(build): build wheels for multiple platforms
Replace the single-platform hatch build with a GitHub Actions matrix that builds native wheels for linux (x86_64, aarch64), macOS (x86_64, arm64), and Windows (x86_64, arm64) using maturin-action. Add --version-only flag to scripts/maturin_build.py so CI can inject the VCS version into pyproject.toml before maturin-action runs. Signed-off-by: Jericho Tolentino <68654047+jericht@users.noreply.github.com>
1 parent 72db090 commit 30a6fca

3 files changed

Lines changed: 35 additions & 38 deletions

File tree

‎.github/workflows/release_publish.yml‎

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,57 +35,36 @@ jobs:
3535
tag: ${{ needs.TagRelease.outputs.tag }}
3636

3737
PreRelease:
38-
needs: [TagRelease, UnitTests]
39-
uses: OpenJobDescription/.github/.github/workflows/reusable_prerelease.yml@mainline
40-
permissions:
41-
id-token: write
42-
contents: write
43-
secrets: inherit
44-
with:
45-
tag: ${{ needs.TagRelease.outputs.tag }}
38+
needs: [TagRelease, UnitTests]
39+
uses: OpenJobDescription/.github/.github/workflows/reusable_maturin_prerelease.yml@mainline
40+
secrets: inherit
41+
with:
42+
tag: ${{ needs.TagRelease.outputs.tag }}
4643

4744
Release:
48-
needs: [TagRelease, PreRelease]
49-
uses: OpenJobDescription/.github/.github/workflows/reusable_release.yml@mainline
50-
secrets: inherit
51-
permissions:
52-
id-token: write
53-
contents: write
54-
with:
55-
tag: ${{ needs.TagRelease.outputs.tag }}
56-
57-
Publish:
58-
needs: [TagRelease, Release]
59-
uses: OpenJobDescription/.github/.github/workflows/reusable_publish_python.yml@mainline
45+
needs: [TagRelease, PreRelease]
46+
uses: OpenJobDescription/.github/.github/workflows/reusable_release.yml@mainline
47+
secrets: inherit
6048
permissions:
6149
id-token: write
62-
secrets: inherit
50+
contents: write
6351
with:
64-
tag: ${{ needs.TagRelease.outputs.tag }}
52+
tag: ${{ needs.TagRelease.outputs.tag }}
6553

6654
# PyPI does not support reusable workflows yet
67-
# # See https://github.com/pypi/warehouse/issues/11096
55+
# See https://github.com/pypi/warehouse/issues/11096
6856
PublishToPyPI:
69-
needs: [TagRelease, Publish]
57+
needs: [TagRelease, Release, PreRelease]
7058
runs-on: ubuntu-latest
7159
environment: release
7260
permissions:
7361
id-token: write
7462
steps:
75-
- name: Checkout
76-
uses: actions/checkout@v6
63+
- uses: actions/download-artifact@v4
7764
with:
78-
ref: ${{ needs.TagRelease.outputs.tag }}
79-
fetch-depth: 0
80-
- name: Set up Python
81-
uses: actions/setup-python@v6
82-
with:
83-
python-version: '3.9'
84-
- name: Install dependencies
85-
run: |
86-
pip install --upgrade hatch "virtualenv<21"
87-
- name: Build
88-
run: hatch -v build
89-
# # See https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-pypi
65+
name: build-artifact
66+
path: dist
9067
- name: Publish to PyPI
9168
uses: pypa/gh-action-pypi-publish@release/v1
69+
with:
70+
packages-dir: dist

‎_build_backend.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,17 @@
3232
from __future__ import annotations
3333

3434
import contextlib
35+
import os
3536
import shutil
3637
import sys
3738
from pathlib import Path
3839

40+
# Windows MSVC linker fails with LNK1104 when paths exceed MAX_PATH (260 chars).
41+
# Building from an extracted sdist produces deeply nested target directories.
42+
# Redirect Cargo's output to a short path to avoid this.
43+
if sys.platform == "win32" and "CARGO_TARGET_DIR" not in os.environ:
44+
os.environ["CARGO_TARGET_DIR"] = "C:\\cargo-target"
45+
3946
import maturin
4047

4148
REPO_ROOT = Path(__file__).resolve().parent

‎scripts/maturin_build.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ def main(argv: list[str]) -> int:
6767
)
6868
shutil.move(str(PYPROJECT_BAK), str(PYPROJECT))
6969

70+
# --version-only: inject the VCS version into pyproject.toml and
71+
# _version.py without running maturin. Used in CI when maturin-action
72+
# handles the actual build but needs the version patched beforehand.
73+
if "--version-only" in argv:
74+
version = compute_version()
75+
write_version_file(version)
76+
print(f"Wrote src/openjd/model/_version.py (version {version})")
77+
_patch_pyproject(version)
78+
print(f"Patched pyproject.toml: project.version = {version!r}")
79+
return 0
80+
7081
maturin_args = argv or ["develop"]
7182

7283
version = compute_version()

0 commit comments

Comments
 (0)