diff --git a/.github/workflows/build-natives.yml b/.github/workflows/build-natives.yml index 0e3316cb..4670e499 100644 --- a/.github/workflows/build-natives.yml +++ b/.github/workflows/build-natives.yml @@ -69,26 +69,33 @@ jobs: uses: robinraju/release-downloader@v1.10 with: repository: 'mstorsjo/llvm-mingw' - tag: 20240518 - fileName: llvm-mingw-20240518-ucrt-ubuntu-20.04-x86_64.tar.xz + tag: 20240619 + fileName: llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz tarBall: false zipBall: false - name: Set up llvm-mingw run: | sudo mkdir -p /usr/local - sudo tar -Jxf llvm-mingw-20240518-ucrt-ubuntu-20.04-x86_64.tar.xz -C /usr/local - echo "PATH=/usr/local/llvm-mingw-20240518-ucrt-ubuntu-20.04-x86_64/bin:$PATH" >> $GITHUB_ENV + sudo tar -Jxf llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64.tar.xz -C /usr/local + echo "PATH=/usr/local/llvm-mingw-20240619-ucrt-ubuntu-20.04-x86_64/bin:$PATH" >> $GITHUB_ENV - name: Install cross-compilation toolchains run: | sudo apt update - sudo apt install -y --force-yes gcc g++ linux-libc-dev libc6-dev - sudo apt install -y --force-yes libc6-dev-i386 lib32stdc++-9-dev - sudo apt install -y --force-yes linux-libc-dev linux-libc-dev-i386-cross - sudo apt install -y --force-yes linux-libc-dev-armhf-cross linux-libc-dev-arm64-cross linux-libc-dev-amd64-cross - sudo apt install -y --force-yes libstdc++-9-dev-i386-cross libstdc++-9-dev-arm64-cross libstdc++-9-dev-armhf-cross - sudo apt install -y --force-yes gcc-i686-linux-gnu g++-i686-linux-gnu libc6-dev-i386-cross + # x86_64 + sudo apt install -y --force-yes gcc g++ + sudo apt install -y --force-yes libc6-dev linux-libc-dev linux-libc-dev-amd64-cross + # x86 + sudo apt install -y --force-yes gcc-i686-linux-gnu g++-i686-linux-gnu + sudo apt install -y --force-yes lib32stdc++-9-dev libstdc++-9-dev-i386-cross + sudo apt install -y --force-yes libc6-dev-i386 libc6-dev-i386-cross linux-libc-dev-i386-cross + # arm64 sudo apt install -y --force-yes gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross + sudo apt install -y --force-yes libstdc++-9-dev-arm64-cross linux-libc-dev-arm64-cross + # armhf sudo apt install -y --force-yes gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross + sudo apt install -y --force-yes libstdc++-9-dev-armhf-cross linux-libc-dev-armhf-cross + # TODO: riscv64 + # Windows sudo apt install -y --force-yes mingw-w64 lib32z1 - name: Install PatchELF (verneed-fix) run: | @@ -106,7 +113,9 @@ jobs: - name: Build natives run: | export NDK_HOME=$ANDROID_NDK_LATEST_HOME - ./gradlew jniGen jnigenBuildLinux jnigenBuildLinux64 jnigenBuildLinuxARM jnigenBuildLinuxARM64 + ./gradlew jniGen jnigenBuildLinux jnigenBuildLinux64 + ./gradlew jniGen jnigenBuildLinuxARM jnigenBuildLinuxARM64 + # TODO: ./gradlew jniGen jnigenBuildLinuxRISCV64 ./gradlew jniGen jnigenBuildAndroid jnigenBuildWindows jnigenBuildWindows64 jnigenBuildWindowsARM64 - name: Test (Desktop) run: | diff --git a/jni/luajava/jua.cpp b/jni/luajava/jua.cpp index 1b83a964..f2cfe5e6 100644 --- a/jni/luajava/jua.cpp +++ b/jni/luajava/jua.cpp @@ -6,7 +6,7 @@ #include -#include "lj/lj_arch.h" +#include "mobile-nosys.h" #if LJ_TARGET_DLOPEN #include int reopenAsGlobal(const char * file) { diff --git a/jni/luajava/lj/lj_arch.h b/jni/luajava/lj/lj_arch.h index dba033b6..26140655 100644 --- a/jni/luajava/lj/lj_arch.h +++ b/jni/luajava/lj/lj_arch.h @@ -1,6 +1,6 @@ /* ** Target architecture selection. -** Copyright (C) 2005-2022 Mike Pall. See Copyright Notice in luajit.h +** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h */ #ifndef _LJ_ARCH_H @@ -57,7 +57,7 @@ #define LUAJIT_TARGET LUAJIT_ARCH_X64 #elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM) #define LUAJIT_TARGET LUAJIT_ARCH_ARM -#elif defined(__aarch64__) +#elif defined(__aarch64__) || defined(_M_ARM64) #define LUAJIT_TARGET LUAJIT_ARCH_ARM64 #elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC) #define LUAJIT_TARGET LUAJIT_ARCH_PPC @@ -66,7 +66,7 @@ #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS) #define LUAJIT_TARGET LUAJIT_ARCH_MIPS32 #else -#error "No support for this architecture (yet)" +#error "Architecture not supported (in this version), see: https://luajit.org/status.html#architectures" #endif #endif @@ -93,6 +93,9 @@ #elif defined(__CYGWIN__) #define LJ_TARGET_CYGWIN 1 #define LUAJIT_OS LUAJIT_OS_POSIX +#elif defined(__QNX__) +#define LJ_TARGET_QNX 1 +#define LUAJIT_OS LUAJIT_OS_POSIX #else #define LUAJIT_OS LUAJIT_OS_OTHER #endif @@ -121,7 +124,7 @@ #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS) #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX -#if TARGET_OS_IPHONE +#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE #define LJ_TARGET_IOS 1 #else #define LJ_TARGET_IOS 0 @@ -234,7 +237,7 @@ #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */ #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL -#if __ARM_ARCH == 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__ +#if __ARM_ARCH >= 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__ #define LJ_ARCH_VERSION 80 #elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__ #define LJ_ARCH_VERSION 70 @@ -256,6 +259,9 @@ #define LJ_ARCH_NAME "arm64" #define LJ_ARCH_ENDIAN LUAJIT_LE #endif +#if !defined(LJ_ABI_PAUTH) && defined(__arm64e__) +#define LJ_ABI_PAUTH 1 +#endif #define LJ_TARGET_ARM64 1 #define LJ_TARGET_EHRETREG 0 #define LJ_TARGET_EHRAREG 30 @@ -325,6 +331,7 @@ #define LJ_ARCH_NOFFI 1 #elif LJ_ARCH_BITS == 64 #error "No support for PPC64" +#undef LJ_TARGET_PPC #endif #if _ARCH_PWR7 @@ -463,11 +470,17 @@ #endif #endif #elif !LJ_TARGET_PS3 +#if __clang__ +#if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)) +#error "Need at least Clang 3.5 or newer" +#endif +#else #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3) #error "Need at least GCC 4.3 or newer" #endif #endif #endif +#endif /* Check target-specific constraints. */ #ifndef _BUILDVM_H @@ -478,36 +491,45 @@ #elif LJ_TARGET_ARM #if defined(__ARMEB__) #error "No support for big-endian ARM" +#undef LJ_TARGET_ARM #endif #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__ #error "No support for Cortex-M CPUs" +#undef LJ_TARGET_ARM #endif #if !(__ARM_EABI__ || LJ_TARGET_IOS) #error "Only ARM EABI or iOS 3.0+ ABI is supported" +#undef LJ_TARGET_ARM #endif #elif LJ_TARGET_ARM64 #if defined(_ILP32) #error "No support for ILP32 model on ARM64" +#undef LJ_TARGET_ARM64 #endif #elif LJ_TARGET_PPC #if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN)) #error "No support for little-endian PPC32" +#undef LJ_TARGET_PPC #endif #if defined(__NO_FPRS__) && !defined(_SOFT_FLOAT) -#error "No support for PPC/e500 anymore (use LuaJIT 2.0)" +#error "No support for PPC/e500, use LuaJIT 2.0" +#undef LJ_TARGET_PPC #endif #elif LJ_TARGET_MIPS32 #if !((defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32) || (defined(_ABIO32) && _MIPS_SIM == _ABIO32)) #error "Only o32 ABI supported for MIPS32" +#undef LJ_TARGET_MIPS #endif #if LJ_TARGET_MIPSR6 /* Not that useful, since most available r6 CPUs are 64 bit. */ #error "No support for MIPS32R6" +#undef LJ_TARGET_MIPS #endif #elif LJ_TARGET_MIPS64 #if !((defined(_MIPS_SIM_ABI64) && _MIPS_SIM == _MIPS_SIM_ABI64) || (defined(_ABI64) && _MIPS_SIM == _ABI64)) /* MIPS32ON64 aka n32 ABI support might be desirable, but difficult. */ #error "Only n64 ABI supported for MIPS64" +#undef LJ_TARGET_MIPS #endif #endif #endif @@ -594,6 +616,10 @@ #define LJ_SOFTFP (!LJ_ARCH_HASFPU) #define LJ_SOFTFP32 (LJ_SOFTFP && LJ_32) +#ifndef LJ_ABI_PAUTH +#define LJ_ABI_PAUTH 0 +#endif + #if LJ_ARCH_ENDIAN == LUAJIT_BE #define LJ_LE 0 #define LJ_BE 1 diff --git a/jni/luajava/mobile-nosys.h b/jni/luajava/mobile-nosys.h index 600334f1..373eaa36 100644 --- a/jni/luajava/mobile-nosys.h +++ b/jni/luajava/mobile-nosys.h @@ -1,8 +1,13 @@ #ifndef MOBILE_NOSYS_H #define MOBILE_NOSYS_H +/* Workaround before LuaJIT supports RISC-V */ +#if (defined(__riscv) || defined(__riscv__)) && __riscv_xlen == 64 +#define LJ_TARGET_RISCV64 1 +#else /* Borrowing arch info from LuaJIT */ #include "lj/lj_arch.h" +#endif /* Disabling exception usage */ #define LUA_USE_LONGJMP diff --git a/lua51/build.gradle b/lua51/build.gradle index cdd2e4ce..524dd9dc 100644 --- a/lua51/build.gradle +++ b/lua51/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1' + classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.2' } } @@ -39,14 +39,6 @@ dependencies { apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) { - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -} - jnigen { sharedLibName = 'lua51' @@ -59,16 +51,14 @@ jnigen { add(Windows, x32) add(Windows, x64) - add(Windows, x64, ARM) { - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) - } + add(Windows, x64, ARM) add(Linux, x32) add(Linux, x64) add(Linux, x32, ARM) add(Linux, x64, ARM) + // TODO: Until we have a RISCV toolchain on Ubuntu. + // add(Linux, x64, RISCV) each({ it.os == Linux }) { String linuxFlags = ' -D_FORTIFY_SOURCE=0 -DLUA_USE_DLOPEN ' cFlags += linuxFlags diff --git a/lua52/build.gradle b/lua52/build.gradle index ca7ae193..6497cdc2 100644 --- a/lua52/build.gradle +++ b/lua52/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1' + classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.2' } } @@ -39,14 +39,6 @@ dependencies { apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) { - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -} - jnigen { sharedLibName = 'lua52' @@ -61,16 +53,14 @@ jnigen { add(Windows, x32) add(Windows, x64) - add(Windows, x64, ARM) { - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) - } + add(Windows, x64, ARM) add(Linux, x32) add(Linux, x64) add(Linux, x32, ARM) add(Linux, x64, ARM) + // TODO: Until we have a RISCV toolchain on Ubuntu. + // add(Linux, x64, RISCV) each({ it.os == Linux }) { String linuxFlags = ' -D_FORTIFY_SOURCE=0 -DLUA_USE_DLOPEN ' cFlags += linuxFlags diff --git a/lua53/build.gradle b/lua53/build.gradle index 0a23ba77..d1838889 100644 --- a/lua53/build.gradle +++ b/lua53/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1' + classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.2' } } @@ -39,14 +39,6 @@ dependencies { apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) { - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -} - jnigen { sharedLibName = 'lua53' @@ -61,16 +53,14 @@ jnigen { add(Windows, x32) add(Windows, x64) - add(Windows, x64, ARM) { - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) - } + add(Windows, x64, ARM) add(Linux, x32) add(Linux, x64) add(Linux, x32, ARM) add(Linux, x64, ARM) + // TODO: Until we have a RISCV toolchain on Ubuntu. + // add(Linux, x64, RISCV) each({ it.os == Linux }) { String linuxFlags = ' -D_FORTIFY_SOURCE=0 -DLUA_USE_DLOPEN ' cFlags += linuxFlags diff --git a/lua54/build.gradle b/lua54/build.gradle index 43a12373..662e1302 100644 --- a/lua54/build.gradle +++ b/lua54/build.gradle @@ -4,7 +4,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1' + classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.2' } } @@ -39,14 +39,6 @@ dependencies { apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) { - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -} - jnigen { sharedLibName = 'lua54' @@ -61,16 +53,14 @@ jnigen { add(Windows, x32) add(Windows, x64) - add(Windows, x64, ARM) { - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) - } + add(Windows, x64, ARM) add(Linux, x32) add(Linux, x64) add(Linux, x32, ARM) add(Linux, x64, ARM) + // TODO: Until we have a RISCV toolchain on Ubuntu. + // add(Linux, x64, RISCV) each({ it.os == Linux }) { String linuxFlags = ' -D_FORTIFY_SOURCE=0 -DLUA_USE_DLOPEN ' cFlags += linuxFlags diff --git a/luajava/build.gradle b/luajava/build.gradle index b5027536..28d59109 100644 --- a/luajava/build.gradle +++ b/luajava/build.gradle @@ -13,7 +13,7 @@ version = rootProject.version dependencies { implementation 'org.jetbrains:annotations:24.1.0' - implementation 'com.badlogicgames.gdx:gdx-jnigen-loader:2.5.1' + implementation 'com.badlogicgames.gdx:gdx-jnigen-loader:2.5.2' } tasks.withType(JavaCompile) { diff --git a/luajit/build.gradle b/luajit/build.gradle index 77ce1770..5372c3bf 100644 --- a/luajit/build.gradle +++ b/luajit/build.gradle @@ -7,7 +7,7 @@ buildscript { mavenCentral() } dependencies { - classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.1' + classpath 'com.badlogicgames.gdx:gdx-jnigen-gradle:2.5.2' } } @@ -167,14 +167,6 @@ void linkerConfig(BuildTarget it, Platform platform) { apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) { - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -} - jnigen { sharedLibName = 'luajit' @@ -205,9 +197,6 @@ jnigen { linkerConfig(it, Platform.Win64) }) add(Windows, x64, ARM) { - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) linkerConfig(it, Platform.WinAArch64) } diff --git a/luajit/jni/luajit b/luajit/jni/luajit index 93e87998..ae4735f6 160000 --- a/luajit/jni/luajit +++ b/luajit/jni/luajit @@ -1 +1 @@ -Subproject commit 93e87998b24021b94de8d1c8db244444c46fb6e9 +Subproject commit ae4735f621d89d84758769b76432d2319dda9827 diff --git a/publish.gradle b/publish.gradle index bd820322..2164f928 100644 --- a/publish.gradle +++ b/publish.gradle @@ -47,6 +47,7 @@ configure([ if (project.tasks.findByName('jnigenJarNativesIOS')) { artifact jnigenJarNativesIOS {} } + // TODO: Add riscv64 to the list once Android NDK & jnigen supports RISC-V Android builds. ['arm64-v8a', 'armeabi-v7a', 'x86_64', 'x86'].each { arch -> if (project.tasks.findByName("jnigenJarNativesAndroid$arch")) { artifact "jnigenJarNativesAndroid$arch" {} diff --git a/scripts/jnigen-gradle.py b/scripts/jnigen-gradle.py index ba747057..f34384ca 100644 --- a/scripts/jnigen-gradle.py +++ b/scripts/jnigen-gradle.py @@ -5,7 +5,7 @@ import sys -jnigen_version = "2.5.1" +jnigen_version = "2.5.2" lua_version = sys.argv[1] assert lua_version in ["lua51", "lua52", "lua53", "lua54"] header_dirs = { @@ -15,6 +15,12 @@ "lua54": "'lua54'", } +compat_flags = { + "lua52": "-DLUA_COMPAT_ALL", + "lua53": "-DLUA_COMPAT_5_2", + "lua54": "-DLUA_COMPAT_5_3", +} + script = f"""\ buildscript {{ repositories {{ @@ -57,18 +63,12 @@ apply plugin: 'com.badlogicgames.gdx.gdx-jnigen' -static def removeNonArmFlags(String s) {{ - // TODO: Until https://github.com/libgdx/gdx-jnigen/pull/56 gets released - return s - .replace("-mfpmath=sse -msse2", "") - .replace("-m32", "") - .replace("-m64", "") -}} - jnigen {{ sharedLibName = '{lua_version}' - all {{ + all {{{'' if lua_version not in compat_flags else f''' + cFlags += ' {compat_flags[lua_version]}' + cppFlags += ' {compat_flags[lua_version]}\''''} headerDirs = ['../../jni/luajava', 'mod', {header_dirs[lua_version]}] cppExcludes = ['{lua_version}/**/*'] cExcludes = ['{lua_version}/**/*'] @@ -77,16 +77,14 @@ add(Windows, x32) add(Windows, x64) - add(Windows, x64, ARM) {{ - cFlags = removeNonArmFlags(cFlags) - cppFlags = removeNonArmFlags(cppFlags) - linkerFlags = removeNonArmFlags(linkerFlags) - }} + add(Windows, x64, ARM) add(Linux, x32) add(Linux, x64) add(Linux, x32, ARM) add(Linux, x64, ARM) + // TODO: Until we have a RISCV toolchain on Ubuntu. + // add(Linux, x64, RISCV) each({{ it.os == Linux }}) {{ String linuxFlags = ' -D_FORTIFY_SOURCE=0 -DLUA_USE_DLOPEN ' cFlags += linuxFlags