Skip to content

Commit 99e8138

Browse files
committed
Clean up Kotlin/JVM bindings generation script
Previously, the targets built by the script was dependent on the platform on which it was run, also delegating some of the logic to the CI publishing scripts. Here, we make the built targets explicit (aarch64 and x86_64 on macOS/darwin and x86_64 on Linux) and copy the artifacts over to their respective ressource locations.
1 parent 77acd3b commit 99e8138

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

scripts/uniffi_bindgen_generate_kotlin.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,30 @@ PROJECT_DIR="ldk-node-jvm"
55
PACKAGE_DIR="org/lightningdevkit/ldknode"
66
UNIFFI_BINDGEN_BIN="cargo run --features=uniffi/cli --bin uniffi-bindgen"
77

8-
DYNAMIC_LIB_PATH="target/release/libldk_node.dylib"
98
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
10-
DYNAMIC_LIB_PATH="target/release/libldk_node.so"
11-
fi
9+
rustup target add x86_64-unknown-linux-gnu || exit 1
10+
cargo build --release --target x86_64-unknown-linux-gnu --features uniffi || exit 1
11+
DYNAMIC_LIB_PATH="target/x86_64-unknown-linux-gnu/release/libldk_node.so"
12+
RES_DIR="$BINDINGS_DIR/$PROJECT_DIR/lib/src/main/resources/linux-x86-64/"
13+
mkdir -p $RES_DIR || exit 1
14+
cp $DYNAMIC_LIB_PATH $RES_DIR || exit 1
15+
else
16+
rustup target add x86_64-apple-darwin || exit 1
17+
cargo build --release --target x86_64-apple-darwin --features uniffi || exit 1
18+
DYNAMIC_LIB_PATH="target/x86_64-apple-darwin/release/libldk_node.dylib"
19+
RES_DIR="$BINDINGS_DIR/$PROJECT_DIR/lib/src/main/resources/darwin-x86-64/"
20+
mkdir -p $RES_DIR || exit 1
21+
cp $DYNAMIC_LIB_PATH $RES_DIR || exit 1
1222

13-
#rustup target add aarch64-apple-darwin
14-
#cargo build --target aarch64-apple-darwin || exit 1
15-
cargo build --release --features uniffi || exit 1
16-
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --language kotlin -o "$TARGET_DIR" || exit 1
23+
rustup target add aarch64-apple-darwin || exit 1
24+
cargo build --release --target aarch64-apple-darwin --features uniffi || exit 1
25+
DYNAMIC_LIB_PATH="target/aarch64-apple-darwin/release/libldk_node.dylib"
26+
RES_DIR="$BINDINGS_DIR/$PROJECT_DIR/lib/src/main/resources/darwin-aarch64/"
27+
mkdir -p $RES_DIR || exit 1
28+
cp $DYNAMIC_LIB_PATH $RES_DIR || exit 1
29+
fi
1730

1831
mkdir -p "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin/"$PACKAGE_DIR" || exit 1
19-
mkdir -p "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/darwin-aarch64/ || exit 1
32+
$UNIFFI_BINDGEN_BIN generate bindings/ldk_node.udl --language kotlin -o "$TARGET_DIR" || exit 1
2033

2134
cp "$TARGET_DIR"/"$PACKAGE_DIR"/ldk_node.kt "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/kotlin/"$PACKAGE_DIR"/ || exit 1
22-
#cp ./target/aarch64-apple-darwin/debug/libldk_node.dylib "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/darwin-aarch64/libldk_node.dylib || exit 1
23-
cp $DYNAMIC_LIB_PATH "$BINDINGS_DIR"/"$PROJECT_DIR"/lib/src/main/resources/libldk_node.dylib || exit 1

0 commit comments

Comments
 (0)