Skip to content

Instantly share code, notes, and snippets.

@notmandatory
Last active August 19, 2021 09:05
Show Gist options
  • Save notmandatory/bb4e5686f01b28fb6fa0288734a43f76 to your computer and use it in GitHub Desktop.
Save notmandatory/bb4e5686f01b28fb6fa0288734a43f76 to your computer and use it in GitHub Desktop.
Steps to build LDK java bindings

How-to build LDK java bindings

Build LDK C bindings

  1. Clone rust-lightning git repo2.

  2. Install clang-12 and set it as the default version

    linux Ubuntu install and set it as the default version

    macos

    brew install llvm
    
  3. Install rust-src

    linux

    rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
    

    macos

    rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
    
  4. Run script to build bindings

    ./genbindings.sh ../rust-lightning true  >& genbindings.out
    
  5. Check genbindings.out for any warning or error messages

Build LDK java bindings

  1. Install open JDK 11 and maven
sudo apt update
sudo apt install openjdk-11-jdk maven
  1. Clone ldk-garbagecollected repo
git clone git@github.com:lightningdevkit/ldk-garbagecollected.git
cd ldk-garbagecollected
  1. Run java tests
export LD_LIBRARY_PATH=.
mvn test

All good, test passes.

Build JNI lib

  1. Set rust toolchain
rustup default 1.51.0
  1. Clone Matt's rust-lightning repo
git clone https://git.bitcoin.ninja/rust-lightning
cd rust-lightning
git checkout 2021-03-java-bindings-base
cd ..
  1. Clone ldk-c-bindings repo
git clone git@github.com:lightningdevkit/ldk-c-bindings.git
cd ldk-c-bindings
  1. Install tools
rustup target add wasm32-wasi

# clang 10.0.1, gcc 9.3.0, g++ 9.3.0, valgrind 3.15.0
cargo install cbindgen g++ valgrind
  1. Generate bindings
./genbindings.sh ../rust-lightning true

This is where I'm stuck.. with error:

+ clang++ -Wall -Wno-nullability-completeness -pthread -std=c++11 -flto -O2 demo.cpp target/release/libldk.a -ldl
/usr/bin/ld: error: LLVM gold plugin has failed to create LTO module: Invalid record
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment