Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 106 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,113 @@
# Automatically build the project and run any configured tests for every push
# and submitted pull request. This can help catch issues that only occur on
# certain platforms or Java versions, and provides a first line of defence
# against bad commits.

name: build
on: [pull_request, push]
on: [push, workflow_dispatch]

permissions:
contents: write

jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
21, # Current Java LTS
]
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
steps:
- name: checkout repository
uses: actions/checkout@v4
- name: validate gradle wrapper
uses: gradle/wrapper-validation-action@v2
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v4
- uses: actions/checkout@v4

- uses: actions/setup-java@v4
with:
distribution: microsoft
java-version: 21

- uses: gradle/actions/setup-gradle@v4

# Android (bionic) arm64 builds of the LWJGL natives that the glibc linux-arm64
# builds cannot provide on Zalith/Pojav. Cached so only the first run is slow.
- name: Cache Android natives
id: natives-cache
uses: actions/cache@v4
with:
path: src/main/resources/linux/arm64/org/lwjgl
key: android-natives-v1-${{ hashFiles('.github/workflows/build.yml') }}

- name: Build Android arm64 natives (spirv-cross, shaderc)
if: steps.natives-cache.outputs.cache-hit != 'true'
run: |
set -euxo pipefail
sudo apt-get update -y
sudo apt-get install -y ninja-build cmake python3 git

NDK="${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_ROOT:-${ANDROID_NDK_HOME:-}}}"
test -d "$NDK"
STRIP="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
COMMON=(-G Ninja
-DCMAKE_TOOLCHAIN_FILE="$NDK/build/cmake/android.toolchain.cmake"
-DANDROID_ABI=arm64-v8a
-DANDROID_PLATFORM=android-26
-DANDROID_STL=c++_static
-DCMAKE_BUILD_TYPE=Release)

OUT="$GITHUB_WORKSPACE/src/main/resources/linux/arm64/org/lwjgl"
mkdir -p "$OUT/spvc" "$OUT/shaderc"
cd "$RUNNER_TEMP"

# --- SPIRV-Cross (C API) -> libspirv-cross.so ---
git clone --depth 1 --branch vulkan-sdk-1.3.296.0 https://github.com/KhronosGroup/SPIRV-Cross.git
cmake -S SPIRV-Cross -B spvc-build "${COMMON[@]}" \
-DSPIRV_CROSS_SHARED=ON -DSPIRV_CROSS_STATIC=OFF \
-DSPIRV_CROSS_CLI=OFF -DSPIRV_CROSS_ENABLE_TESTS=OFF
cmake --build spvc-build --target spirv-cross-c-shared -j"$(nproc)"
cp "$(find spvc-build -name 'libspirv-cross-c-shared.so' | head -n1)" "$OUT/spvc/libspirv-cross.so"
"$STRIP" --strip-unneeded "$OUT/spvc/libspirv-cross.so"

# --- shaderc -> libshaderc.so ---
git clone --depth 1 --branch v2024.4 https://github.com/google/shaderc.git
(cd shaderc && python3 utils/git-sync-deps)
cmake -S shaderc -B shaderc-build "${COMMON[@]}" \
-DSHADERC_SKIP_TESTS=ON -DSHADERC_SKIP_EXAMPLES=ON \
-DSHADERC_SKIP_COPYRIGHT_CHECK=ON -DSHADERC_ENABLE_WERROR_COMPILE=OFF \
-DSPIRV_SKIP_TESTS=ON -DSPIRV_SKIP_EXECUTABLES=ON \
-DENABLE_GLSLANG_BINARIES=OFF -DSPIRV_HEADERS_SKIP_EXAMPLES=ON
cmake --build shaderc-build --target shaderc_shared -j"$(nproc)"
cp "$(find shaderc-build -name 'libshaderc_shared.so' | head -n1)" "$OUT/shaderc/libshaderc.so"
"$STRIP" --strip-unneeded "$OUT/shaderc/libshaderc.so"

- name: Check natives
run: |
set -eux
for f in spvc/libspirv-cross.so shaderc/libshaderc.so; do
p="src/main/resources/linux/arm64/org/lwjgl/$f"
test -s "$p"
file "$p"
# must not depend on glibc's libstdc++
! (readelf -d "$p" | grep -q 'libstdc++')
done

- run: chmod +x ./gradlew && ./gradlew build --no-daemon

- name: Check natives are inside the jar
run: |
JAR="$(ls build/libs/*.jar | grep -v sources | head -n1)"
unzip -l "$JAR" | grep -E 'linux/arm64/org/lwjgl/(spvc/libspirv-cross|shaderc/libshaderc)\.so'
test "$(unzip -l "$JAR" | grep -cE 'linux/arm64/org/lwjgl/(spvc/libspirv-cross|shaderc/libshaderc)\.so')" -eq 2

