Skip to content

Commit b8236af

Browse files
authored
Fix native library publish for non amd64 platforms (#8108)
When publishing native packages make sure different architectures don't override each other Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent 4b089af commit b8236af

3 files changed

Lines changed: 63 additions & 17 deletions

File tree

.github/workflows/publish.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ jobs:
8080
env:
8181
# Picked up by gradle-git-version
8282
GIT_VERSION: ${{ github.event.release.tag_name }}
83+
# The cross-compiled release JNI libs are copied into resources/native/
84+
# before any gradle task runs; skip the host-arch rebuild that would
85+
# otherwise overwrite them with a debug amd64 .so on the publish runner.
86+
VORTEX_SKIP_MAKE_TEST_FILES: "true"
8387
defaults:
8488
run:
8589
working-directory: ./java

.github/workflows/release-binaries.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,40 @@ permissions:
1010
jobs:
1111
build:
1212
name: Build ${{ matrix.target }}
13-
runs-on: ${{ matrix.runs-on }}
13+
runs-on: >-
14+
${{ github.repository == 'vortex-data/vortex'
15+
&& matrix.runner
16+
|| matrix.fallback_runner }}
1417
timeout-minutes: 120
1518
strategy:
1619
fail-fast: false
1720
matrix:
1821
include:
1922
- target: aarch64-apple-darwin
20-
runs-on: macos-latest
23+
runner: macos-latest
24+
fallback_runner: macos-latest
2125
archive: tgz
2226
- target: x86_64-apple-darwin
23-
runs-on: macos-15-intel
27+
runner: macos-15-intel
28+
fallback_runner: macos-15-intel
2429
archive: tgz
30+
# Linux targets cross-compile from an amd64 runs-on runner via
31+
# cargo-zigbuild with glibc 2.31 pinning, matching the Python wheel
32+
# and JNI builds.
2533
- target: aarch64-unknown-linux-gnu
26-
runs-on: ubuntu-24.04-arm
34+
runner: runs-on=${{ github.run_id }}/runner=amd64-medium/image=ubuntu24-full-x64-pre-v2/tag=release-vx-aarch64-linux
35+
fallback_runner: ubuntu-24.04
2736
archive: tgz
2837
- target: x86_64-unknown-linux-gnu
29-
runs-on: ubuntu-24.04
38+
runner: runs-on=${{ github.run_id }}/runner=amd64-medium/image=ubuntu24-full-x64-pre-v2/tag=release-vx-amd64-linux
39+
fallback_runner: ubuntu-24.04
3040
archive: tgz
3141
steps:
42+
- uses: runs-on/action@v2
43+
if: github.repository == 'vortex-data/vortex' && contains(matrix.target, 'linux')
44+
with:
45+
sccache: s3
46+
3247
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
3348
with:
3449
fetch-depth: 0
@@ -37,9 +52,24 @@ jobs:
3752
with:
3853
repo-token: ${{ secrets.GITHUB_TOKEN }}
3954
targets: ${{ matrix.target }}
40-
enable-sccache: "false"
55+
enable-sccache: ${{ contains(matrix.target, 'linux') && 'true' || 'false' }}
56+
57+
- name: Setup Zig
58+
if: contains(matrix.target, 'linux')
59+
uses: mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2.2.1
60+
61+
- name: Install cargo-zigbuild
62+
if: contains(matrix.target, 'linux')
63+
uses: taiki-e/cache-cargo-install-action@66c9585ef5ca780ee69399975a5e911f47905995
64+
with:
65+
tool: cargo-zigbuild
66+
67+
- name: Build release binary (Linux, zigbuild)
68+
if: contains(matrix.target, 'linux')
69+
run: cargo zigbuild --release --package vortex-tui --bin vx --target ${{ matrix.target }}.2.31
4170

42-
- name: Build release binary
71+
- name: Build release binary (macOS)
72+
if: contains(matrix.target, 'apple-darwin')
4373
run: cargo build --release --package vortex-tui --bin vx --target ${{ matrix.target }}
4474

4575
- name: Create archive (tgz)

java/vortex-jni/build.gradle.kts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,43 @@ tasks.register("makeTestFiles") {
112112
description = "Generate files used by unit tests"
113113
group = "verification"
114114

115+
// The publish workflow places release, cross-compiled libs for every supported
116+
// architecture before invoking shadowJar; rebuilding the host-arch debug lib
117+
// here would overwrite them (linux-aarch64 ends up holding a linux-amd64 .so).
118+
onlyIf { System.getenv("VORTEX_SKIP_MAKE_TEST_FILES") != "true" }
119+
115120
doLast {
116121
println("makeTestFiles executed")
117122

118123
val execOps = serviceOf<ExecOperations>()
119124

120-
// Build the JNI lib
125+
// Build the JNI lib for the host architecture only.
121126
execOps.exec {
122127
workingDir = rootProject.projectDir.absoluteFile.parentFile
123128
executable = "cargo"
124129
args("build", "--package", "vortex-jni")
125130
}
126131

127-
copy {
128-
from("${rootProject.projectDir.absoluteFile.parentFile}/target/debug/libvortex_jni.so")
129-
into("$projectDir/src/main/resources/native/linux-amd64")
132+
val osName = System.getProperty("os.name").lowercase()
133+
val osArch = System.getProperty("os.arch").lowercase()
134+
val osShortName = when {
135+
osName.contains("mac") -> "darwin"
136+
osName.contains("nix") || osName.contains("nux") -> "linux"
137+
osName.contains("win") -> "win"
138+
else -> throw GradleException("Unsupported OS for makeTestFiles: $osName")
130139
}
131-
132-
copy {
133-
from("${rootProject.projectDir.absoluteFile.parentFile}/target/debug/libvortex_jni.so")
134-
into("$projectDir/src/main/resources/native/linux-aarch64")
140+
val libExt = when (osShortName) {
141+
"darwin" -> ".dylib"
142+
"linux" -> ".so"
143+
"win" -> ".dll"
144+
else -> throw GradleException("Unsupported OS short name: $osShortName")
135145
}
136146

147+
// Only populate the host-arch directory so cross-compiled libs for other
148+
// architectures (placed by the publish workflow) are preserved.
137149
copy {
138-
from("${rootProject.projectDir.absoluteFile.parentFile}/target/debug/libvortex_jni.dylib")
139-
into("$projectDir/src/main/resources/native/darwin-aarch64")
150+
from("${rootProject.projectDir.absoluteFile.parentFile}/target/debug/libvortex_jni$libExt")
151+
into("$projectDir/src/main/resources/native/$osShortName-$osArch")
140152
}
141153
}
142154
}

0 commit comments

Comments
 (0)