From 3a496e16c89d9193d4da3ad4fb93ffbe32a9fdb2 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 3 Jun 2023 02:43:24 +0000 Subject: [PATCH] Pass the target tuple to genbindings.py and avoid sys.platform --- genbindings.py | 7 ++++--- genbindings.sh | 12 ++++++------ java_strings.py | 5 +++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/genbindings.py b/genbindings.py index e5a59700..28b0e7e7 100755 --- a/genbindings.py +++ b/genbindings.py @@ -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") diff --git a/genbindings.sh b/genbindings.sh index 5520c3a0..2f316030 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -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 diff --git a/java_strings.py b/java_strings.py index 1f8ef1a3..f5df004d 100644 --- a/java_strings.py +++ b/java_strings.py @@ -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 -- 2.30.2