Skip to content

Commit

Permalink
fix: ndk r27 attempts to build for riscv
Browse files Browse the repository at this point in the history
  • Loading branch information
gudzpoz committed Aug 16, 2024
1 parent 8c54f58 commit 1048aac
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 103 deletions.
31 changes: 20 additions & 11 deletions .github/workflows/build-natives.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion jni/luajava/jua.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <stdlib.h>

#include "lj/lj_arch.h"
#include "mobile-nosys.h"
#if LJ_TARGET_DLOPEN
#include <dlfcn.h>
int reopenAsGlobal(const char * file) {
Expand Down
38 changes: 32 additions & 6 deletions jni/luajava/lj/lj_arch.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions jni/luajava/mobile-nosys.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 4 additions & 14 deletions lua51/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down Expand Up @@ -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'

Expand All @@ -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
Expand Down
18 changes: 4 additions & 14 deletions lua52/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down Expand Up @@ -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'

Expand All @@ -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
Expand Down
18 changes: 4 additions & 14 deletions lua53/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}

Expand Down Expand Up @@ -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'

Expand All @@ -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
Expand Down
Loading

0 comments on commit 1048aac

Please sign in to comment.