Skip to content

Commit f13ec24

Browse files
authored
feat: add native Linux ARM64 build target (linuxarm64) (#439)
generateLibs' Linux target has always been constructed via newDefaultTarget(Os.Linux, Bitness._64), which defaults to Architecture.x86 regardless of host architecture. That's the root cause behind #105: even on a native aarch64 host, the task emits x86-only compiler flags (-mfpmath=sse -msse -m64), which a real aarch64 g++/gcc rejects outright. gdx-jnigen 2.5.2 (the library this build script sits on top of) already ships a correct Architecture.ARM Linux target (aarch64-linux-gnu- prefix, -fPIC, no SSE flags) — this task just never selects it. Add an opt-in `linuxarm64` env (mirroring the existing `macosarm64` convention) that builds via that target instead, refactoring the existing x86 Linux target into a shared createLinuxTarget() helper (mirroring createMacTarget()) so both paths stay in sync. libName is pinned to libimgui-java64.so on both architectures for consistency, matching how the mac target already does this for x86_64/arm64.
1 parent d95baae commit f13ec24

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

‎buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class GenerateLibs extends DefaultTask {
3232
private final String[] buildEnvs = System.getProperty('envs')?.split(',')
3333
private final boolean forWindows = buildEnvs?.contains('windows')
3434
private final boolean forLinux = buildEnvs?.contains('linux')
35+
private final boolean forLinuxArm64 = buildEnvs?.contains('linuxarm64')
3536
private final boolean forMac = buildEnvs?.contains('macos')
3637
private final boolean forMacArm64 = buildEnvs?.contains('macosarm64')
3738

@@ -120,10 +121,11 @@ class GenerateLibs extends DefaultTask {
120121
}
121122

122123
if (forLinux) {
123-
def linux64 = BuildTarget.newDefaultTarget(Os.Linux, Architecture.Bitness._64)
124-
requireCpp17(linux64)
125-
addFreeTypeIfEnabled(linux64)
126-
buildTargets += linux64
124+
buildTargets += createLinuxTarget(Architecture.x86)
125+
}
126+
127+
if (forLinuxArm64) {
128+
buildTargets += createLinuxTarget(Architecture.ARM)
127129
}
128130

129131
if (forMac) {
@@ -145,6 +147,8 @@ class GenerateLibs extends DefaultTask {
145147
BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', commonParams)
146148
if (forLinux)
147149
BuildExecutor.executeAnt(jniDir + '/build-linux64.xml', commonParams)
150+
if (forLinuxArm64)
151+
BuildExecutor.executeAnt(jniDir + '/build-linuxarm64.xml', commonParams)
148152
if (forMac)
149153
BuildExecutor.executeAnt(jniDir + '/build-macosx64.xml', commonParams)
150154
if (forMacArm64)
@@ -156,6 +160,8 @@ class GenerateLibs extends DefaultTask {
156160
checkLibExist("windows64/imgui-java64.dll")
157161
if (forLinux)
158162
checkLibExist("linux64/libimgui-java64.so")
163+
if (forLinuxArm64)
164+
checkLibExist("linuxarm64/libimgui-java64.so")
159165
if (forMac)
160166
checkLibExist("macosx64/libimgui-java64.dylib")
161167
if (forMacArm64)
@@ -170,6 +176,21 @@ class GenerateLibs extends DefaultTask {
170176
}
171177
}
172178

179+
BuildTarget createLinuxTarget(Architecture arch) {
180+
def linuxTarget = BuildTarget.newDefaultTarget(Os.Linux, Architecture.Bitness._64, arch)
181+
linuxTarget.libName = "libimgui-java64.so" // Lib for arm64 will be named the same for consistency.
182+
if (arch == Architecture.ARM && System.getProperty('os.arch') in ['aarch64', 'arm64']) {
183+
// gdx-jnigen defaults ARM Linux targets to the aarch64-linux-gnu- cross-compiler
184+
// prefix. When already running natively on an aarch64 host (e.g. GitHub's
185+
// ubuntu-24.04-arm runners) that prefix isn't needed, and the cross toolchain
186+
// package providing it usually isn't installed there anyway.
187+
linuxTarget.compilerPrefix = ''
188+
}
189+
requireCpp17(linuxTarget)
190+
addFreeTypeIfEnabled(linuxTarget)
191+
return linuxTarget
192+
}
193+
173194
BuildTarget createMacTarget(Architecture arch) {
174195
def minMacOsVersion = '10.15'
175196
def macTarget = BuildTarget.newDefaultTarget(Os.MacOsX, Architecture.Bitness._64, arch)

0 commit comments

Comments
 (0)