Skip to content

Test and Build

Test and Build #80

Workflow file for this run

on: [push, pull_request]
defaults:
run:
shell: bash
env:
cratename: ckmeans
rustflags: -C rpath
CARGO_TERM_COLOR: always
name: Test and Build
jobs:
test:
if: github.event_name == 'push' && !contains(github.ref, 'refs/tags/')
name: Test on ${{ matrix.os }} (${{ matrix.target }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
use-cross: false
- build: macos
os: macos-13
rust: stable
target: x86_64-apple-darwin
use-cross: false
deptarget: 10.9
- build: windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
use-cross: false
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Run tests
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deptarget }}
run: cargo test --target=${{ matrix.target }}
build:
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
name: Build and release on ${{ matrix.os }} (${{ matrix.target }})
runs-on: ${{ matrix.os }}
container: ${{ matrix.container || '' }}
strategy:
fail-fast: false
matrix:
include:
- build: linux
os: ubuntu-latest
rust: stable
target: x86_64-unknown-linux-gnu
container: quay.io/pypa/manylinux_2_28_x86_64
- build: linux-arm64
os: ubuntu-24.04-arm
rust: stable
target: aarch64-unknown-linux-gnu
container: quay.io/pypa/manylinux_2_28_aarch64
- build: macos
os: macos-13
rust: stable
target: x86_64-apple-darwin
deptarget: 10.9
- build: macos
os: macos-13
rust: stable
target: aarch64-apple-darwin
deptarget: 11.0
- build: windows
os: windows-latest
rust: stable
target: x86_64-pc-windows-msvc
steps:
- name: Switch to macOS 13.x SDK
if: matrix.target == 'aarch64-apple-darwin'
run: |
xcodebuild -showsdks
SDKROOT=$(xcrun -sdk macosx14.2 --show-sdk-path)
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
- name: Install Rust llvm-tools (Linux)
if: matrix.build == 'linux' || matrix.build == 'linux-arm64'
run: rustup component add llvm-tools-preview
- name: Build with PGO (Linux)
if: matrix.build == 'linux' || matrix.build == 'linux-arm64'
run: |
# PGO Build Process
mkdir -p target/pgo-profiles
# Find Rust's llvm-profdata
RUSTUP_HOME="${RUSTUP_HOME:-$HOME/.rustup}"
RUST_LLVM_PROFDATA=$(find "$RUSTUP_HOME" -name "llvm-profdata" -type f 2>/dev/null | head -n1)
if [ -z "$RUST_LLVM_PROFDATA" ]; then
echo "Error: llvm-profdata not found"
exit 1
fi
echo "Using llvm-profdata: $RUST_LLVM_PROFDATA"
# Build with instrumentation in tools directory
cd tools
RUSTFLAGS="-Cprofile-generate=$PWD/../target/pgo-profiles" \
cargo build --bin pgo_training --profile pgo-generate
cd ..
# Run training
./tools/target/pgo-generate/pgo_training
# Merge profiles
"$RUST_LLVM_PROFDATA" merge -o target/pgo-profiles/merged.profdata target/pgo-profiles/*.profraw
# Build with PGO
RUSTFLAGS="-Cprofile-use=$PWD/target/pgo-profiles/merged.profdata" \
cargo build --profile pgo-use --target=${{ matrix.target }} --features headers
- name: Build with cargo (non-Linux)
if: matrix.build != 'linux' && matrix.build != 'linux-arm64'
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.deptarget }}
run: cargo build --release --target=${{ matrix.target }} --features headers
- name: Gather Assets
run: |
src=$(pwd)
stage=
case $RUNNER_OS in
Linux)
stage=$(mktemp -d)
;;
macOS)
stage=$(mktemp -d -t tmp)
;;
Windows)
stage=$(mktemp -d)
;;
esac
mkdir zipped
cp include/header.h $stage
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
ASSET_NAME="${{ env.cratename }}-$RELEASE_VERSION-${{ matrix.target }}"
echo "Release name is $ASSET_NAME"
echo "STAGE=$stage" >> $GITHUB_ENV
echo "ASSET_NAME=$ASSET_NAME" >> $GITHUB_ENV
if [ "$RUNNER_OS" == "Linux" ]; then
echo "TYPE=tar" >> $GITHUB_ENV
echo "EXTENSION=tar.gz" >> $GITHUB_ENV
# Use PGO-optimized build for Linux
cp target/pgo-use/*.so $stage/
fi
if [ "$RUNNER_OS" == "macOS" ]; then
echo "TYPE=tar" >> $GITHUB_ENV
echo "EXTENSION=tar.gz" >> $GITHUB_ENV
for lib in target/${{ matrix.target }}/release/*.dylib; do
install_name_tool -id "@rpath/lib${{ env.cratename }}.dylib" $lib
otool -L $lib
done
cp target/${{ matrix.target }}/release/*.dylib $stage/
fi
if [ "$RUNNER_OS" == "Windows" ]; then
echo "TYPE=tar" >> $GITHUB_ENV
echo "EXTENSION=tar.gz" >> $GITHUB_ENV
cp target/${{ matrix.target }}/release/deps/${{ env.cratename }}.dll.lib target/${{ matrix.target }}/release/deps/${{ env.cratename }}.lib
cp target/${{ matrix.target }}/release/${{ env.cratename }}* $stage/
cp target/${{ matrix.target }}/release/deps/${{ env.cratename }}* $stage/
fi
ls $stage
cd $src
- name: Create archive
run: |
pushd ${{ env.STAGE }}
tar -czf "${{ env.ASSET_NAME }}.${{ env.EXTENSION }}" *
popd
cp "${{ env.STAGE }}/${{ env.ASSET_NAME }}.${{ env.EXTENSION }}" zipped/
- name: Release
uses: softprops/action-gh-release@v2.2.1
with:
files: |
zipped/${{ env.ASSET_NAME }}.${{ env.EXTENSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}