- name: Prepare jar
run: |
mkdir out
cp "$(ls build/libs/*.jar | grep -v sources | head -n1)" out/Riftoptimizer-Vulkan-mobile.jar

- uses: actions/upload-artifact@v4
with:
java-version: ${{ matrix.java }}
distribution: 'microsoft'
- name: make gradle wrapper executable
run: chmod +x ./gradlew
- name: build
run: ./gradlew build
- name: capture build artifacts
if: ${{ matrix.java == '21' }} # Only upload artifacts built from latest java
uses: actions/upload-artifact@v4
name: Riftoptimizer-Vulkan-mobile
path: out/Riftoptimizer-Vulkan-mobile.jar

- uses: softprops/action-gh-release@v2
if: github.ref == 'refs/heads/mobile-compat'
with:
name: Artifacts
path: build/libs/
tag_name: mobile-test
name: Riftoptimizer-Vulkan Mobile Test
prerelease: true
fail_on_unmatched_files: true
files: out/Riftoptimizer-Vulkan-mobile.jar
body: |
Test build for Minecraft 1.21.11 (Fabric), for Zalith/Pojav on Android.
- LWJGL modules bundled at 3.3.6 to match the launcher (fixes NoSuchFieldError UNSAFE).
- libspirv-cross.so and libshaderc.so are now built for Android arm64 (bionic, static libc++)
by CI and shipped inside the jar (fixes libstdc++.so.6 / libspirv-cross.so UnsatisfiedLinkError).
Not fully verified on Android yet.
28 changes: 15 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,37 @@ dependencies {
includeModule("fabric-transitive-access-wideners-v1")
}

project.ext.lwjglVersion = "3.3.3"
// Mobile (Zalith/Pojav) ships LWJGL 3.3.6-snapshot as core. Bundled modules must
// match it: 3.3.3 structs reference Struct.UNSAFE, which no longer exists in 3.3.6.
project.ext.lwjglVersion = "3.3.6"
project.ext.jomlVersion = "1.10.4"
project.ext.winNatives = "natives-windows"
project.ext.linuxNatives = "natives-linux"
project.ext.linuxArmNatives = "natives-linux-arm64"
project.ext.macosNatives = "natives-macos"
project.ext.macosArmNatives = "natives-macos-arm64"

dependencies {
include(implementation("org.lwjgl:lwjgl-vulkan:$lwjglVersion"))

ext.includeNatives = { name ->
// shaderc / spirv-cross: the official linux-arm64 natives are glibc builds that need
// libstdc++.so.6, which Android does not have (UnsatisfiedLinkError on libshaderc.so).
// For these two, the arm64 .so files are built for Android (bionic, static libc++) by CI
// and shipped as resources at linux/arm64/org/lwjgl/<module>/ instead.
ext.includeNatives = { name, androidBuilt ->
include(implementation("$name:$lwjglVersion"))
include(runtimeOnly("$name:$lwjglVersion:$winNatives"))
include(runtimeOnly("$name:$lwjglVersion:$linuxNatives"))
if (!androidBuilt) {
include(runtimeOnly("$name:$lwjglVersion:$linuxArmNatives"))
}
include(runtimeOnly("$name:$lwjglVersion:$macosNatives"))
include(runtimeOnly("$name:$lwjglVersion:$macosArmNatives"))
}

includeNatives("org.lwjgl:lwjgl-vma")
includeNatives("org.lwjgl:lwjgl-shaderc")
includeNatives("org.lwjgl:lwjgl-spvc")
includeNatives("org.lwjgl:lwjgl-vma", false)
includeNatives("org.lwjgl:lwjgl-shaderc", true)
includeNatives("org.lwjgl:lwjgl-spvc", true)

//MoltenVK
include(runtimeOnly("org.lwjgl:lwjgl-vulkan:$lwjglVersion:$macosNatives"))
Expand All @@ -80,9 +90,6 @@ tasks.withType(JavaCompile).configureEach {
}

java {
// Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task
// if it is present.
// If you remove this line, sources will not be generated.
withSourcesJar()

sourceCompatibility = JavaVersion.VERSION_21
Expand All @@ -104,11 +111,6 @@ publishing {
}
}

// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
// Notice: This block does NOT have the same function as the block in the top level.
// The repositories here will be used for publishing your artifact, not for
// retrieving dependencies.
}
}
98 changes: 98 additions & 0 deletions build.yml.new
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: build
on: [push, workflow_dispatch]

permissions:
contents: write

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

- uses: actions/setup-java@v4
with:
distribution: microsoft
java-version: 21

- uses: gradle/actions/setup-gradle@v4

- name: Cache Android natives
id: natcache
uses: actions/cache@v4
with:
path: android-natives
key: android-natives-shaderc-2024.4-spvc-1.3.280-v1

