From 11b00bd9ea7e79f1c22db45f86f4776165fdc68f Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 2 Jun 2023 22:05:11 +0000 Subject: [PATCH] [Java] Support building for OSX on Linux --- genbindings.sh | 131 ++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 90 deletions(-) diff --git a/genbindings.sh b/genbindings.sh index e2952f73..5520c3a0 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -20,13 +20,47 @@ function is_gnu_sed(){ sed --version >/dev/null 2>&1 } -if [ "$CC" != "" ]; then - COMMON_COMPILE="$CC -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-unused-function -Wno-nullability-completeness -Wno-pointer-sign -Wdate-time -ffile-prefix-map=$(pwd)=" -else +if [ "$CC" = "" ]; then CC=clang - COMMON_COMPILE="clang -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-unused-function -Wno-nullability-completeness -Wno-pointer-sign -Wdate-time -ffile-prefix-map=$(pwd)=" fi +TARGET_STRING="$LDK_TARGET" +if [ "$TARGET_STRING" = "" ]; then + # We assume clang-style $CC --version here, but worst-case we just get an empty suffix + TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')" +fi + +IS_MAC=false +[ "$($CC --version | grep apple-darwin)" != "" ] && IS_MAC=true +IS_APPLE_CLANG=false +[ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true + +case "$TARGET_STRING" in + "x86_64-pc-linux"*) + LDK_TARGET_SUFFIX="_Linux-amd64" + LDK_JAR_TARGET=true + ;; + "x86_64-apple-darwin"*) + LDK_TARGET_SUFFIX="_MacOSX-x86_64" + LDK_JAR_TARGET=true + IS_MAC=true + ;; + "aarch64-apple-darwin"*) + LDK_TARGET_CPU="apple-a14" + LDK_TARGET_SUFFIX="_MacOSX-aarch64" + LDK_JAR_TARGET=true + IS_MAC=true + ;; + *) + LDK_TARGET_SUFFIX="_${TARGET_STRING}" +esac +if [ "$LDK_TARGET_CPU" = "" ]; then + LDK_TARGET_CPU="sandybridge" +fi + +COMMON_COMPILE="$CC -std=c11 -Wall -Wextra -Wno-unused-parameter -Wno-ignored-qualifiers -Wno-unused-function -Wno-nullability-completeness -Wno-pointer-sign -Wdate-time -ffile-prefix-map=$(pwd)=" +[ "$IS_MAC" = "true" -a "$2" != "wasm" ] && COMMON_COMPILE="$COMMON_COMPILE --target=$TARGET_STRING -mcpu=$LDK_TARGET_CPU" + DEBUG_ARG="$3" if [ "$3" = "leaks" ]; then DEBUG_ARG="true" @@ -50,32 +84,6 @@ fi if [ "$2" = "c_sharp" ]; then - TARGET_STRING="$LDK_TARGET" - if [ "$TARGET_STRING" = "" ]; then - # We assume clang-style $CC --version here, but worst-case we just get an empty suffix - TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')" - fi - case "$TARGET_STRING" in - "x86_64-pc-linux"*) - LDK_TARGET_SUFFIX="_Linux-amd64" - LDK_JAR_TARGET=true - ;; - "x86_64-apple-darwin"*) - LDK_TARGET_SUFFIX="_MacOSX-x86_64" - LDK_JAR_TARGET=true - ;; - "aarch64-apple-darwin"*) - LDK_TARGET_CPU="apple-a14" - LDK_TARGET_SUFFIX="_MacOSX-aarch64" - LDK_JAR_TARGET=true - ;; - *) - LDK_TARGET_SUFFIX="_${TARGET_STRING}" - esac - if [ "$LDK_TARGET_CPU" = "" ]; then - LDK_TARGET_CPU="sandybridge" - fi - echo "Creating C# bindings..." mkdir -p c_sharp/src/org/ldk/{enums,structs,impl} rm -f c_sharp/src/org/ldk/{enums,structs,impl}/*.cs @@ -108,7 +116,7 @@ if [ "$2" = "c_sharp" ]; then mv ./-out:csharpldk.dll csharpldk.dll # Mono is braindead, apparently echo "Building C# bindings..." - COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC" + COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -fPIC" LINK="-ldl -shared" [ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined" [ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9" @@ -125,32 +133,6 @@ if [ "$2" = "c_sharp" ]; then llvm-strip liblightningjni_release$LDK_TARGET_SUFFIX.so fi elif [ "$2" = "python" ]; then - TARGET_STRING="$LDK_TARGET" - if [ "$TARGET_STRING" = "" ]; then - # We assume clang-style $CC --version here, but worst-case we just get an empty suffix - TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')" - fi - case "$TARGET_STRING" in - "x86_64-pc-linux"*) - LDK_TARGET_SUFFIX="_Linux-amd64" - LDK_JAR_TARGET=true - ;; - "x86_64-apple-darwin"*) - LDK_TARGET_SUFFIX="_MacOSX-x86_64" - LDK_JAR_TARGET=true - ;; - "aarch64-apple-darwin"*) - LDK_TARGET_CPU="apple-a14" - LDK_TARGET_SUFFIX="_MacOSX-aarch64" - LDK_JAR_TARGET=true - ;; - *) - LDK_TARGET_SUFFIX="_${TARGET_STRING}" - esac - if [ "$LDK_TARGET_CPU" = "" ]; then - LDK_TARGET_CPU="sandybridge" - fi - echo "Creating Python bindings..." mkdir -p python/src/{enums,structs,impl} rm -f python/src/{enums,structs,impl}/*.py @@ -173,7 +155,7 @@ elif [ "$2" = "python" ]; then [ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true echo "Building Python bindings..." - COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC" + COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -fPIC" LINK="-ldl -shared" [ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined" [ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9" @@ -250,32 +232,6 @@ elif [ "$2" = "wasm" ]; then fi fi else - TARGET_STRING="$LDK_TARGET" - if [ "$TARGET_STRING" = "" ]; then - # We assume clang-style $CC --version here, but worst-case we just get an empty suffix - TARGET_STRING="$($CC --version | grep Target | awk '{ print $2 }')" - fi - case "$TARGET_STRING" in - "x86_64-pc-linux"*) - LDK_TARGET_SUFFIX="_Linux-amd64" - LDK_JAR_TARGET=true - ;; - "x86_64-apple-darwin"*) - LDK_TARGET_SUFFIX="_MacOSX-x86_64" - LDK_JAR_TARGET=true - ;; - "aarch64-apple-darwin"*) - LDK_TARGET_CPU="apple-a14" - LDK_TARGET_SUFFIX="_MacOSX-aarch64" - LDK_JAR_TARGET=true - ;; - *) - LDK_TARGET_SUFFIX="_${TARGET_STRING}" - esac - if [ "$LDK_TARGET_CPU" = "" ]; then - LDK_TARGET_CPU="sandybridge" - fi - if is_gnu_sed; then sed -i "s/^ .*<\/version>/ ${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}<\/version>/g" pom.xml else @@ -306,13 +262,8 @@ else javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/*.java rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class - IS_MAC=false - [ "$($CC --version | grep apple-darwin)" != "" ] && IS_MAC=true - IS_APPLE_CLANG=false - [ "$($CC --version | grep "Apple clang version")" != "" ] && IS_APPLE_CLANG=true - echo "Building Java bindings..." - COMPILE="$COMMON_COMPILE -mcpu=$LDK_TARGET_CPU -Isrc/main/jni -pthread -fPIC" + COMPILE="$COMMON_COMPILE -Isrc/main/jni -pthread -fPIC" LINK="-ldl -shared" [ "$IS_MAC" = "false" ] && LINK="$LINK -Wl,--no-undefined" [ "$IS_MAC" = "true" ] && COMPILE="$COMPILE -mmacosx-version-min=10.9" -- 2.39.5