X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.sh;h=ff90b3ad4b33e0a2240bfaeb605b8f5e55d38367;hb=6c95131720d1d390bf006f5160dcf4aa878fa4f0;hp=0f74c4b302fe0181d95616e2b3c91b65891f3ee9;hpb=4b7b5e65190e2c14a349b01284bfc67dc296c73d;p=ldk-c-bindings diff --git a/genbindings.sh b/genbindings.sh index 0f74c4b..ff90b3a 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -3,11 +3,17 @@ set -e set -x -if [ ! -d "$1/lightning" ]; then - echo "USAGE: $0 path-to-rust-lightning" +if [ ! -d "$1/lightning" -o "$2" != "true" -a "$2" != "false" ]; then + echo "USAGE: $0 path-to-rust-lightning allow-std" + echo "allow-std must be either 'true' or 'false' to indicate if we should be built relying on time and pthread support" exit 1 fi +if [ "$2" = "true" ]; then + FEATURES_ARGS='--features=allow_wallclock_use' + FEATURES='"allow_wallclock_use"' +fi + # On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software. ORIG_PWD="$(pwd)" cd "$1/lightning" @@ -26,7 +32,7 @@ mv lightning-c-bindings/src/bitcoin ./ rm -rf lightning-c-bindings/src -mkdir -p lightning-c-bindings/src/c_types/ +mkdir -p lightning-c-bindings/src/{c_types,lightning} mv ./mod.rs lightning-c-bindings/src/c_types/ mv ./bitcoin lightning-c-bindings/src/ @@ -38,16 +44,25 @@ OUT_CPP="$(pwd)/lightning-c-bindings/include/lightningpp.hpp" BIN="$(pwd)/c-bindings-gen/target/release/c-bindings-gen" pushd "$LIGHTNING_PATH" -RUSTC_BOOTSTRAP=1 cargo rustc --profile=check -- -Zunstable-options --pretty=expanded | - RUST_BACKTRACE=1 "$BIN" "$OUT/" lightning "$OUT_TEMPL" "$OUT_F" "$OUT_CPP" -popd +RUSTC_BOOTSTRAP=1 cargo rustc $FEATURES_ARGS --profile=check -- -Zunstable-options --pretty=expanded > /tmp/lightning-crate-source.txt HOST_PLATFORM="$(rustc --version --verbose | grep "host:")" if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then # OSX sed is for some reason not compatible with GNU sed - sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml + sed -E -i '' 's/#!\[crate_name = "(.*)"\]/pub mod \1 {/' /tmp/lightning-crate-source.txt +else + sed -E -i 's/#!\[crate_name = "(.*)"\]/pub mod \1 {/' /tmp/lightning-crate-source.txt +fi +echo "}" >> /tmp/lightning-crate-source.txt + +cat /tmp/lightning-crate-source.txt | RUST_BACKTRACE=1 "$BIN" "$OUT/" "$OUT_TEMPL" "$OUT_F" "$OUT_CPP" +popd + +if [ "$HOST_PLATFORM" = "host: x86_64-apple-darwin" ]; then + # OSX sed is for some reason not compatible with GNU sed + sed -i '' 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml else - sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml + sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'", features = ['"$FEATURES"'] }|' lightning-c-bindings/Cargo.toml fi # Set path to include our rustc wrapper as well as cbindgen