From fddce04ed1013021783129f22d477e2874775f51 Mon Sep 17 00:00:00 2001 From: greenjon Date: Wed, 16 Sep 2026 18:39:19 -0700 Subject: [PATCH] Add native Linux ARM64 build target (linuxarm64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../groovy/tool/generator/GenerateLibs.groovy | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy index d6dd666c..d7df6b0f 100644 --- a/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy +++ b/buildSrc/src/main/groovy/tool/generator/GenerateLibs.groovy @@ -32,6 +32,7 @@ class GenerateLibs extends DefaultTask { private final String[] buildEnvs = System.getProperty('envs')?.split(',') private final boolean forWindows = buildEnvs?.contains('windows') private final boolean forLinux = buildEnvs?.contains('linux') + private final boolean forLinuxArm64 = buildEnvs?.contains('linuxarm64') private final boolean forMac = buildEnvs?.contains('macos') private final boolean forMacArm64 = buildEnvs?.contains('macosarm64') @@ -120,10 +121,11 @@ class GenerateLibs extends DefaultTask { } if (forLinux) { - def linux64 = BuildTarget.newDefaultTarget(Os.Linux, Architecture.Bitness._64) - requireCpp17(linux64) - addFreeTypeIfEnabled(linux64) - buildTargets += linux64 + buildTargets += createLinuxTarget(Architecture.x86) + } + + if (forLinuxArm64) { + buildTargets += createLinuxTarget(Architecture.ARM) } if (forMac) { @@ -145,6 +147,8 @@ class GenerateLibs extends DefaultTask { BuildExecutor.executeAnt(jniDir + '/build-windows64.xml', commonParams) if (forLinux) BuildExecutor.executeAnt(jniDir + '/build-linux64.xml', commonParams) + if (forLinuxArm64) + BuildExecutor.executeAnt(jniDir + '/build-linuxarm64.xml', commonParams) if (forMac) BuildExecutor.executeAnt(jniDir + '/build-macosx64.xml', commonParams) if (forMacArm64) @@ -156,6 +160,8 @@ class GenerateLibs extends DefaultTask { checkLibExist("windows64/imgui-java64.dll") if (forLinux) checkLibExist("linux64/libimgui-java64.so") + if (forLinuxArm64) + checkLibExist("linuxarm64/libimgui-java64.so") if (forMac) checkLibExist("macosx64/libimgui-java64.dylib") if (forMacArm64) @@ -170,6 +176,21 @@ class GenerateLibs extends DefaultTask { } } + BuildTarget createLinuxTarget(Architecture arch) { + def linuxTarget = BuildTarget.newDefaultTarget(Os.Linux, Architecture.Bitness._64, arch) + linuxTarget.libName = "libimgui-java64.so" // Lib for arm64 will be named the same for consistency. + if (arch == Architecture.ARM && System.getProperty('os.arch') in ['aarch64', 'arm64']) { + // gdx-jnigen defaults ARM Linux targets to the aarch64-linux-gnu- cross-compiler + // prefix. When already running natively on an aarch64 host (e.g. GitHub's + // ubuntu-24.04-arm runners) that prefix isn't needed, and the cross toolchain + // package providing it usually isn't installed there anyway. + linuxTarget.compilerPrefix = '' + } + requireCpp17(linuxTarget) + addFreeTypeIfEnabled(linuxTarget) + return linuxTarget + } + BuildTarget createMacTarget(Architecture arch) { def minMacOsVersion = '10.15' def macTarget = BuildTarget.newDefaultTarget(Os.MacOsX, Architecture.Bitness._64, arch)