#!/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":
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
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")
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
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
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
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
class Target(Enum):
JAVA = 1,
ANDROID = 2
+ MACOS = 3
class Consts:
def __init__(self, DEBUG: bool, target: Target, **kwargs):
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)
}
"""
- 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