Skip to content

Get aarch64 build to run in the before-script-linux step of the matur… #132

Get aarch64 build to run in the before-script-linux step of the matur…

Get aarch64 build to run in the before-script-linux step of the matur… #132

Workflow file for this run

#
# This action will:
# Build python wheels
# Build libraries
# Publish a release in GitHub
# Publish to pypi
# Publish to crates.io
#
# This file contains parts autogenerated by maturin v1.7.2
#
# maturin generate-ci github --platform manylinux macos
#
name: Releasev2
on:
push:
tags:
- "*"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: 0
jobs:
# build_source_distribution:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
# - name: Build source distribution wheel
# uses: PyO3/maturin-action@v1
# with:
# target: x86_64
# args: --release --all-features --out dist --sdist
# manylinux: auto
# - name: Upload souce disttribution wheel
# uses: actions/upload-artifact@v4
# with:
# name: wheels-sdist
# path: dist
build_linux_wheels:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: aarch64
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build linux wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --all-features --out dist -i 3.9 3.10 3.11 3.12 3.13
manylinux: auto
before-script-linux: |
export TAG="$(git describe --tags)"
echo "TAG=$TAG"
export PLATFORM_TARGET="${{ matrix.platform.target }}"
echo "PLATFORM_TARGET=$PLATFORM_TARGET"
# determine which target cpus for rustc to build for from machine type
case $PLATFORM_TARGET in
x86_64)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
export TARGETS="x86-64 x86-64-v2 x86-64-v3"
else
export TARGETS="x86-64"
fi
;;
aarch64)
export TARGETS="aarch64"
;;
*) echo "unknown platform target $PLATFORM_TARGET"; exit 1 ;;
esac
echo "Rust TARGETS=$TARGETS"
export LIB_GLOB="{a,so}"
for TARGET in $TARGETS; do
echo "building kernel-target linux-$TARGET"
export RUSTFLAGS="-C target-cpu=$TARGET"
# Build C objects
cargo build --release --features cfitsio-static,examples
# Create new release asset tarballs
# Get some debug
ls -la target/release
ls -la include
ls -la .
eval mv target/release/libmwalib.${LIB_GLOB} include/mwalib.h .
eval tar -acvf mwalib-${TAG}-linux-${TARGET}.tar.gz \
LICENSE LICENSE-cfitsio README.md CHANGELOG.md \
libmwalib.${LIB_GLOB} mwalib.h
eval tar -acvf mwalib-${TAG}-linux-${TARGET}-python.tar.gz \
LICENSE LICENSE-cfitsio README.md CHANGELOG.md \
./dist/*.whl
done
- name: Upload linux wheels (only used by pypi publish step)
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist
- name: Build linux C and Rust libraries
run: |
# Fix permissions- output files from maturn-action end up owned by root
# so lets change them back to root:root
sudo chown -R runner:docker .
echo "TAG=$TAG"
echo "PLATFORM_TARGET=$PLATFORM_TARGET"
echo "Rust TARGETS=$TARGETS"
echo "lib glob=$LIB_GLOB"
for TARGET in $TARGETS; do
eval tar -acvf mwalib-${TAG}-linux-${TARGET}-python.tar.gz \
LICENSE LICENSE-cfitsio README.md CHANGELOG.md \
./dist/*.whl
done
- name: Upload linux tarballs
uses: actions/upload-artifact@v4
with:
name: linux-${{ matrix.platform.target }}.tar.gz
path: "*.tar.gz"
if-no-files-found: error
build_macos_wheels:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform: # see https://github.com/actions/runner-images?tab=readme-ov-file#available-images for runner types
- runner: macos-13
target: x86_64
- runner: macos-14
target: aarch64
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install automake and autoconf
run: |
brew install automake autoconf
- name: Build macos wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --all-features --out dist -i 3.9 3.10 3.11 3.12 3.13
- name: Upload macos wheels
uses: actions/upload-artifact@v4
with:
name: wheels-${{ matrix.platform.runner }}-${{ matrix.platform.target }}
path: dist
- name: Build C and Rust libraries
run: |
export TAG="$(git describe --tags)"
echo "TAG=$TAG"
# determine which target cpus for rustc to build for from machine type
export ARCH="$(uname -m)"
case $ARCH in
x86_64)
export TARGET="x86-64";;
arm64) export TARGET="arm64";;
*) echo "unknown arch (uname -m) $ARCH"; exit 1 ;;
esac
echo "ARCH=$ARCH"
# determine which library file extensions to include in archive from kernel
export LIB_GLOB="{a,dylib}"
echo "Rust TARGETS=$TARGETS"
echo "building kernel-target darwin-$TARGET"
export RUSTFLAGS="-C target-cpu=$TARGET"
# Build C objects
cargo build --release --features examples,cfitsio-static
# Get some debug
ls -la target/release
ls -la include
ls -la .
# Create new release asset tarballs
eval mv target/release/libmwalib.${LIB_GLOB} include/mwalib.h .
eval tar -acvf mwalib-${TAG}-darwin-${TARGET}.tar.gz \
LICENSE LICENSE-cfitsio README.md CHANGELOG.md \
libmwalib.${LIB_GLOB} mwalib.h
eval tar -acvf mwalib-${TAG}-darwin-${TARGET}-python.tar.gz \
LICENSE LICENSE-cfitsio README.md CHANGELOG.md \
./dist/*.whl
- name: Upload macos tarball
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.platform.runner }}-${{ matrix.platform.target }}.tar.gz
path: "*.tar.gz"
if-no-files-found: error
create-github-release:
name: Create a new github release
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/') }}
needs: [build_linux_wheels, build_macos_wheels]
environment: CI
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
merge-multiple: true
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
shell: bash
run: |
gh release create "$tag" \
--repo="$GITHUB_REPOSITORY" \
--title="${GITHUB_REPOSITORY#*/} ${tag#v}" \
--generate-notes *.tar.gz
pypi_release:
name: Publish to pypi
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
environment: CI
needs: [create-github-release]
permissions:
# Use to sign the release artifacts
id-token: write
# Used to upload release artifacts
contents: write
# Used to generate artifact attestation
attestations: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: wheels-*
- name: Generate artifact attestation
uses: actions/attest-build-provenance@v1
with:
subject-path: 'wheels-*/*'
- name: Publish to PyPI
if: startsWith(github.ref, 'refs/tags/')
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
rust_release:
name: Publish to crates.io
runs-on: ubuntu-latest
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
needs: [create-github-release]
environment: CI
steps:
- name: Checkout sources
uses: actions/checkout@v4
- name: Install stable, minimal toolchain
uses: dtolnay/rust-toolchain@v1
with:
toolchain: stable
# We install cfitsio because when releasing to crates.io, it runs
# the rust docs generation which fails if our code does any
# writing. With feature cfitsio-static, it has to build cfitsio which
# involves writing so have to build without that feature when pushing
# to crates.io
- name: Install cfitsio 3.49
run: |
curl "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-3.49.tar.gz" -o cfitsio.tar.gz
tar -xf cfitsio.tar.gz
rm cfitsio.tar.gz
cd cfitsio-3.49
# Enabling SSE2/SSSE3 could cause portability problems, but it's unlikely that anyone
# is using such a CPU...
# https://stackoverflow.com/questions/52858556/most-recent-processor-without-support-of-ssse3-instructions
# Disabling curl just means you cannot fits_open() using a URL.
CFLAGS="-O3" ./configure --prefix=/usr/local --enable-reentrant --enable-sse2 --enable-ssse3 --disable-curl
make -j
sudo make install
sudo ldconfig
cd ..
rm -rf cfitsio-3.49
- name: Build on latest stable rust
run: cargo build --release --features examples
- uses: katyo/publish-crates@v2
with:
registry-token: ${{ secrets.CARGO_REGISTRY_TOKEN }}
args: --no-verify