Skip to content

fix arm64

fix arm64 #45

Workflow file for this run

# 可参考如下项目的一些配置:
# https://github.com/tdewolff/minify/blob/fb9d8da7423075897c53e6a711fa7781f7146f77/.github/workflows/python.yml
# 也可github搜索Code,查找相关示例: gopy cibuildwheel language:yaml
name: Build and Publish Wheels
on:
push:
branches:
- main
- master
tags:
- 'v*'
pull_request:
jobs:
build_linux_amd64:
if: true
name: Build Linux Amd64
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Use custom setup.py
shell: bash # Use bash for consistency across platforms
run: cp python/setup_custom.py setup.py
- name: Build wheels
uses: pypa/[email protected]
env:
# CGO_ENABLED: 1
CIBW_BUILD: "cp311*_x86_64"
CIBW_ARCHS: "native"
# For Linux, install Go once per container using CIBW_BEFORE_ALL.
# This is more efficient than installing it for every Python version.
CIBW_BEFORE_ALL_LINUX: >
set -ex &&
curl -sL https://go.dev/dl/go1.23.0.linux-amd64.tar.gz | tar -C /usr/local -xzf - &&
/usr/local/go/bin/go version &&
/usr/local/go/bin/go install github.com/go-python/gopy@latest &&
/usr/local/go/bin/go install golang.org/x/tools/cmd/goimports@latest &&
ln -sf /root/go/bin/gopy /usr/local/bin/gopy &&
ln -sf /root/go/bin/goimports /usr/local/bin/goimports
# For Linux, add Go to the PATH and set CGO_LDFLAGS to help the linker find the Python library.
CIBW_ENVIRONMENT_LINUX: 'PATH=/usr/local/go/bin:/root/go/bin:$PATH'
# Before building each wheel (on all platforms), install pybindgen and other build dependencies.
CIBW_BEFORE_BUILD: "pip install pybindgen setuptools wheel"
# Skip building for Python 3.7 and older, and all PyPy versions.
CIBW_SKIP: "cp36-* cp37-* cp38-* cp39-* cp310-* cp312-* cp313-* pp* *-i686"
- name: Store wheel artifacts
uses: actions/upload-artifact@v4
with:
name: bbta-linux-amd64.whl
path: ./wheelhouse/*.whl
build_linux_arm:
if: true
name: Build Linux (aarch64)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use custom setup.py
shell: bash # Use bash for consistency across platforms
run: cp python/setup_custom.py setup.py
# QEMU is used by cibuildwheel to cross-compile wheels
# https://cibuildwheel.pypa.io/en/stable/faq/#emulation
- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Build wheels
uses: pypa/[email protected]
env:
CGO_ENABLED: 1
CIBW_BUILD: "cp311*_aarch64"
CIBW_ARCHS: "aarch64"
CIBW_BEFORE_ALL_LINUX: >
set -ex &&
curl -sL https://go.dev/dl/go1.23.0.linux-arm64.tar.gz | tar -C /usr/local -xzf - &&
/usr/local/go/bin/go version &&
/usr/local/go/bin/go install github.com/go-python/gopy@latest &&
/usr/local/go/bin/go install golang.org/x/tools/cmd/goimports@latest &&
ln -sf /root/go/bin/gopy /usr/local/bin/gopy &&
ln -sf /root/go/bin/goimports /usr/local/bin/goimports
# For Linux, add Go to the PATH and set CGO_LDFLAGS to help the linker find the Python library.
CIBW_ENVIRONMENT_LINUX: 'PATH=/usr/local/go/bin:/root/go/bin:$PATH'
CIBW_BEFORE_BUILD: "pip install pybindgen setuptools wheel"
CIBW_SKIP: "cp36-* cp37-* cp38-* cp39-* cp310-* cp313-* pp* *-musllinux*"
- name: Store wheel artifacts
uses: actions/upload-artifact@v4
with:
name: bbta-linux-arm64.whl
path: ./wheelhouse/*.whl
build_wheels_macos:
if: true
name: MacOS ${{ matrix.os_version }} 3${{ matrix.python3_version }} ${{ matrix.arch_cibw_go[0] }}
strategy:
fail-fast: false
matrix:
os_version: [ 13 ]
python3_version: [ 10]
arch_cibw_go:
- [ "x86_64", "amd64" ]
- [ "arm64", "arm64" ]
runs-on: macos-${{ matrix.os_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install Go dependencies
run: |
go install github.com/go-python/gopy@latest
go install golang.org/x/tools/cmd/goimports@latest
- name: Use custom setup.py
shell: bash # Use bash for consistency across platforms
run: cp python/setup_custom.py setup.py
- name: Build wheels
uses: pypa/[email protected]
env:
CGO_ENABLED: 1
# Build for both x86_64 and arm64 (Apple Silicon)
CIBW_ARCHS: ${{ matrix.arch_cibw_go[0] }}
CIBW_BUILD: "cp3${{ matrix.python3_version }}-*"
# This is necessary for gopy to correctly cross-compile on macOS.
CIBW_ENVIRONMENT: 'PATH=$HOME/go/bin:$PATH GOARCH=${{ matrix.arch_cibw_go[1] }}'
# Allow all CGO LDFLAGS to prevent issues with certain flags in CI.
CGO_LDFLAGS_ALLOW: '.*'
CIBW_BEFORE_BUILD: "pip install pybindgen setuptools wheel"
# Skip building for Python 3.7 and older, and all PyPy versions.
CIBW_SKIP: "cp36-* cp37-* cp38-* cp39-* pp*"
- name: Store wheel artifacts
uses: actions/upload-artifact@v4
with:
name: bbta-macos-${{ matrix.arch_cibw_go[1] }}.whl
path: ./wheelhouse/*.whl
build_wheels_windows:
if: true
name: Build wheels on Windows
runs-on: windows-2019
# strategy:
# matrix:
# include:
# - go_target: amd64
# cibw_target: AMD64
# - go_target: 386
# cibw_target: x86
# - go_target: arm64
# cibw_target: ARM64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: Install Go dependencies
run: |
go install github.com/go-python/gopy@latest
go install golang.org/x/tools/cmd/goimports@latest
- name: Use custom setup.py
shell: bash # Use bash for consistency across platforms
run: cp python/setup_custom.py setup.py
- name: Build wheels
uses: pypa/[email protected]
env:
CGO_ENABLED: 1
CIBW_BUILD: "cp311*" # build would fail on 3.13
CIBW_ARCHS: "native"
# CIBW_ARCHS: "${{ matrix.cibw_target }}"
# 下面用于设置gopy环境变量,但目前不需要设置也可编译
# python python/set_gopy_env.py && call gopy_env.bat &&
CIBW_BEFORE_BUILD: 'pip install pybindgen setuptools wheel'
# Skip building for Python 3.7 and older, and all PyPy versions.
CIBW_SKIP: "cp36-* cp37-* cp38-* cp39-* pp* *-win32"
CIBW_ENVIRONMENT: >
GOARCH=amd64
- name: Store wheel artifacts
uses: actions/upload-artifact@v4
with:
name: bbta-windows-amd64.whl
path: ./wheelhouse/*.whl
publish_wheels:
name: Publish wheels to PyPI
needs: [build_linux_amd64, build_linux_arm, build_wheels_macos, build_wheels_windows]
runs-on: ubuntu-latest
# Only run on 'v*' tags, matching the trigger.
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
environment: pypi
permissions:
id-token: write # required for trusted publishing
steps:
- name: Download all wheel artifacts
uses: actions/download-artifact@v4
with:
path: dist
pattern: bbta-*
merge-multiple: true
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# No password needed, using trusted publishing with OIDC