Native Library Builder #86
This file contains 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
name: Native Library Builder | |
on: | |
workflow_dispatch: | |
release: | |
types: [published] | |
permissions: | |
contents: write | |
actions: write | |
jobs: | |
build_native: | |
name: Cross build with Scala Native | |
permissions: write-all | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- os: ubuntu-latest | |
arch: x64 | |
name: linux | |
# TODO This works, but binary signing and notarization is required | |
- os: macos-latest | |
arch: arm64 | |
name: mac | |
# TODO It seems arm64 is not available yet (2024-11) | |
- os: ubuntu-latest | |
arch: arm64 | |
name: linux | |
# TODO Need some tweaks to run sbt on Windows | |
# - os: windows-latest | |
# arch: x64 | |
# name: windows | |
runs-on: ${{ matrix.os }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
repository: wvlet/wvlet | |
- uses: actions/checkout@v4 | |
with: | |
path: local | |
- name: Local Patches for Library -x | |
run: | | |
cp local/_patches/WvcMain.scala wvc/src/main/scala/wvlet/lang/native/WvcMain.scala | |
cp local/_patches/WvcLib.scala wvc/src/main/scala/wvlet/lang/native/WvcLib.scala | |
cp local/_patches/Makefile wvc-lib/Makefile | |
cp local/_patches/build.sbt build.sbt | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '23' | |
cache: sbt | |
- name: Set SCALA_VERSION env | |
run: | | |
SCALA_VERSION=$(cat SCALA_VERSION) | |
echo SCALA_VERSION: $SCALA_VERSION | |
echo "SCALA_VERSION=$SCALA_VERSION" >> $GITHUB_ENV | |
- name: Build native libraries for ${{ matrix.name }}-${{ matrix.arch }} | |
if: ${{ !(matrix.name == 'linux' && matrix.arch == 'arm64') }} | |
run: | | |
./sbt 'wvcLib/nativeLink' | |
./sbt 'wvcLibStatic/nativeLink' | |
FILEPATH=$(find . -name 'libwvlet.*') | |
echo "Found $FILEPATH" | |
mkdir -p out | |
cp $FILEPATH ./out/ | |
cd ./out && for f in *.*; do mv -- "$f" "${{ matrix.name }}-${{ matrix.arch }}_$f"; done | |
ls -alFh | |
- name: Docker Setup QEMU | |
if: ${{ matrix.name == 'linux' && matrix.arch == 'arm64' }} | |
uses: docker/setup-qemu-action@v2 | |
with: | |
platforms: arm64 | |
- name: Re-Build native libraries in ARM64-emulated environment | |
if: ${{ matrix.name == 'linux' && matrix.arch == 'arm64' }} | |
run: | | |
docker run --rm -v $(pwd):/${{ github.workspace }} -w ${{ github.workspace }} --platform linux/${{ matrix.arch }} arm64v8/ubuntu:oracular /bin/bash -c " | |
apt-get update && apt-get install ca-certificates apt-transport-https curl gnupg build-essential -yqq && | |
echo 'deb https://repo.scala-sbt.org/scalasbt/debian all main' | tee /etc/apt/sources.list.d/sbt.list && | |
echo 'deb https://repo.scala-sbt.org/scalasbt/debian /' | tee /etc/apt/sources.list.d/sbt_old.list && | |
curl -sL 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823' | gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --import && | |
chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpg && | |
apt-get update && | |
apt-get install -y openjdk-23-jdk-headless sbt clang libstdc++-12-dev libgc-dev zlib1g-dev libssl-dev && | |
./sbt 'wvcLib/nativeLink' && | |
./sbt 'wvcLibStatic/nativeLink' && | |
mkdir -p out && | |
FILEPATH=$(find . -name 'libwvlet.*') && | |
cp $FILEPATH ./out/ && | |
cd ./out && for f in *.*; do mv -- \"\$f\" \"linux-arm64_\$f\"; done && | |
ls -alFh" | |
# wvcLibArm64 | |
- name: Upload native libraries for ${{ matrix.name }}-${{ matrix.arch }} | |
uses: actions/upload-artifact@v4 | |
with: | |
name: libwvlet_${{ matrix.name }}-${{ matrix.arch }} | |
path: ./out/*.* | |
- name: Upload libraries to release | |
if: github.event_name == 'release' | |
uses: svenstaro/upload-release-action@v2 | |
with: | |
repo_token: ${{ secrets.GITHUB_TOKEN }} | |
file: ./out/*.* | |
tag: ${{ github.ref }} | |
overwrite: true | |
file_glob: true | |
collect_artifact: | |
name: Collect wvc binaries | |
runs-on: ubuntu-latest | |
needs: build_native | |
steps: | |
- name: Merge artifacts | |
uses: actions/upload-artifact/merge@v4 | |
with: | |
name: wvc-binaries | |
delete-merged: true |