Skip to content

Commit 2c5a5ab

Browse files
committed
Compile toolchains for macOS hosts
1 parent 21fe82b commit 2c5a5ab

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

.github/workflows/prebuild_assets.yml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ jobs:
1414
compile:
1515
name: Compile SQLite
1616
timeout-minutes: 30
17-
# We need the intel build because arm runners don't support docker :(
18-
runs-on: macos-15-intel
17+
runs-on: macos-latest
1918
outputs:
2019
artifact_url: ${{ steps.upload.outputs.artifact-url }}
2120
artifact_id: ${{ steps.upload.outputs.artifact-id }}
@@ -51,20 +50,16 @@ jobs:
5150
- name: Set up XCode
5251
if: steps.cache_prebuild.outputs.cache-hit != 'true'
5352
uses: maxim-lobanov/setup-xcode@v1
54-
- name: Setup Docker
55-
uses: douglascamata/setup-docker-macos-action@v1
56-
- name: Setup Linux build docker image
57-
run: docker build -t powersync_kotlin_sqlite3mc_build_helper --load jni
58-
- name: Download llvm-mingw
53+
- name: Download build tools
5954
run: |
60-
curl -L https://github.com/mstorsjo/llvm-mingw/releases/download/20251118/llvm-mingw-20251118-ucrt-macos-universal.tar.xz -o llvm-ming.tar.xz
61-
tar --extract --gzip --file llvm-ming.tar.xz
62-
rm llvm-ming.tar.xz
55+
cd internal/prebuild-binaries
56+
./download_glibc.sh
57+
./download_llvm_mingw.sh
6358
6459
- name: Compile SQLite with Gradle
6560
if: steps.cache_prebuild.outputs.cache-hit != 'true'
6661
run: |
67-
./gradlew --scan -PllvmMingw=$(pwd)/llvm-mingw-20251118-ucrt-macos-universal internal:prebuild-binaries:compileNative
62+
./gradlew --scan internal:prebuild-binaries:compileNative
6863
shell: bash
6964
- uses: actions/upload-artifact@v5
7065
id: upload

internal/prebuild-binaries/build.gradle.kts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ fun compileJni(target: JniTarget): CompiledAsset {
7878
JniTarget.LINUX_X64, JniTarget.LINUX_ARM -> {}
7979
JniTarget.WINDOWS_X64, JniTarget.WINDOWS_ARM -> {
8080
// For Windows, we compile with LLVM MinGW: https://github.com/mstorsjo/llvm-mingw
81-
val path = providers.gradleProperty("llvmMingw")
82-
val clang = path.orNull?.let {
83-
Path(path.get()).resolve("bin/clang").toString()
84-
} ?: "clang"
81+
val clang = layout.buildDirectory.file("llvm-mingw/bin/clang").map { it.asFile.path }
8582
clangPath.set(clang)
8683
}
8784
JniTarget.MACOS_X64, JniTarget.MACOS_ARM -> {
@@ -154,11 +151,16 @@ val compileNative by tasks.registering(Copy::class) {
154151
}
155152
}
156153

157-
val jniCompileTasks: List<CompiledAsset> = JniTarget.entries.map(::compileJni)
154+
val jniCompileTasks: Map<JniTarget, CompiledAsset> = buildMap {
155+
for (target in JniTarget.entries) {
156+
put(target, compileJni(target))
157+
}
158+
}
159+
158160
val compileJni by tasks.registering(Copy::class) {
159161
into(project.layout.buildDirectory.dir("output/jni"))
160162

161-
for (task in jniCompileTasks) {
163+
for (task in jniCompileTasks.values) {
162164
from(task.output) {
163165
rename { task.fullName }
164166
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
mkdir -p build/sysroot
5+
cd build/sysroot
6+
7+
function download_package() {
8+
curl -L $1 | tar --extract --gzip
9+
}
10+
11+
download_package https://archlinux.org/packages/core/x86_64/glibc/download/
12+
download_package https://archlinux.org/packages/core/x86_64/linux-api-headers/download/
13+
download_package https://archlinux.org/packages/core/x86_64/gcc/download/
14+
download_package https://archlinux.org/packages/core/x86_64/gcc-libs/download/
15+
16+
download_package https://archlinux.org/packages/extra/any/aarch64-linux-gnu-glibc/download/
17+
download_package https://archlinux.org/packages/extra/any/aarch64-linux-gnu-linux-api-headers/download/
18+
download_package https://archlinux.org/packages/extra/x86_64/aarch64-linux-gnu-gcc/download/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
mkdir -p build
5+
cd build/
6+
7+
curl -L https://github.com/mstorsjo/llvm-mingw/releases/download/20251118/llvm-mingw-20251118-ucrt-macos-universal.tar.xz -o llvm-ming.tar.xz
8+
tar --extract --gzip --file llvm-ming.tar.xz
9+
rm llvm-ming.tar.xz
10+
11+
mv llvm-mingw-20251118-ucrt-macos-universal llvm-mingw

plugins/build-plugin/src/main/kotlin/com/powersync/compile/JniLibraryCompile.kt

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,22 @@ abstract class JniLibraryCompile: DefaultTask() {
8787
return file.relativeTo(workingDir).path
8888
}
8989

90-
if (target == JniTarget.LINUX_X64 || target == JniTarget.LINUX_ARM) {
91-
executable = "/opt/homebrew/bin/docker"
92-
args(
93-
"run",
94-
"-v", "./jni:/jni",
95-
"-v", "./build:/build",
96-
"powersync_kotlin_sqlite3mc_build_helper",
97-
"clang",
98-
"-fuse-ld=lld"
99-
)
100-
} else {
101-
executable = clang
90+
if (target == JniTarget.LINUX_X64) {
91+
args("-fuse-ld=lld")
92+
args("--sysroot=build/sysroot/")
10293
}
10394

95+
if (target == JniTarget.LINUX_ARM) {
96+
val gccParent = layout.buildDirectory.dir("sysroot/usr/lib/gcc/aarch64-linux-gnu")
97+
val gccPath = filePath(gccParent.get().asFile.listFiles().single())
98+
99+
args("-fuse-ld=lld")
100+
args("--sysroot=build/sysroot/usr/aarch64-linux-gnu/")
101+
args("-Wl,-L", gccPath)
102+
args("-B", gccPath)
103+
}
104+
105+
executable = clang
104106
toolchain.orNull?.let { args("-B$toolchain") }
105107

106108
args(

0 commit comments

Comments
 (0)