From 7b0f233251dd5c452794b54e8e14c5f188c14697 Mon Sep 17 00:00:00 2001 From: Roman Dmitrienko Date: Wed, 28 Feb 2024 22:52:56 +0100 Subject: [PATCH 1/2] Add the Go bindings build script. --- scripts/uniffi_bindgen_generate_go.sh | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 scripts/uniffi_bindgen_generate_go.sh diff --git a/scripts/uniffi_bindgen_generate_go.sh b/scripts/uniffi_bindgen_generate_go.sh new file mode 100755 index 000000000..60f28f8ab --- /dev/null +++ b/scripts/uniffi_bindgen_generate_go.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -e + +uniffi-bindgen-go bindings/ldk_node.udl -o ffi/golang -c ./uniffi.toml + +build_lib() { + local TOOL=$1 + local TARGET=$2 + local OUTPUT_FILE=$3 + + $TOOL build --release --target $TARGET --features uniffi || exit 1 + mkdir -p "ffi/golang/ldk_node/$TARGET" || exit 1 + cp "target/$TARGET/release/$OUTPUT_FILE" "ffi/golang/ldk_node/$TARGET/" || exit 1 +} + +is_target_installed() { + local TARGET=$1 + rustup target list --installed | grep -q $TARGET +} + +# If we're running on macOS, build the macOS library using the host compiler. +# Cross compilation is not supported (needs more complex setup). +if [[ "$OSTYPE" == "darwin"* ]]; then + build_lib "cargo" "aarch64-apple-darwin" "libldk_node.dylib" +fi + +build_lib "cross" "x86_64-unknown-linux-gnu" "libldk_node.so" +build_lib "cross" "x86_64-pc-windows-gnu" "ldk_node.dll" From c10b391c33a70cac5939241790075f456e79b3dc Mon Sep 17 00:00:00 2001 From: Roman Dmitrienko Date: Fri, 1 Mar 2024 21:42:26 +0100 Subject: [PATCH 2/2] Check if cross-rs is available, provide instructions on installation if it is not. --- scripts/uniffi_bindgen_generate_go.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/uniffi_bindgen_generate_go.sh b/scripts/uniffi_bindgen_generate_go.sh index 60f28f8ab..9cf563a9e 100755 --- a/scripts/uniffi_bindgen_generate_go.sh +++ b/scripts/uniffi_bindgen_generate_go.sh @@ -2,6 +2,12 @@ set -e +if ! command -v cross &> /dev/null; then + echo "cross-rs is required to build bindings. Install it by running:" + echo " cargo install cross --git https://github.com/cross-rs/cross" + exit 1 +fi + uniffi-bindgen-go bindings/ldk_node.udl -o ffi/golang -c ./uniffi.toml build_lib() {