Skip to content

Commit ef9e8be

Browse files
authored
Build win arm64 (#1944)
<!-- ELLIPSIS_HIDDEN --> > [!IMPORTANT] > Add support for building Python wheels for Windows ARM64 in GitHub Actions workflows and update `pyproject.toml` for compatibility. > > - **Build System**: > - Add ARM64 Windows target to `build-python-release.reusable.yaml`. > - Setup build environment for ARM64 Windows, including Rust and Python 3.11, 3.12, 3.13. > - Update `pyproject.toml` to include `pyo3/generate-import-lib` feature for Windows ARM64. > - **Workflows**: > - Modify `release.yml` to expect at least 8 wheels, reflecting the new ARM64 build. > - Minor formatting changes in `release.yml`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 63d12a4. You can [customize](https://app.ellipsis.dev/BoundaryML/settings/summaries) this summary. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN -->
1 parent d2f0d5a commit ef9e8be

3 files changed

Lines changed: 85 additions & 18 deletions

File tree

.github/workflows/build-python-release.reusable.yaml

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@ name: BAML Release - Build Python
22

33
on:
44
workflow_call: {}
5+
push:
6+
branches:
7+
- baml-py-win
58

69
concurrency:
710
# suffix is important to prevent a concurrency deadlock with the calling workflow
811
group: ${{ github.workflow }}-${{ github.ref }}-build-python
912
cancel-in-progress: true
1013

14+
defaults:
15+
run:
16+
shell: bash
17+
1118
jobs:
1219
build:
1320
strategy:
@@ -49,24 +56,86 @@ jobs:
4956
- target: x86_64-pc-windows-msvc
5057
runs_on: windows-latest
5158

59+
- target: aarch64-pc-windows-msvc
60+
runs_on: windows-11-arm
61+
architecture: arm64
62+
5263
name: ${{ matrix._.target }}
5364
runs-on: ${{ matrix._.runs_on }}
65+
# See also https://github.com/mcrumiller/polars/.github/workflows/release-python.yml#L282
5466
steps:
67+
- name: Setup build environment (ARM64 Windows)
68+
if: matrix._.target == 'aarch64-pc-windows-msvc'
69+
shell:
70+
powershell
71+
# Notes
72+
# * We update `Expand-Archive` to avoid "" is not a supported archive file format when extracting
73+
# files that don't end in `.zip`
74+
run: |
75+
# rustup is not installed in aarch64
76+
if (-not (Get-Command rustup -ErrorAction SilentlyContinue)) {
77+
Invoke-WebRequest -Uri "https://static.rust-lang.org/rustup/dist/aarch64-pc-windows-msvc/rustup-init.exe" -OutFile "rustup-init.exe"
78+
.\rustup-init.exe --default-toolchain stable -y
79+
Remove-Item "rustup-init.exe"
80+
"$env:USERPROFILE/.cargo/bin" | Out-File -FilePath "$env:GITHUB_PATH" -Append
81+
}
82+
83+
- name: Check build environment (ARM64 Windows)
84+
if: matrix._.target == 'aarch64-pc-windows-msvc'
85+
run: |
86+
set -x
87+
bash --version
88+
rustup show
89+
clang -v
90+
cmake --version
91+
5592
- uses: actions/checkout@v4
56-
- uses: actions/setup-python@v5
93+
94+
# Setup Python for non-ARM64 Windows targets and other OS
95+
- name: Setup Python (default)
96+
if: matrix._.target != 'aarch64-pc-windows-msvc'
97+
uses: actions/setup-python@v5
5798
with:
5899
python-version: "3.8"
59-
architecture: ${{ matrix._.runs_on == 'windows-latest' && 'x64' || null }}
100+
architecture: ${{ matrix._.architecture }}
101+
102+
# Setup Python versions for ARM64 Windows
103+
- name: Setup Python 3.11 (ARM64 Windows)
104+
if: matrix._.target == 'aarch64-pc-windows-msvc'
105+
uses: actions/setup-python@v5
106+
id: py311
107+
with:
108+
python-version: "3.11"
109+
architecture: "arm64"
110+
allow-prereleases: true
111+
- name: Setup Python 3.12 (ARM64 Windows)
112+
if: matrix._.target == 'aarch64-pc-windows-msvc'
113+
uses: actions/setup-python@v5
114+
id: py312
115+
with:
116+
python-version: "3.12"
117+
architecture: "arm64"
118+
allow-prereleases: true
119+
- name: Setup Python 3.13 (ARM64 Windows)
120+
if: matrix._.target == 'aarch64-pc-windows-msvc'
121+
uses: actions/setup-python@v5
122+
id: py313
123+
with:
124+
python-version: "3.13"
125+
architecture: "arm64"
126+
allow-prereleases: true
60127

61128
- name: Build wheels
62129
uses: PyO3/maturin-action@v1
63-
env: ${{ matrix._.env || fromJSON('{}') }}
130+
env:
131+
# see https://github.com/PyO3/maturin/issues/2110
132+
XWIN_VERSION: "16"
64133
with:
65134
target: ${{ matrix._.target }}
66135
command: build
67136
# building in engine/ ensures that we pick up .cargo/config.toml
68137
working-directory: engine
69-
args: --release --out language_client_python/dist --manifest-path language_client_python/Cargo.toml
138+
args: --release --out language_client_python/dist --manifest-path language_client_python/Cargo.toml ${{ (matrix._.target == 'aarch64-pc-windows-msvc' && format('--interpreter {0} {1} {2}', steps.py311.outputs.python-path, steps.py312.outputs.python-path, steps.py313.outputs.python-path)) || '' }}
70139
manylinux: ${{ matrix._.manylinux }}
71140
before-script-linux: |
72141
if command -v yum &> /dev/null; then

.github/workflows/release.yml

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969

7070
build-typescript-release:
7171
uses: ./.github/workflows/build-typescript-release.reusable.yaml
72-
72+
7373
build-cli:
7474
needs: determine-version
7575
uses: ./.github/workflows/build-cli-release.reusable.yaml
@@ -79,14 +79,14 @@ jobs:
7979

8080
# This job now calls the reusable workflow which contains the matrix strategy
8181
build-vscode-reusable: # Renamed job for clarity
82-
needs: [ determine-version, build-cli ]
82+
needs: [determine-version, build-cli]
8383
uses: ./.github/workflows/build-vscode-release.reusable.yaml
8484
with:
8585
# No artifact_name needed here anymore
8686
version: ${{ needs.determine-version.outputs.version_string }}
8787
# Pass the boolean output directly
8888
is_release_build: ${{ needs.determine-version.outputs.is_release_tag == 'true' }}
89-
89+
9090
# Kick off integration tests when we build everything.
9191
# This does not yet succeed/pass consistently, or even run everything, but it's a good start.
9292
integ-tests:
@@ -105,7 +105,6 @@ jobs:
105105
- build-vscode-reusable # Depends on the job calling the reusable workflow
106106
steps:
107107
- run: echo "::do-nothing::" >/dev/null
108-
109108

110109
publish-to-pypi:
111110
environment: release
@@ -129,8 +128,8 @@ jobs:
129128
set -euo pipefail
130129
ls dist/
131130
wheel_count=$(ls dist/*.whl 2>/dev/null | wc -l)
132-
if [ "$wheel_count" -lt 7 ]; then
133-
echo "Error: Expected at least 7 wheels, but found $wheel_count"
131+
if [ "$wheel_count" -lt 8 ]; then
132+
echo "Error: Expected at least 8 wheels, but found $wheel_count"
134133
exit 1
135134
fi
136135
echo "Found $wheel_count wheels"
@@ -223,8 +222,6 @@ jobs:
223222
gem push $i
224223
done
225224
226-
227-
228225
publish-to-open-vsx:
229226
environment: release
230227
needs: [determine-version, all-builds] # Also need determine-version for the condition
@@ -308,19 +305,19 @@ jobs:
308305
uses: actions/download-artifact@v4
309306
with:
310307
# Match artifacts starting with 'baml-cli-'
311-
pattern: baml-cli-*
308+
pattern: baml-cli-*
312309
# Download into this directory
313-
path: cli-artifacts
310+
path: cli-artifacts
314311
merge-multiple: true # Merge artifacts from different OS/arch into the path
315312

316313
# Download all CFFI library artifacts produced by the build-cli job
317314
- name: Download all libbaml-cffi artifacts
318315
uses: actions/download-artifact@v4
319316
with:
320317
# Match artifacts starting with 'libbaml-cffi-'
321-
pattern: libbaml-cffi-*
318+
pattern: libbaml-cffi-*
322319
# Download into a separate directory
323-
path: cffi-artifacts
320+
path: cffi-artifacts
324321
merge-multiple: true # Merge artifacts from different OS into the path
325322

326323
- name: List downloaded CLI artifacts
@@ -369,4 +366,4 @@ jobs:
369366
# Use default GITHUB_TOKEN
370367
token: ${{ secrets.GITHUB_TOKEN }}
371368
# Do not auto-generate release notes, rely on changelog or empty body
372-
generate_release_notes: false
369+
generate_release_notes: false

engine/language_client_python/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ build-backend = "maturin"
1515
[tool.maturin]
1616
python-source = "python_src"
1717
# "extension-module" tells pyo3 we want to build an extension module (skips linking against libpython.so).
18-
features = ["pyo3/extension-module"]
18+
# The second feature is to fix windows aarch64 https://github.com/samuelcolvin/rtoml/pull/73/files
19+
features = ["pyo3/extension-module", "pyo3/generate-import-lib"]
1920

2021
[project.scripts]
2122
baml-cli = "baml_py:invoke_runtime_cli"

0 commit comments

Comments
 (0)