Pass the target tuple to genbindings.py and avoid sys.platform
authorMatt Corallo <git@bluematt.me>
Sat, 3 Jun 2023 02:43:24 +0000 (02:43 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 4 Jun 2023 04:50:22 +0000 (04:50 +0000)
genbindings.py
genbindings.sh
java_strings.py

index e5a59700352c6f0c1cdff2de3546783770396ee8..28b0e7e7b62c5d412e31ac345796f4149a0c0f0c 100755 (executable)
@@ -1,8 +1,8 @@
 #!/usr/bin/env python3
 import os, sys, re, subprocess
 
-if len(sys.argv) < 7:
-    print("USAGE: /path/to/lightning.h /path/to/bindings/output /path/to/bindings/ /path/to/bindings/output.c debug lang")
+if len(sys.argv) < 8:
+    print("USAGE: /path/to/lightning.h /path/to/bindings/output /path/to/bindings/ /path/to/bindings/output.c debug lang target-tuple")
     sys.exit(1)
 
 if sys.argv[5] == "false":
@@ -20,6 +20,8 @@ if sys.argv[6] == "java" or sys.argv[6] == "android":
     target = java_strings.Target.JAVA
     if sys.argv[6] == "android":
         target = java_strings.Target.ANDROID
+    if "apple" in sys.argv[8]:
+        target = java_strings.Target.MACOS
 elif sys.argv[6] == "typescript":
     import typescript_strings
     from typescript_strings import Consts
@@ -38,7 +40,6 @@ else:
     print("Only java, typescript, python, or c_sharp can be set for lang")
     sys.exit(1)
 
-
 consts = Consts(DEBUG, target=target, outdir=sys.argv[4])
 
 local_git_version = os.getenv("LDK_GARBAGECOLLECTED_GIT_OVERRIDE")
index 5520c3a0c0f1a6a49fd35e1255aa0b726cc73914..2f316030e61e211c960e099ad162fb146e481037 100755 (executable)
@@ -87,7 +87,7 @@ if [ "$2" = "c_sharp" ]; then
        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
-       ./genbindings.py "./lightning.h" c_sharp/src/org/ldk/impl c_sharp/src/org/ldk c_sharp/ $DEBUG_ARG c_sharp $4
+       ./genbindings.py "./lightning.h" c_sharp/src/org/ldk/impl c_sharp/src/org/ldk c_sharp/ $DEBUG_ARG c_sharp $4 $TARGET_STRING
        rm -f c_sharp/bindings.c
        if [ "$3" = "true" ]; then
                echo "#define LDK_DEBUG_BUILD" > c_sharp/bindings.c
@@ -136,7 +136,7 @@ elif [ "$2" = "python" ]; then
        echo "Creating Python bindings..."
        mkdir -p python/src/{enums,structs,impl}
        rm -f python/src/{enums,structs,impl}/*.py
-       ./genbindings.py "./lightning.h" python/src/impl python/src python/ $DEBUG_ARG python $4
+       ./genbindings.py "./lightning.h" python/src/impl python/src python/ $DEBUG_ARG python $4 $TARGET_STRING
        rm -f python/bindings.c
        if [ "$3" = "true" ]; then
                echo "#define LDK_DEBUG_BUILD" > python/bindings.c
@@ -176,9 +176,9 @@ elif [ "$2" = "wasm" ]; then
        mkdir -p ts/{enums,structs}
        rm -f ts/{enums,structs,}/*.{mjs,mts,mts.part}
        if [ "$4" = "false" ]; then
-               ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript node
+               ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript node wasm
        else
-               ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript browser
+               ./genbindings.py "./lightning.h" ts ts ts $DEBUG_ARG typescript browser wasm
        fi
        rm -f ts/bindings.c
        sed -i 's/^  "version": .*/  "version": "'${LDK_GARBAGECOLLECTED_GIT_OVERRIDE:1:100}'",/g' ts/package.json
@@ -244,9 +244,9 @@ else
        rm -f src/main/java/org/ldk/{enums,structs}/*.java
        rm -f src/main/jni/*.h
        if [ "$4" = "true" ]; then
-               ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG android $4
+               ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG android $4 $TARGET_STRING
        else
-               ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG java $4
+               ./genbindings.py "./lightning.h" src/main/java/org/ldk/impl src/main/java/org/ldk src/main/jni/ $DEBUG_ARG java $4 $TARGET_STRING
        fi
        rm -f src/main/jni/bindings.c
        if [ "$3" = "true" ]; then
index 1f8ef1a3886cbcf9c3eb1940ca12198f8ff69f52..f5df004d80d3dd709c54366165a712ceb461337e 100644 (file)
@@ -5,6 +5,7 @@ import sys
 class Target(Enum):
     JAVA = 1,
     ANDROID = 2
+    MACOS = 3
 
 class Consts:
     def __init__(self, DEBUG: bool, target: Target, **kwargs):
@@ -193,7 +194,7 @@ void __attribute__((constructor)) spawn_stderr_redirection() {
         else:
             self.c_file_pfx = self.c_file_pfx + "#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)\n"
 
-        if not DEBUG or sys.platform == "darwin":
+        if not DEBUG or self.target == Target.MACOS:
             self.c_file_pfx = self.c_file_pfx + """#define MALLOC(a, _) malloc(a)
 #define FREE(p) if ((uint64_t)(p) > 4096) { free(p); }
 #define CHECK_ACCESS(p)
@@ -218,7 +219,7 @@ void __attribute__((constructor)) debug_log_version() {
 }
 """
 
-            if sys.platform != "darwin":
+            if self.target != Target.MACOS:
                 self.c_file_pfx += """
 // Running a leak check across all the allocations and frees of the JDK is a mess,
 // so instead we implement our own naive leak checker here, relying on the -wrap