Add cross compile parameterization for the java binding

This commit is contained in:
Stefan Bratanov 2022-11-29 10:56:31 +00:00
parent 12df969a26
commit 26ac90da96
3 changed files with 8 additions and 3 deletions

View File

@ -2,11 +2,14 @@ INCLUDE_DIRS = ../../src ../../blst/bindings
LIBRARY_FOLDER=src/main/resources/ethereum/ckzg4844/lib LIBRARY_FOLDER=src/main/resources/ethereum/ckzg4844/lib
CC_FLAGS=
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
CLANG_EXECUTABLE=clang CLANG_EXECUTABLE=clang
GRADLE_COMMAND=gradlew GRADLE_COMMAND=gradlew
CLANG_FLAGS=-shared CLANG_FLAGS=-shared
JNI_INCLUDE_FOLDER=win32 JNI_INCLUDE_FOLDER=win32
OS_ARCH=amd64
LIBRARY_RESOURCE=ckzg4844jni.dll LIBRARY_RESOURCE=ckzg4844jni.dll
else else
CLANG_EXECUTABLE=clang CLANG_EXECUTABLE=clang
@ -15,6 +18,7 @@ else
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
CLANG_FLAGS=-fPIC -shared CLANG_FLAGS=-fPIC -shared
JNI_INCLUDE_FOLDER=linux JNI_INCLUDE_FOLDER=linux
OS_ARCH=amd64
LIBRARY_RESOURCE=libckzg4844jni.so LIBRARY_RESOURCE=libckzg4844jni.so
endif endif
ifeq ($(UNAME_S),Darwin) ifeq ($(UNAME_S),Darwin)
@ -23,6 +27,7 @@ else
endif endif
CLANG_FLAGS=-dynamiclib CLANG_FLAGS=-dynamiclib
JNI_INCLUDE_FOLDER=darwin JNI_INCLUDE_FOLDER=darwin
OS_ARCH=x86_64
LIBRARY_RESOURCE=libckzg4844jni.dylib LIBRARY_RESOURCE=libckzg4844jni.dylib
endif endif
endif endif
@ -34,8 +39,8 @@ endif
all: build test all: build test
build: build:
mkdir -p ${LIBRARY_FOLDER} mkdir -p ${LIBRARY_FOLDER}/${OS_ARCH}
${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 ${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: test:
${GRADLE_COMMAND} clean test ${GRADLE_COMMAND} clean test

View File

@ -13,7 +13,7 @@ public class CKzg4844JNI {
static { static {
InputStream libraryResource = CKzg4844JNI.class.getResourceAsStream( InputStream libraryResource = CKzg4844JNI.class.getResourceAsStream(
"lib/" + PLATFORM_NATIVE_LIBRARY_NAME); "lib/" + System.getProperty("os.arch") + "/" + PLATFORM_NATIVE_LIBRARY_NAME);
if (libraryResource == null) { if (libraryResource == null) {
try { try {
System.loadLibrary(LIBRARY_NAME); System.loadLibrary(LIBRARY_NAME);