Skip to content

🙅 Enable cross-compilation across platforms #494

🙅 Enable cross-compilation across platforms

🙅 Enable cross-compilation across platforms #494

Workflow file for this run

name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
FORCE_COLOR: 3
CIBW_BUILD_VERBOSITY: 2
CIBW_SKIP: "pp* *musllinux*"
CIBW_BUILD_FRONTEND: "build"
jobs:
style:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: 3.12
- name: Run style checks
run: pipx run pre-commit run --all-files
check_commit_message:
needs: [style]
name: Check commit message
runs-on: ubuntu-latest
outputs:
trigger: ${{ steps.check-commit-message.outputs.trigger }}
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- name: Check commit message
id: check-commit-message
run: |
set -e -x
COMMIT_MESSAGE=$(git log --no-merges -1 --oneline)
if [[ "$GITHUB_EVENT_NAME" == pull_request &&
"$COMMIT_MSG" =~ \[buildjet\] ]]; then
echo "trigger=true" >> "$GITHUB_OUTPUT"
fi
- name: Run BuildJet runners
if: steps.check-commit-message.outputs.trigger == 'true'
run: echo "Running BuildJet runners"
build_wheels:
needs: [style]
name: ${{ matrix.runs-on }}-python-${{ matrix.python-version }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.12", "3.13"]
runs-on: [ubuntu-latest, macos-13, macos-14, windows-latest]
exclude:
# https://github.com/actions/setup-python/issues/808
- python-version: "3.8"
runs-on: macos-14
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Set up Go toolchain
id: setup-go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "1.23.0"
cache: false
check-latest: true
- name: Install MinGW on Windows
if: matrix.runs-on == 'windows-latest'
run: choco install mingw
- name: Restore Hugo builder cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ./hugo_cache/
key: ${{ matrix.runs-on }}-hugo-${{ steps.setup-go.outputs.go-version }}
- name: Install Python dependencies
run: python -m pip install build virtualenv nox
- name: Build binary distribution (wheel)
run: |
python -m build --wheel . --outdir wheelhouse/
- name: Test entry points for package
run: nox -s venv
build_wheels_linux_aarch64:
needs: [check_commit_message]
name: linux-aarch64-buildjet-python-3.12
runs-on: buildjet-2vcpu-ubuntu-2204-arm
if: ${{ needs.check_commit_message.outputs.trigger == 'true' }}
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: buildjet/setup-python@v5.2.0
- uses: buildjet/setup-go@af85c03c2736c2267d5afe4d5952023a3b64bf89 # v5.0.0
with:
go-version: "1.23.0"
cache: false
check-latest: true
- name: Build binary distribution (wheel) on Linux (aarch64)
run: |
python -m pip install cibuildwheel
python -m cibuildwheel --output-dir wheelhouse
env:
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_LINUX: aarch64
CIBW_BEFORE_ALL_LINUX: |
tarball="go1.23.0.linux-arm64.tar.gz"
curl -LJO https://golang.org/dl/$tarball
mkdir $HOME/go_installed/
tar -C $HOME/go_installed/ -xzf $tarball
export PATH=$PATH:$HOME/go_installed/go/bin >> ~/.bashrc
export PATH=$PATH:$HOME/go_installed/go/bin >> ~/.bash_profile
go version
CIBW_ENVIRONMENT_LINUX: PATH=$PATH:$HOME/go_installed/go/bin
CIBW_TEST_COMMAND: |
hugo version
hugo env --logLevel debug
experimental:
needs: [style]
name: zig-${{ matrix.runs-on }}-${{ matrix.architecture }}-python-${{ matrix.python-version }}
env:
CIBW_BUILD_VERBOSITY: 2
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest]
architecture: [arm64, i686]
python-version: [3.8, 3.12, 3.13]
# Exclude i686 on Linux for all Python versions
# Test just one Python version on Windows for now
exclude:
- runs-on: ubuntu-latest
architecture: i686
- python-version: "3.8"
runs-on: windows-latest
- python-version: "3.13"
runs-on: windows-latest
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Set up Go toolchain
id: setup-go
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version: "1.23.0"
cache: false
check-latest: true
- uses: goto-bus-stop/setup-zig@7ab2955eb728f5440978d5824358023be3a2802d # v2.2.0
with:
version: 0.13.0
- name: Restore Hugo builder cache
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ./hugo_cache/
key: zig-${{ matrix.runs-on }}-${{ matrix.architecture}}-hugo-experimental-${{ steps.setup-go.outputs.go-version }}
- name: Install Python dependencies
run: python -m pip install build virtualenv nox auditwheel
- name: Build binary distribution (wheel) on Linux
if: matrix.runs-on == 'ubuntu-latest'
# Cross-compile for arm64 target via Zig toolchain
env:
GOARCH: arm64
# We are on ubuntu amd64, so set target as arm64
CC: zig cc -target aarch64-linux-gnu
CXX: zig c++ -target aarch64-linux-gnu
run: |
python -m build --wheel . --outdir wheelhouse/
# can't repair arm64 wheels on Linux x86_64 right now
# auditwheel repair --plat manylinux_2_28_aarch64 -w wheelhouse/ dist/*.whl
- name: Build binary distribution (wheel) on Windows (arm64)
if: matrix.runs-on == 'windows-latest' && matrix.architecture == 'arm64'
# We need to use cibuildwheel because it has experimental support for cross-compiling
# to arm64 and setup-python does not have arm64 support on Windows right now
uses: pypa/cibuildwheel@d4a2945fcc8d13f20a1b99d461b8e844d5fc6e23 # v2.21.1
with:
package-dir: .
output-dir: wheelhouse
# Cross-compile for arm64 target via Zig toolchain
env:
GOARCH: arm64
# We are on Windows amd64, so set target as arm64
CC: zig cc -target aarch64-windows-gnu
CXX: zig c++ -target aarch64-windows-gnu
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_WINDOWS: ARM64
CIBW_BEFORE_BUILD_WINDOWS: "pip install delvewheel"
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair -w {dest_dir} {wheel}
CIBW_TEST_SKIP: "*-win_arm64"
# Note: cibuildwheel will manage installing 32-bit Python on Windows. We
# do not need to do that manually unless we use setup-python instead.
- name: Build binary distribution (wheel) on Windows (i686)
if: matrix.runs-on == 'windows-latest' && matrix.architecture == 'i686'
uses: pypa/cibuildwheel@d4a2945fcc8d13f20a1b99d461b8e844d5fc6e23 # v2.21.1
with:
package-dir: .
output-dir: wheelhouse
# Cross-compile for i686 target via Zig toolchain
env:
GOARCH: 386
CC: zig cc -target x86-windows-gnu
CXX: zig c++ -target x86-windows-gnu
CIBW_BUILD: "cp312-*"
CIBW_ARCHS_WINDOWS: x86
CIBW_BEFORE_BUILD_WINDOWS: "pip install delvewheel"
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: delvewheel repair -w {dest_dir} {wheel}
CIBW_TEST_COMMAND: |
hugo version
hugo env --logLevel debug
- name: Upload artifacts for debugging
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: wheels_${{ matrix.runs-on }}_${{ matrix.architecture }}_py${{ matrix.python-version }}
path: ./wheelhouse/*.whl
inspect_distributions:
needs: [style]
name: inspect-sdist-wheel-contents
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938 # v4.2.0
- uses: actions/setup-python@f677139bbe7f9c59b41e40162b753c062f5d49a3 # v5.2.0
with:
python-version: 3.12
- name: Build source distribution (SDist) and binary distribution (wheel)
run: |
pipx run build --sdist --wheel . --outdir dist/
pipx run twine check dist/* --strict
- name: Build, inspect, and display contents of distributions
shell: bash
run: |
mkdir -p output/sdist
tar -xf dist/*.tar.gz -C output/sdist
echo -e '## View source distribution (SDist) contents\n' >> $GITHUB_STEP_SUMMARY
echo -e '```\n' >> $GITHUB_STEP_SUMMARY
(cd output/sdist && tree -a * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
echo -e '\n```\n' >> $GITHUB_STEP_SUMMARY
mkdir -p output/wheel
pipx run wheel unpack dist/*.whl -d output/wheel
echo -e '## View binary distribution (wheel) contents\n' >> $GITHUB_STEP_SUMMARY
echo -e '```\n' >> $GITHUB_STEP_SUMMARY
(cd output/wheel && tree -a * | sed 's/^/ /' | tee -a $GITHUB_STEP_SUMMARY)
echo -e '\n```\n' >> $GITHUB_STEP_SUMMARY