From: Matt Corallo Date: Wed, 31 Mar 2021 04:08:22 +0000 (-0400) Subject: Optionally enable allow_wallclock_use X-Git-Tag: v0.0.98~17^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=b25e291110094bb9b59bc05f3f233c1b5d37b6e6;p=ldk-c-bindings Optionally enable allow_wallclock_use --- diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9511edf..2db5936 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,8 +25,10 @@ jobs: run: cargo install --force cbindgen - name: Checkout Rust-Lightning git run: git clone https://github.com/rust-bitcoin/rust-lightning + - name: Rebuild bindings without std, and check the sample app builds + links + run: ./genbindings.sh ./rust-lightning false - name: Rebuild bindings, and check the sample app builds + links - run: ./genbindings.sh ./rust-lightning + run: ./genbindings.sh ./rust-lightning true - name: Check that the latest bindings are in git run: | git checkout lightning-c-bindings/Cargo.toml # genbindings edits this to update the path diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 0b8e10d..10f83e5 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -82,12 +82,21 @@ pub fn export_status(attrs: &[syn::Attribute]) -> ExportStatus { if i == "any" { // #[cfg(any(test, feature = ""))] if let TokenTree::Group(g) = iter.next().unwrap() { - if let TokenTree::Ident(i) = g.stream().into_iter().next().unwrap() { - if i == "test" || i == "feature" { - // If its cfg(feature(...)) we assume its test-only - return ExportStatus::TestOnly; + let mut all_test = true; + for token in g.stream().into_iter() { + if let TokenTree::Ident(i) = token { + match format!("{}", i).as_str() { + "test" => {}, + "feature" => {}, + _ => all_test = false, + } + } else if let TokenTree::Literal(lit) = token { + if format!("{}", lit) != "fuzztarget" { + all_test = false; + } } } + if all_test { return ExportStatus::TestOnly; } } } else if i == "test" || i == "feature" { // If its cfg(feature(...)) we assume its test-only diff --git a/genbindings.sh b/genbindings.sh index 0f74c4b..0d03950 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" @@ -38,16 +44,16 @@ 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 | +RUSTC_BOOTSTRAP=1 cargo rustc $FEATURES_ARGS --profile=check -- -Zunstable-options --pretty=expanded | RUST_BACKTRACE=1 "$BIN" "$OUT/" lightning "$OUT_TEMPL" "$OUT_F" "$OUT_CPP" popd 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 -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 diff --git a/lightning-c-bindings/Cargo.toml b/lightning-c-bindings/Cargo.toml index 1ba8632..e8e556b 100644 --- a/lightning-c-bindings/Cargo.toml +++ b/lightning-c-bindings/Cargo.toml @@ -18,7 +18,7 @@ crate-type = ["staticlib" bitcoin = "0.26" secp256k1 = { version = "0.20.1", features = ["global-context-less-secure"] } # Note that the following line is matched by genbindings to update the path -lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3" } +lightning = { git = "https://git.bitcoin.ninja/rust-lightning", rev = "6fcac8bc65ed6d372e0b8c367e9934c754f99ff3", features = ["allow_wallclock_use"] } [patch.crates-io] # Rust-Secp256k1 PR 279. Should be dropped once merged.