- name: Build Android natives (shaderc + SPIRV-Cross, bionic, static libc++)
if: steps.natcache.outputs.cache-hit != 'true'
run: |
set -euxo pipefail
NDK="${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-$ANDROID_NDK_ROOT}}"
TC="$NDK/build/cmake/android.toolchain.cmake"
STRIP="$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip"
COMMON="-G Ninja -DCMAKE_TOOLCHAIN_FILE=$TC -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-26 -DANDROID_STL=c++_static -DCMAKE_BUILD_TYPE=Release -DCMAKE_SHARED_LINKER_FLAGS=-Wl,-z,max-page-size=16384"
mkdir -p android-natives

git clone --depth 1 --branch v2024.4 https://github.com/google/shaderc
(cd shaderc && python3 utils/git-sync-deps)
cmake -S shaderc -B build-shaderc $COMMON \
-DSHADERC_SKIP_TESTS=ON -DSHADERC_SKIP_EXAMPLES=ON -DSHADERC_SKIP_COPYRIGHT_CHECK=ON \
-DSPIRV_SKIP_TESTS=ON -DSPIRV_SKIP_EXECUTABLES=ON -DSKIP_GLSLANG_INSTALL=ON \
-DSKIP_SPIRV_TOOLS_INSTALL=ON -DSKIP_GOOGLETEST_INSTALL=ON -DENABLE_GLSLANG_BINARIES=OFF
cmake --build build-shaderc --target shaderc_shared -j"$(nproc)"
cp "$(find build-shaderc -name 'libshaderc_shared.so' | head -n1)" android-natives/libshaderc.so

git clone --depth 1 --branch vulkan-sdk-1.3.280.0 https://github.com/KhronosGroup/SPIRV-Cross
cmake -S SPIRV-Cross -B build-spvc $COMMON \
-DSPIRV_CROSS_SHARED=ON -DSPIRV_CROSS_STATIC=OFF -DSPIRV_CROSS_CLI=OFF -DSPIRV_CROSS_ENABLE_TESTS=OFF
cmake --build build-spvc -j"$(nproc)"
cp "$(find build-spvc -name 'libspirv-cross-c-shared.so' | head -n1)" android-natives/libspirv-cross.so

"$STRIP" --strip-unneeded android-natives/*.so

- name: Verify natives are Android-compatible
run: |
set -eu
for f in android-natives/libshaderc.so android-natives/libspirv-cross.so; do
test -s "$f"
readelf -h "$f" | grep -q AArch64
readelf -d "$f" | grep NEEDED
if readelf -d "$f" | grep -E 'libstdc\+\+|libgcc_s'; then echo "::error::$f depends on glibc libstdc++"; exit 1; fi
done

- name: Add natives to mod resources
run: |
mkdir -p src/main/resources/linux/arm64/org/lwjgl/shaderc src/main/resources/linux/arm64/org/lwjgl/spvc
cp android-natives/libshaderc.so src/main/resources/linux/arm64/org/lwjgl/shaderc/libshaderc.so
cp android-natives/libspirv-cross.so src/main/resources/linux/arm64/org/lwjgl/spvc/libspirv-cross.so

- run: chmod +x ./gradlew && ./gradlew build --no-daemon

- name: Prepare jar
run: |
mkdir out
cp "$(ls build/libs/*.jar | grep -v sources | head -n1)" out/Riftoptimizer-Vulkan-mobile.jar
unzip -l out/Riftoptimizer-Vulkan-mobile.jar | grep -E 'linux/arm64/org/lwjgl/(shaderc|spvc)/'

- uses: actions/upload-artifact@v4
with:
name: Riftoptimizer-Vulkan-mobile
path: out/Riftoptimizer-Vulkan-mobile.jar

- uses: softprops/action-gh-release@v2
if: github.ref == 'refs/heads/mobile-compat'
with:
tag_name: mobile-v4-android-natives
name: Riftoptimizer-Vulkan Mobile v4 (Android natives)
prerelease: true
fail_on_unmatched_files: true
files: out/Riftoptimizer-Vulkan-mobile.jar
body: |
Minecraft 1.21.11 (Fabric), Zalith/Pojav on Android (arm64).

Fixes crash #3: `UnsatisfiedLinkError ... libshaderc.so ... library "libstdc++.so.6" not found`.
- libshaderc / libspirv-cross are now built for Android (bionic, static libc++) in CI instead of
using the glibc linux-arm64 LWJGL builds. This also pre-empts the same crash in spirv-cross.
- Shaders now target Vulkan 1.0 / SPIR-V 1.0 so Vulkan-1.0-only drivers (Turnip Adreno 610) accept them.
Use together with Riftoptimizer 1.2.6. Not yet verified on a device.
Loading