From 26ac90da96400ec87974721ea1f1a1fcaf6f051d Mon Sep 17 00:00:00 2001 From: Stefan Bratanov Date: Tue, 29 Nov 2022 10:56:31 +0000 Subject: [PATCH] Add cross compile parameterization for the java binding --- bindings/java/Makefile | 9 +++++++-- .../src/main/java/ethereum/ckzg4844/CKzg4844JNI.java | 2 +- .../resources/{ethereum/ckzg4844/lib => }/.gitignore | 0 3 files changed, 8 insertions(+), 3 deletions(-) rename bindings/java/src/main/resources/{ethereum/ckzg4844/lib => }/.gitignore (100%) diff --git a/bindings/java/Makefile b/bindings/java/Makefile index 005a8a2..a04199e 100644 --- a/bindings/java/Makefile +++ b/bindings/java/Makefile @@ -2,11 +2,14 @@ INCLUDE_DIRS = ../../src ../../blst/bindings LIBRARY_FOLDER=src/main/resources/ethereum/ckzg4844/lib +CC_FLAGS= + ifeq ($(OS),Windows_NT) CLANG_EXECUTABLE=clang GRADLE_COMMAND=gradlew CLANG_FLAGS=-shared JNI_INCLUDE_FOLDER=win32 + OS_ARCH=amd64 LIBRARY_RESOURCE=ckzg4844jni.dll else CLANG_EXECUTABLE=clang @@ -15,6 +18,7 @@ else ifeq ($(UNAME_S),Linux) CLANG_FLAGS=-fPIC -shared JNI_INCLUDE_FOLDER=linux + OS_ARCH=amd64 LIBRARY_RESOURCE=libckzg4844jni.so endif ifeq ($(UNAME_S),Darwin) @@ -23,6 +27,7 @@ else endif CLANG_FLAGS=-dynamiclib JNI_INCLUDE_FOLDER=darwin + OS_ARCH=x86_64 LIBRARY_RESOURCE=libckzg4844jni.dylib endif endif @@ -34,8 +39,8 @@ endif all: build test build: - mkdir -p ${LIBRARY_FOLDER} - ${CLANG_EXECUTABLE} ${CLANG_FLAGS} -O -Wall ${addprefix -I,${INCLUDE_DIRS}} -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/${JNI_INCLUDE_FOLDER}" -o ${LIBRARY_FOLDER}/${LIBRARY_RESOURCE} c_kzg_4844_jni.c c_kzg_4844.o ../../lib/libblst.a + mkdir -p ${LIBRARY_FOLDER}/${OS_ARCH} + ${CLANG_EXECUTABLE} ${CC_FLAGS} ${CLANG_FLAGS} -O -Wall ${addprefix -I,${INCLUDE_DIRS}} -I"${JAVA_HOME}/include" -I"${JAVA_HOME}/include/${JNI_INCLUDE_FOLDER}" -o ${LIBRARY_FOLDER}/${OS_ARCH}/${LIBRARY_RESOURCE} c_kzg_4844_jni.c c_kzg_4844.o ../../lib/libblst.a test: ${GRADLE_COMMAND} clean test diff --git a/bindings/java/src/main/java/ethereum/ckzg4844/CKzg4844JNI.java b/bindings/java/src/main/java/ethereum/ckzg4844/CKzg4844JNI.java index 3db9bbe..c56ac17 100644 --- a/bindings/java/src/main/java/ethereum/ckzg4844/CKzg4844JNI.java +++ b/bindings/java/src/main/java/ethereum/ckzg4844/CKzg4844JNI.java @@ -13,7 +13,7 @@ public class CKzg4844JNI { static { InputStream libraryResource = CKzg4844JNI.class.getResourceAsStream( - "lib/" + PLATFORM_NATIVE_LIBRARY_NAME); + "lib/" + System.getProperty("os.arch") + "/" + PLATFORM_NATIVE_LIBRARY_NAME); if (libraryResource == null) { try { System.loadLibrary(LIBRARY_NAME); diff --git a/bindings/java/src/main/resources/ethereum/ckzg4844/lib/.gitignore b/bindings/java/src/main/resources/.gitignore similarity index 100% rename from bindings/java/src/main/resources/ethereum/ckzg4844/lib/.gitignore rename to bindings/java/src/main/resources/.gitignore