Skip to content

Fix CI

Fix CI #15

name: "Build binaries"
on:
workflow_call:
inputs:
plan: # https://opensource.axo.dev/cargo-dist/book/ci/customizing.html
required: true
type: string
pull_request:
paths:
- .github/workflows/build-binaries.yml
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
APP_NAME: tee-rs
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTFLAGS: "-D warnings -W unreachable-pub"
RUSTUP_MAX_RETRIES: 10
FETCH_DEPTH: 0 # pull in the tags for the version string
MACOSX_DEPLOYMENT_TARGET: 13.0
defaults:
run:
shell: bash -eux -o pipefail {0}
jobs:
dist:
strategy:
matrix:
include:
- os: windows-latest
target: x86_64-pc-windows-msvc
- os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
# https://blog.rust-lang.org/2022/08/01/Increasing-glibc-kernel-requirements.html
glib_version: 2.17
- os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
glib_version: 2.17
- os: ubuntu-20.04
target: x86_64-unknown-linux-musl
- os: ubuntu-20.04
target: aarch64-unknown-linux-musl
- os: macos-13
target: x86_64-apple-darwin
- os: macos-13
target: aarch64-apple-darwin
name: dist (${{ matrix.target }})
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Prepare for common
run: |
CARGO_HOME="${{ runner.temp }}/.cargo"
echo CARGO_HOME="${CARGO_HOME}" >> "$GITHUB_ENV"
echo "${CARGO_HOME}/bin" >> "$GITHUB_PATH"
- name: Prepare for Linux
if: ${{ contains(matrix.target, 'linux') }}
run: |
XDG_BIN_HOME="${{ runner.temp }}/.local/bin"
{
echo XDG_CONFIG_HOME="${{ runner.temp }}/.config"
echo XDG_CACHE_HOME="${{ runner.temp }}/.cache"
echo XDG_DATA_HOME="${{ runner.temp }}/.local/share"
echo XDG_BIN_HOME="${XDG_BIN_HOME}"
echo PYTHONUSERBASE="${{ runner.temp }}/.local"
} >> "$GITHUB_ENV"
{
echo "${XDG_BIN_HOME}"
} >> "$GITHUB_PATH"
- name: Prepare for MacOS
if: ${{ contains(matrix.target, 'darwin') }}
run: |
PYTHONUSERBASE="${{ runner.temp }}/.local"
echo PYTHONUSERBASE="$PYTHONUSERBASE/.local" >> "$GITHUB_ENV"
echo "$PYTHONUSERBASE/.local/bin" >> "$GITHUB_PATH"
- name: Prepare for Windows
if: ${{ contains(matrix.target, 'windows') }}
run: |
export PYTHONUSERBASE="${{ runner.temp }}/.local"
echo PYTHONUSERBASE="$PYTHONUSERBASE" >> "$GITHUB_ENV"
# Get 'Scripts' path
py_content=$(
cat <<'__PY_CONTENT_EOF__'
import site
from pathlib import Path
user_site_pkgs_path = Path(site.getusersitepackages())
print(user_site_pkgs_path.parent / "Scripts")
__PY_CONTENT_EOF__
)
py_scripts_path=$(python -c "$py_content")
if [[ -z "$py_scripts_path" ]]; then
echo "Failed to get 'Scripts' path" >&2
exit 1
fi
echo "$py_scripts_path" >> "$GITHUB_PATH"
# - name: Install Rust
# run: |
# curl --proto '=https' --tlsv1.2 --retry 10 --retry-connrefused -fsSL "https://sh.rustup.rs" \
# | sh -s -- --profile minimal --default-toolchain none -y
# echo "${CARGO_HOME:-$HOME/.cargo}/bin" >> $GITHUB_PATH
- name: Update pip
run: python -m pip install --user -U pip
- name: Install cargo-zigbuild (and ziglang)
run: python -m pip install --user cargo-zigbuild
- name: Install Rust toolchain
run: |
rustup update --no-self-update stable
rustup target add ${{ matrix.target }}
rustup component add rust-src
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
- name: Dist
run: |
target="${{ matrix.target }}"
if [[ -n "${{ matrix.glib_version }}" ]]; then
target="${target}.${{ matrix.glib_version }}"
fi
cargo zigbuild --target="${target}" --release
- name: Archive binary for Unix-like systems
if: ${{ !contains(matrix.target, 'windows-msvc') }}
run: |
ARCHIVE_NAME="${{ env.APP_NAME }}-${{ matrix.target }}"
ARCHIVE_FILE="$ARCHIVE_NAME.tar.gz"
mkdir -p "$ARCHIVE_NAME"
cp "target/${{ matrix.target }}/release/${{ env.APP_NAME }}" "$ARCHIVE_NAME/${{ env.APP_NAME }}"
tar czvf "$ARCHIVE_FILE" "$ARCHIVE_NAME"
shasum -a 256 "$ARCHIVE_FILE" > "$ARCHIVE_FILE.sha256"
- name: Archive binary for Windows
if: ${{ contains(matrix.target, 'windows-msvc') }}
run: |
ARCHIVE_NAME="${{ env.APP_NAME }}-${{ matrix.target }}"
ARCHIVE_FILE="$ARCHIVE_NAME.zip"
7z a "$ARCHIVE_FILE" ./target/${{ matrix.target }}/release/${{ env.APP_NAME }}.exe
sha256sum $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: artifacts-${{ matrix.target }}
retention-days: 1
path: |
*.tar.gz
*.zip
*.sha256