Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Go bindings build script #3

Merged
merged 3 commits into from
Mar 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions scripts/uniffi_bindgen_generate_go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
rolznz marked this conversation as resolved.
Show resolved Hide resolved

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"
Loading