Skip to content

Commit

Permalink
Compile JVM JNI native libaries using Zig, add Linux ARM
Browse files Browse the repository at this point in the history
Zig's build system allows us to trivially cross-compile to different platforms and architectures than the host.
  • Loading branch information
JakeWharton committed Dec 19, 2024
1 parent ce5633b commit b04aea9
Show file tree
Hide file tree
Showing 13 changed files with 2,641 additions and 265 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/Dockerfile

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/build-linux-amd64.sh

This file was deleted.

94 changes: 0 additions & 94 deletions .github/workflows/build-mac.sh

This file was deleted.

133 changes: 72 additions & 61 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,89 @@ env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false"

jobs:
build:
zig:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4

- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0

- run: zig build -p src/jvmMain/resources/jni
working-directory: zipline

- uses: actions/upload-artifact@v4
with:
name: jni-binaries
path: zipline/src/jvmMain/resources/jni
if-no-files-found: error

platform-tests:
needs:
- zig
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [amd64]
cmake-arch: [x86_64]
include:
- os: macos-latest-large
arch: x86_64
cmake-arch: x86_64
platform:
- os: macos-13
task: macosX64Test
- os: macos-latest
arch: aarch64
cmake-arch: arm64
# TODO: build on 'windows-latest'
task: macosArm64Test
- os: ubuntu-latest
task: linuxX64Test

runs-on: ${{ matrix.os }}
runs-on: ${{ matrix.platform.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20

- name: Build native library (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get install -y libtinfo6
cp -a . ../zipline-dockerbuild
docker build \
--tag zipline-linux-amd64 \
.github/workflows
docker run \
--volume `pwd`/../zipline-dockerbuild:/zipline \
--workdir /zipline \
--entrypoint ./.github/workflows/build-linux-amd64.sh \
zipline-linux-amd64
mkdir -p zipline/src/jvmMain/resources/jni/amd64
cp -v ../zipline-dockerbuild/build/jni/amd64/libquickjs.* zipline/src/jvmMain/resources/jni/amd64/
- name: Build native library (macOS)
if: matrix.os == 'macos-latest' || matrix.os == 'macos-latest-large'
run: ./.github/workflows/build-mac.sh -a ${{ matrix.arch }} -c ${{ matrix.cmake-arch }}

- name: Zipline tests
run: ./gradlew :zipline:check --stacktrace

- name: Build all Zipline
if: matrix.os == 'macos-latest'
run: ./gradlew build --stacktrace

- name: Build samples
if: matrix.os == 'macos-latest'
run: ./gradlew -p samples check --stacktrace
java-version: 23

- uses: actions/upload-artifact@v4
- uses: actions/download-artifact@v4
with:
name: jvm-native-libraries-${{ matrix.os }}-${{ matrix.arch }}
path: zipline/src/jvmMain/resources/*
if-no-files-found: error
name: jni-binaries
path: zipline/src/jvmMain/resources/jni

- run: ./gradlew jvmTest ${{ matrix.platform.task }} apiCheck --stacktrace

- uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: test-report-${{ matrix.os }}-${{ matrix.arch }}
name: test-report-${{ matrix.platform.os }}
path: '**/build/reports/tests/**'
retention-days: 1

android:
samples:
runs-on: macos-latest
needs:
- zig

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 23

- uses: actions/download-artifact@v4
with:
name: jni-binaries
path: zipline/src/jvmMain/resources/jni

- run: ./gradlew -p samples check --stacktrace

android-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20
java-version: 23

- name: Enable KVM
run: |
Expand All @@ -106,41 +111,41 @@ jobs:
emulator-boot-timeout: 20000
script: ./gradlew connectedCheck

ios:
ios-app:
runs-on: macos-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20
java-version: 23

- name: Build Xcode samples
run: |
cd samples/world-clock/ios/app
pod install
xcodebuild -workspace WorldClock.xcworkspace -scheme WorldClock -destination 'platform=iOS Simulator,name=iPhone 13,OS=latest'
publish:
build:
runs-on: macos-latest
needs:
- build
- android
- ios
- platform-tests
- samples
- android-tests
- ios-app

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20
java-version: 23

- uses: actions/download-artifact@v4
with:
pattern: jvm-native-libraries-*
path: zipline/src/jvmMain/resources
merge-multiple: true
name: jni-binaries
path: zipline/src/jvmMain/resources/jni

- run: ./gradlew assemble :dokkaHtmlMultiModule

Expand All @@ -162,6 +167,12 @@ jobs:
path: zipline-cli/build/distributions/zipline-cli-*.zip
if-no-files-found: error

- uses: actions/upload-artifact@v4
with:
name: html-docs
path: build/dokka/htmlMultiModule/
if-no-files-found: error

- run: ./gradlew publishToMavenCentral
if: ${{ github.ref == 'refs/heads/trunk' && github.repository == 'cashapp/zipline' }}
env:
Expand Down
62 changes: 6 additions & 56 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,8 @@ on:

env:
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dkotlin.incremental=false"
ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL: 60

jobs:
native-library:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [amd64]
cmake-arch: [x86_64]
include:
- os: macos-latest-large
arch: x86_64
cmake-arch: x86_64
- os: macos-latest
arch: aarch64
cmake-arch: arm64
# TODO: build on 'windows-latest'

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20

- name: Build native library (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
cp -a . ../zipline-dockerbuild
docker build \
--tag zipline-linux-amd64 \
.github/workflows
docker run \
--volume `pwd`/../zipline-dockerbuild:/zipline \
--workdir /zipline \
--entrypoint ./.github/workflows/build-linux-amd64.sh \
zipline-linux-amd64
mkdir -p zipline/src/jvmMain/resources/jni/amd64
cp -v ../zipline-dockerbuild/build/jni/amd64/libquickjs.* zipline/src/jvmMain/resources/jni/amd64/
- name: Build native library (macOS)
if: matrix.os == 'macos-latest' || matrix.os == 'macos-latest-large'
run: ./.github/workflows/build-mac.sh -a ${{ matrix.arch }} -c ${{ matrix.cmake-arch }}

- uses: actions/upload-artifact@v4
with:
name: jvm-native-libraries-${{ matrix.os }}-${{ matrix.arch }}
path: zipline/src/jvmMain/resources/*
if-no-files-found: error

publish:
runs-on: macos-latest
needs:
Expand All @@ -70,13 +19,14 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 20
java-version: 23

- uses: actions/download-artifact@v4
- uses: goto-bus-stop/setup-zig@v2
with:
pattern: jvm-native-libraries-*
path: zipline/src/jvmMain/resources
merge-multiple: true
version: 0.13.0

- run: zig build -p src/jvmMain/resources/jni
working-directory: zipline

- run: ./gradlew publishToMavenCentral :dokkaHtmlMultiModule
if: ${{ github.repository == 'cashapp/zipline' }}
Expand Down
Loading

0 comments on commit b04aea9

Please sign in to comment.