From 31a9cd2d3d339aaf0dd28ca4ba68b42bcce8b65e Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 16 Aug 2024 19:17:42 +0000 Subject: [PATCH] Drop the `no-std` feature from `lightning-invoice` Now that we don't have to have everything in our entire ecosystem use the same `std`/`no-std` feature combinations we should start by untangling our own features a bit. This takes another step by removing the `no-std` feature entirely from the `lightning-invoice` crate and removing all feature implications on dependencies from the remaining `std` feature. --- ci/ci-tests.sh | 13 ++++++++++--- lightning-invoice/Cargo.toml | 4 +--- lightning-invoice/src/lib.rs | 3 --- lightning/Cargo.toml | 2 +- no-std-check/Cargo.toml | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/ci/ci-tests.sh b/ci/ci-tests.sh index 13ddcaf9a..5555667db 100755 --- a/ci/ci-tests.sh +++ b/ci/ci-tests.sh @@ -77,14 +77,21 @@ grep '^max_level_' lightning/Cargo.toml | awk '{ print $1 }'| while read -r FEAT RUSTFLAGS="$RUSTFLAGS -A unused_variables -A unused_macros -A unused_imports -A dead_code" cargo check -p lightning --verbose --color always --features "$FEATURE" done +echo -e "\n\nTesting no-std builds" +for DIR in lightning-invoice; do + cargo test -p $DIR --verbose --color always --no-default-features + # check if there is a conflict between no-std and the c_bindings cfg + RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features +done + echo -e "\n\nTesting no-std flags in various combinations" -for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do +for DIR in lightning lightning-rapid-gossip-sync; do cargo test -p $DIR --verbose --color always --no-default-features --features no-std # check if there is a conflict between no-std and the default std feature cargo test -p $DIR --verbose --color always --features no-std done -for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do +for DIR in lightning lightning-rapid-gossip-sync; do # check if there is a conflict between no-std and the c_bindings cfg RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test -p $DIR --verbose --color always --no-default-features --features=no-std done @@ -94,7 +101,7 @@ RUSTFLAGS="$RUSTFLAGS --cfg=c_bindings" cargo test --verbose --color always cargo test -p lightning --verbose --color always --no-default-features --features=std,_test_vectors # This one only works for lightning-invoice # check that compile with no-std and serde works in lightning-invoice -cargo test -p lightning-invoice --verbose --color always --no-default-features --features no-std --features serde +cargo test -p lightning-invoice --verbose --color always --no-default-features --features serde echo -e "\n\nTesting no-std build on a downstream no-std crate" # check no-std compatibility across dependencies diff --git a/lightning-invoice/Cargo.toml b/lightning-invoice/Cargo.toml index f03875d67..2a5bc406b 100644 --- a/lightning-invoice/Cargo.toml +++ b/lightning-invoice/Cargo.toml @@ -15,9 +15,7 @@ all-features = true rustdoc-args = ["--cfg", "docsrs"] [features] -default = ["std"] -no-std = [] -std = ["bech32/std"] +std = [] [dependencies] bech32 = { version = "0.9.1", default-features = false } diff --git a/lightning-invoice/src/lib.rs b/lightning-invoice/src/lib.rs index bbb8dc8d5..58f08583a 100644 --- a/lightning-invoice/src/lib.rs +++ b/lightning-invoice/src/lib.rs @@ -22,9 +22,6 @@ //! //! [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr -#[cfg(not(any(feature = "std", feature = "no-std")))] -compile_error!("at least one of the `std` or `no-std` features must be enabled"); - extern crate bech32; extern crate lightning_types; extern crate alloc; diff --git a/lightning/Cargo.toml b/lightning/Cargo.toml index 6fab8d5ec..d642b6fbd 100644 --- a/lightning/Cargo.toml +++ b/lightning/Cargo.toml @@ -31,7 +31,7 @@ unsafe_revoked_tx_signing = [] # Override signing to not include randomness when generating signatures for test vectors. _test_vectors = [] -no-std = ["hashbrown", "possiblyrandom", "lightning-invoice/no-std", "libm"] +no-std = ["hashbrown", "possiblyrandom", "libm"] std = ["lightning-invoice/std", "bech32/std"] # Generates low-r bitcoin signatures, which saves 1 byte in 50% of the cases diff --git a/no-std-check/Cargo.toml b/no-std-check/Cargo.toml index c9d404c92..056cb1d20 100644 --- a/no-std-check/Cargo.toml +++ b/no-std-check/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [features] -default = ["lightning/no-std", "lightning-invoice/no-std", "lightning-rapid-gossip-sync/no-std"] +default = ["lightning/no-std", "lightning-rapid-gossip-sync/no-std"] [dependencies] lightning = { path = "../lightning", default-features = false } -- 2.39.5