add special case for x86_64-unknown-linux-gnu target #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| workflow_call: | |
| inputs: | |
| docker: | |
| required: false | |
| type: string | |
| host: | |
| required: true | |
| type: string | |
| if: | |
| description: 'Whether to run this job' | |
| required: false | |
| default: true | |
| type: boolean | |
| publish: | |
| required: false | |
| type: boolean | |
| default: false | |
| setup: | |
| required: false | |
| type: string | |
| target: | |
| required: true | |
| type: string | |
| jobs: | |
| reusable-build: | |
| if: ${{ inputs.if }} | |
| name: stable - ${{ inputs.target }} - python@3.12 | |
| runs-on: ${{ inputs.host }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Cache cargo | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| .cargo-cache | |
| target/ | |
| key: ${{ inputs.target }}-cargo-${{ inputs.host }} | |
| - name: Setup toolchain | |
| run: ${{ inputs.setup }} | |
| if: ${{ inputs.setup }} | |
| shell: bash | |
| - name: Install nasm for i686-pc-windows-msvc | |
| uses: ilammy/setup-nasm@v1 | |
| if: inputs.target == 'i686-pc-windows-msvc' | |
| - name: Setup x86 Python for i686-pc-windows-msvc | |
| if: ${{ inputs.target == 'i686-pc-windows-msvc' }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| architecture: "x86" | |
| - name: Download ARM64 Python SDK | |
| if: ${{ inputs.target == 'aarch64-pc-windows-msvc' }} | |
| run: | | |
| curl -LO https://www.python.org/ftp/python/3.12.0/python-3.12.0-embed-arm64.zip | |
| mkdir python-arm64 | |
| tar -xf python-3.12.0-embed-arm64.zip -C python-arm64 | |
| - name: Set ARM64 Python environment variables | |
| if: ${{ inputs.target == 'aarch64-pc-windows-msvc' }} | |
| shell: pwsh | |
| run: | | |
| echo "PYTHONHOME=${{ github.workspace }}\python-arm64" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "PYTHONPATH=${{ github.workspace }}\python-arm64" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| echo "PATH=${{ github.workspace }}\python-arm64;${env:PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| - name: Build and (Publish) musl for ${{ inputs.target }} | |
| uses: addnab/docker-run-action@v3 | |
| if: ${{ inputs.target == 'x86_64-unknown-linux-musl' || inputs.target == 'aarch64-unknown-linux-musl' }} | |
| with: | |
| image: ${{ inputs.docker }} | |
| options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build' | |
| run: | | |
| echo "apk add:" | |
| apk upgrade | |
| apk add musl-dev gcc make cmake clang-libclang rustup python3-dev bash | |
| rustup-init -y | |
| . $HOME/.cargo/env | |
| echo "create venv:" | |
| make venv | |
| ./venv/bin/pip install patchelf | |
| make build | |
| if [ "${{ inputs.publish }}" = 'true' ]; then | |
| echo "~~~~ maturin publishing" | |
| . ./venv/bin/activate && maturin publish --no-sdist --skip-existing -u __token__ -p ${{ secrets.MATURIN_PASSWORD }} | |
| fi | |
| - name: Build and (Publish) aarch64-unknown-linux-gnu | |
| uses: addnab/docker-run-action@v3 | |
| if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }} | |
| with: | |
| image: ${{ inputs.docker }} | |
| options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build' | |
| run: | | |
| # Ensure multilib support is available | |
| sudo apt -y update | |
| sudo apt -y full-upgrade | |
| sudo apt -y install gcc-multilib | |
| # Install Rust | |
| curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| # ring 0.17 assembly build needs __ARM_ARCH set | |
| export CFLAGS_aarch64_unknown_linux_gnu="-D__ARM_ARCH=8" | |
| rustup component add llvm-tools-preview || true | |
| rustup target add aarch64-unknown-linux-gnu | |
| python3 -m venv .env | |
| . .env/bin/activate && pip install -r requirements.txt | |
| . .env/bin/activate && pip install patchelf | |
| if [ "${{ inputs.publish }}" = 'true' ]; then | |
| echo "~~~~ maturin publishing" | |
| # pass '--debug' to avoid optimization, which breaks tls signature validation on this platform | |
| . .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }} | |
| else | |
| echo "~~~~ maturin building" | |
| . .env/bin/activate && maturin build --target ${{ inputs.target }} | |
| fi | |
| - name: Build and (Publish) armv7-unknown-linux-gnueabihf | |
| uses: addnab/docker-run-action@v3 | |
| if: ${{ inputs.target == 'armv7-unknown-linux-gnueabihf' }} | |
| with: | |
| image: ${{ inputs.docker }} | |
| options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build' | |
| run: | | |
| # Ensure multilib support is available | |
| sudo apt -y update | |
| sudo apt -y full-upgrade | |
| sudo apt -y install gcc-multilib | |
| # Set up bindgen environment | |
| export BINDGEN_EXTRA_CLANG_ARGS="--target=armv7-unknown-linux-gnueabihf" | |
| export BINDGEN_SYSROOT="/usr/arm-linux-gnueabihf" | |
| export RUST_BACKTRACE=1 | |
| # Install Rust and configure ARM target | |
| curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| rustup target add armv7-unknown-linux-gnueabihf | |
| cargo install --force --locked bindgen-cli | |
| python3 -m venv .env | |
| . .env/bin/activate && pip install -r requirements.txt | |
| . .env/bin/activate && pip install patchelf | |
| if [ "${{ inputs.publish }}" = 'true' ]; then | |
| echo "~~~~ maturin publishing" | |
| # pass '--debug' to avoid optimization, which breaks tls signature validation on this platform | |
| . .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }} | |
| else | |
| echo "~~~~ maturin building" | |
| RUST_BACKTRACE=1 . .env/bin/activate && maturin build --target ${{ inputs.target }} --verbose | |
| fi | |
| - name: Build and (Publish) x86_64-unknown-linux-gnu | |
| uses: addnab/docker-run-action@v3 | |
| if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }} | |
| with: | |
| image: ${{ inputs.docker }} | |
| options: '--user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build' | |
| run: | | |
| # Update and install required packages | |
| sudo apt-get update | |
| sudo apt-get install -y llvm-dev clang libclang-dev gcc-multilib | |
| # Install Rust minimal toolchain | |
| curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal | |
| export PATH="$HOME/.cargo/bin:$PATH" | |
| # Add necessary Rust targets and components | |
| rustup component add llvm-tools-preview || true | |
| rustup target add x86_64-unknown-linux-gnu | |
| # Create and activate Python virtual environment | |
| python3 -m venv .env | |
| . .env/bin/activate && pip install -r requirements.txt | |
| . .env/bin/activate && pip install patchelf | |
| if [ "${{ inputs.publish }}" = 'true' ]; then | |
| echo "~~~~ maturin publishing" | |
| . .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing -i python3.12 -u __token__ -p ${{ secrets.MATURIN_PASSWORD }} | |
| else | |
| echo "~~~~ maturin building" | |
| . .env/bin/activate && maturin build --target ${{ inputs.target }} | |
| fi | |
| - name: Build Python Extension Module (non-docker) | |
| if: ${{ inputs.publish != true && !inputs.docker && !contains(inputs.target,'android') }} | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| maturin-version: v1.9.1 | |
| target: ${{ inputs.target }} | |
| # builds in release mode with the specified python version as the interpreter and the Cargo.toml file as the manifest | |
| args: --release -i python3.12 --target ${{ inputs.target }} -m Cargo.toml | |
| env: | |
| # see https://github.com/PyO3/maturin/issues/2110 | |
| XWIN_VERSION: '16' | |
| - name: Publish to PyPI (non-docker) | |
| if: ${{ inputs.publish == true && !inputs.docker && !contains(inputs.target,'android') }} | |
| uses: PyO3/maturin-action@v1 | |
| with: | |
| command: publish | |
| maturin-version: v1.9.1 | |
| target: ${{ inputs.target }} | |
| args: --no-sdist --skip-existing -i python3.12 -m Cargo.toml -u __token__ -p ${{ secrets.MATURIN_PASSWORD }} | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bindings-${{ inputs.target }} | |
| path: target/wheels/*.whl # path to the python wheel package | |
| if-no-files-found: error |