forked from lightningdevkit/ldk-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from getAlby/downgrade-uniffi
Add the Go bindings build script
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
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() { | ||
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" |