e8137380705e1d33da8f6d090b8987853907b2d6
[rust-lightning] / ci / ci-tests.sh
1 #!/bin/bash
2 set -eox pipefail
3
4 RUSTC_MINOR_VERSION=$(rustc --version | awk '{ split($2,a,"."); print a[2] }')
5 HOST_PLATFORM="$(rustc --version --verbose | grep "host:" | awk '{ print $2 }')"
6
7 # Tokio MSRV on versions 1.17 through 1.26 is rustc 1.49. Above 1.26 MSRV is 1.56.
8 [ "$RUSTC_MINOR_VERSION" -lt 49 ] && cargo update -p tokio --precise "1.14.1" --verbose
9 [[ "$RUSTC_MINOR_VERSION" -gt 48  &&  "$RUSTC_MINOR_VERSION" -lt 56 ]] && cargo update -p tokio --precise "1.25.1" --verbose
10
11 # Sadly the log crate is always a dependency of tokio until 1.20, and has no reasonable MSRV guarantees
12 [ "$RUSTC_MINOR_VERSION" -lt 49 ] && cargo update -p log --precise "0.4.18" --verbose
13
14 # The addr2line v0.20 crate (a dependency of `backtrace` starting with 0.3.68) relies on 1.55+
15 [ "$RUSTC_MINOR_VERSION" -lt 55 ] && cargo update -p backtrace --precise "0.3.67" --verbose
16
17 # The serde_json crate switched to Rust edition 2021 starting with v1.0.101, i.e., has MSRV of 1.56
18 [ "$RUSTC_MINOR_VERSION" -lt 56 ] && cargo update -p serde_json --precise "1.0.100" --verbose
19
20 [ "$LDK_COVERAGE_BUILD" != "" ] && export RUSTFLAGS="-C link-dead-code"
21
22 export RUST_BACKTRACE=1
23
24 echo -e "\n\nBuilding and testing all workspace crates..."
25 cargo build --verbose --color always
26 cargo test --verbose --color always
27
28 echo -e "\n\nBuilding with all Log-Limiting features"
29 pushd lightning
30 grep '^max_level_' Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
31         cargo build --verbose --color always --features "$FEATURE"
32 done
33 popd
34
35 if [ "$RUSTC_MINOR_VERSION" -gt 51 ]; then # Current `object` MSRV, subject to change
36         echo -e "\n\nTest backtrace-debug builds"
37         pushd lightning
38         cargo test --verbose --color always --features backtrace
39         popd
40 fi
41
42 echo -e "\n\nTesting no-std flags in various combinations"
43 for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
44         pushd $DIR
45         cargo test --verbose --color always --no-default-features --features no-std
46         # check if there is a conflict between no-std and the default std feature
47         cargo test --verbose --color always --features no-std
48         # check if there is a conflict between no-std and the c_bindings cfg
49         RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
50         popd
51 done
52 # Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
53 pushd lightning
54 cargo test --verbose --color always --no-default-features --features=std,_test_vectors
55 popd
56 # This one only works for lightning-invoice
57 pushd lightning-invoice
58 # check that compile with no-std and serde works in lightning-invoice
59 cargo test --verbose --color always --no-default-features --features no-std --features serde
60 popd
61
62 echo -e "\n\nTesting no-std build on a downstream no-std crate"
63 # check no-std compatibility across dependencies
64 pushd no-std-check
65 cargo check --verbose --color always --features lightning-transaction-sync
66 popd
67
68 if [ -f "$(which arm-none-eabi-gcc)" ]; then
69         pushd no-std-check
70         cargo build --target=thumbv7m-none-eabi
71         popd
72 fi
73
74 echo -e "\n\nBuilding and testing Block Sync Clients with features"
75 pushd lightning-block-sync
76 cargo build --verbose --color always --features rest-client
77 cargo test --verbose --color always --features rest-client
78 cargo build --verbose --color always --features rpc-client
79 cargo test --verbose --color always --features rpc-client
80 cargo build --verbose --color always --features rpc-client,rest-client
81 cargo test --verbose --color always --features rpc-client,rest-client
82 cargo build --verbose --color always --features rpc-client,rest-client,tokio
83 cargo test --verbose --color always --features rpc-client,rest-client,tokio
84 popd
85
86 if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
87         echo -e "\n\nBuilding and testing Transaction Sync Clients with features"
88         pushd lightning-transaction-sync
89         cargo build --verbose --color always --features esplora-blocking
90         cargo test --verbose --color always --features esplora-blocking
91         cargo build --verbose --color always --features esplora-async
92         cargo test --verbose --color always --features esplora-async
93         cargo build --verbose --color always --features esplora-async-https
94         cargo test --verbose --color always --features esplora-async-https
95         popd
96 fi
97
98 echo -e "\n\nTest futures builds"
99 pushd lightning-background-processor
100 cargo test --verbose --color always --features futures
101 popd
102
103 if [ "$RUSTC_MINOR_VERSION" -gt 55 ]; then
104         echo -e "\n\nTest Custom Message Macros"
105         pushd lightning-custom-message
106         cargo test --verbose --color always
107         popd
108 fi
109
110 echo -e "\n\nTest Taproot builds"
111 pushd lightning
112 RUSTFLAGS="$RUSTFLAGS --cfg=taproot" cargo test --verbose --color always -p lightning
113 popd