Compile For ARM
Some checks failed
ScriptCraft/pipeline/head There was a failure building this commit

This commit is contained in:
TheBrokenRail 2020-04-25 13:25:37 -04:00
parent 8fd4fdd51e
commit 35e1157df9
13 changed files with 89 additions and 25 deletions

View File

@ -1,4 +1,9 @@
FROM alpine:latest FROM ubuntu:bionic
RUN apt-get update && apt-get install --no-install-recommends -y curl openjdk-11-jdk-headless cmake make gcc gcc-multilib-i686-linux-gnu gcc-multilib-arm-linux-gnueabihf gcc-aarch64-linux-gnu clang lld mingw-w64 lsb-release
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt-get install --no-install-recommends -y nodejs
RUN apt-get clean
RUN apk add --no-cache curl openjdk8 npm cmake make clang binutils mingw-w64-gcc
RUN npm install -g typescript typedoc RUN npm install -g typescript typedoc

View File

@ -10,20 +10,25 @@ class JNIPlatform {
String[] cmakeArgs String[] cmakeArgs
String libExtension String libExtension
JNIPlatform(String name, String[] cmakeArgs, String libExtension) { JNIPlatform(String name, String libExtension, File rootDir) {
this.name = name this.name = name
this.cmakeArgs = cmakeArgs this.cmakeArgs = ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/${name}-toolchain.cmake"] as String[]
this.libExtension = libExtension this.libExtension = libExtension
} }
} }
JNIPlatform[] jniPlatforms = [ JNIPlatform[] jniPlatforms = [
new JNIPlatform("linux-x86_64", [] as String[], ".so"), new JNIPlatform("linux-x86_64", ".so", rootDir),
new JNIPlatform("linux-i686", ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/linux_i686_toolchain.cmake"] as String[], ".so"), new JNIPlatform("linux-x86", ".so", rootDir),
new JNIPlatform("windows-x86_64", ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/windows_x86_64_toolchain.cmake"] as String[], ".dll"), new JNIPlatform("linux-armhf", ".so", rootDir),
new JNIPlatform("windows-i686", ["-DCMAKE_TOOLCHAIN_FILE=${rootDir.absolutePath}/cmake/windows_i686_toolchain.cmake"] as String[], ".dll") new JNIPlatform("linux-arm64", ".so", rootDir),
new JNIPlatform("windows-x86_64", ".dll", rootDir),
new JNIPlatform("windows-x86", ".dll", rootDir)
] ]
task cleanJNI {}
task compileJNI {}
for (JNIPlatform platform : jniPlatforms) { for (JNIPlatform platform : jniPlatforms) {
def buildDir = new File(cDir, "build-${platform.name}") def buildDir = new File(cDir, "build-${platform.name}")
if (!buildDir.exists()) { if (!buildDir.exists()) {
@ -45,15 +50,18 @@ for (JNIPlatform platform : jniPlatforms) {
dependsOn tasks.getByName("cmake-${platform.name}") dependsOn tasks.getByName("cmake-${platform.name}")
} }
processResources.dependsOn tasks.getByName("compileJNI-${platform.name}") compileJNI.dependsOn tasks.getByName("compileJNI-${platform.name}")
tasks.create(name: "cleanJNI-${platform.name}", type: Delete) { tasks.create(name: "cleanJNI-${platform.name}", type: Delete) {
delete buildDir.absolutePath delete buildDir.absolutePath
} }
clean.dependsOn tasks.getByName("cleanJNI-${platform.name}") cleanJNI.dependsOn tasks.getByName("cleanJNI-${platform.name}")
} }
clean.dependsOn cleanJNI
processResources.dependsOn compileJNI
compileJava { compileJava {
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8

View File

@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(BUILD_TARGET "aarch64-linux-gnu")
set(CMAKE_SYSROOT "/usr/${BUILD_TARGET}")
set(CMAKE_C_COMPILER clang)
add_compile_options(-target ${BUILD_TARGET})
add_link_options(-fuse-ld=lld -target ${BUILD_TARGET})

View File

@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(BUILD_TARGET "arm-linux-gnueabihf")
set(CMAKE_SYSROOT "/usr/${BUILD_TARGET}")
set(CMAKE_C_COMPILER clang)
add_compile_options(-target ${BUILD_TARGET})
add_link_options(-fuse-ld=lld -target ${BUILD_TARGET})

View File

@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)
set(BUILD_TARGET "i686-linux-gnu")
set(CMAKE_SYSROOT "/usr/${BUILD_TARGET}")
set(CMAKE_C_COMPILER clang)
add_compile_options(-target ${BUILD_TARGET})
add_link_options(-fuse-ld=lld -target ${BUILD_TARGET})

View File

@ -0,0 +1,10 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
if(NOT CMAKE_SYSTEM_PROCESSOR STREQUAL CMAKE_HOST_SYSTEM_PROCESSOR)
message(FATAL_ERROR "Host System is not x86_64")
endif()
set(CMAKE_C_COMPILER clang)
add_link_options(-fuse-ld=lld)

View File

@ -1,7 +0,0 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)
set(CMAKE_C_FLAGS "-m32 -march=i686")
set(CMAKE_CXX_FLAGS "-m32 -march=i686")
set(CMAKE_EXE_LINKER_FLAGS "-m32 -march=i686")

View File

@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.10)
project(scriptcraft C) project(scriptcraft C)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast") add_compile_options(-Wall -Werror -Wno-implicit-int-float-conversion -Wno-int-to-pointer-cast -Wno-pointer-to-int-cast -Wno-sign-compare -Wno-missing-field-initializers -Wundef -Wuninitialized -Wunused -Wno-unused-parameter -Wwrite-strings -Wchar-subscripts -funsigned-char)
add_library( add_library(
scriptcraft scriptcraft

View File

@ -11,13 +11,13 @@
static JavaVM *jvm; static JavaVM *jvm;
static void *get_pointer(JNIEnv *env, jobject obj, char *name) { static void *get_pointer(JNIEnv *env, jobject obj, const char *name) {
jclass clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/QuickJS"); jclass clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/QuickJS");
jfieldID field = (*env)->GetFieldID(env, clazz, name, "J"); jfieldID field = (*env)->GetFieldID(env, clazz, name, "J");
return (void *) (long) (*env)->GetLongField(env, obj, field); return (void *) (long) (*env)->GetLongField(env, obj, field);
} }
static void set_pointer(JNIEnv *env, jobject obj, char *name, void *value) { static void set_pointer(JNIEnv *env, jobject obj, const char *name, void *value) {
jclass clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/QuickJS"); jclass clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/QuickJS");
jfieldID field = (*env)->GetFieldID(env, clazz, name, "J"); jfieldID field = (*env)->GetFieldID(env, clazz, name, "J");
(*env)->SetLongField(env, obj, field, (jlong) (long) value); (*env)->SetLongField(env, obj, field, (jlong) (long) value);
@ -163,7 +163,7 @@ static JSModuleDef *js_module_loader(JSContext *ctx, const char *module_name, vo
return m; return m;
} }
static void throw_exception(JNIEnv *env, char *message) { static void throw_exception(JNIEnv *env, const char *message) {
jclass exception_clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/JSException"); jclass exception_clazz = (*env)->FindClass(env, "com/thebrokenrail/scriptcraft/quickjs/JSException");
(*env)->ThrowNew(env, exception_clazz, message); (*env)->ThrowNew(env, exception_clazz, message);
} }

View File

@ -10,9 +10,9 @@ static JSValue js_print_internal(JSContext *ctx, JSValueConst this_val, int argc
int i; int i;
char *out; char *out;
if (prepend_throw) { if (prepend_throw) {
out = "Throw: "; out = (char *) "Throw: ";
} else { } else {
out = ""; out = (char *) "";
} }
const char *str; const char *str;
@ -53,7 +53,7 @@ static JSValue js_assert(JSContext *ctx, JSValueConst this_val, int argc, JSValu
} }
if (!bool_val) { if (!bool_val) {
char *out = "Assertion failed"; char *out = (char *) "Assertion failed";
for (i = 1; i < argc; i++) { for (i = 1; i < argc; i++) {
if (i != 1) { if (i != 1) {
asprintf(&out, "%s ", out); asprintf(&out, "%s ", out);

View File

@ -21,14 +21,26 @@ public class OSUtil {
String arch; String arch;
switch (raw) { switch (raw) {
case "x86": case "x86":
case "i386":
case "i686": { case "i686": {
arch = "i686"; arch = "x86";
break; break;
} }
case "amd64": { case "amd64": {
arch = "x86_64"; arch = "x86_64";
break; break;
} }
case "arm": {
arch = "armhf";
break;
}
case "aarch64_be":
case "armv8b":
case "armv8l":
case "aarch64": {
arch = "arm64";
break;
}
default: { default: {
arch = "other"; arch = "other";
break; break;