40e118a2fd05094c965d6fecd4b6ae61505e1769
[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 [ "$LDK_COVERAGE_BUILD" != "" ] && export RUSTFLAGS="-C link-dead-code"
18
19 export RUST_BACKTRACE=1
20
21 echo -e "\n\nBuilding and testing all workspace crates..."
22 cargo build --verbose --color always
23 cargo test --verbose --color always
24
25 echo -e "\n\nBuilding with all Log-Limiting features"
26 pushd lightning
27 grep '^max_level_' Cargo.toml | awk '{ print $1 }'| while read -r FEATURE; do
28         cargo build --verbose --color always --features "$FEATURE"
29 done
30 popd
31
32 if [ "$RUSTC_MINOR_VERSION" -gt 51 ]; then # Current `object` MSRV, subject to change
33         echo -e "\n\nTest backtrace-debug builds"
34         pushd lightning
35         cargo test --verbose --color always --features backtrace
36         popd
37 fi
38
39 echo -e "\n\nTesting no-std flags in various combinations"
40 for DIR in lightning lightning-invoice lightning-rapid-gossip-sync; do
41         pushd $DIR
42         cargo test --verbose --color always --no-default-features --features no-std
43         # check if there is a conflict between no-std and the default std feature
44         cargo test --verbose --color always --features no-std
45         # check if there is a conflict between no-std and the c_bindings cfg
46         RUSTFLAGS="--cfg=c_bindings" cargo test --verbose --color always --no-default-features --features=no-std
47         popd
48 done
49 # Note that outbound_commitment_test only runs in this mode because of hardcoded signature values
50 pushd lightning
51 cargo test --verbose --color always --no-default-features --features=std,_test_vectors
52 popd
53 # This one only works for lightning-invoice
54 pushd lightning-invoice
55 # check that compile with no-std and serde works in lightning-invoice
56 cargo test --verbose --color always --no-default-features --features no-std --features serde
57 popd
58
59 echo -e "\n\nTesting no-std build on a downstream no-std crate"
60 # check no-std compatibility across dependencies
61 pushd no-std-check
62 cargo check --verbose --color always --features lightning-transaction-sync
63 popd
64
65 if [ -f "$(which arm-none-eabi-gcc)" ]; then
66         pushd no-std-check
67         cargo build --target=thumbv7m-none-eabi
68         popd
69 fi
70
71 echo -e "\n\nBuilding and testing Block Sync Clients with features"
72 pushd lightning-block-sync
73 cargo build --verbose --color always --features rest-client
74 cargo test --verbose --color always --features rest-client
75 cargo build --verbose --color always --features rpc-client
76 cargo test --verbose --color always --features rpc-client
77 cargo build --verbose --color always --features rpc-client,rest-client
78 cargo test --verbose --color always --features rpc-client,rest-client
79 cargo build --verbose --color always --features rpc-client,rest-client,tokio
80 cargo test --verbose --color always --features rpc-client,rest-client,tokio
81 popd
82
83 if [[ $RUSTC_MINOR_VERSION -gt 67 && "$HOST_PLATFORM" != *windows* ]]; then
84         echo -e "\n\nBuilding and testing Transaction Sync Clients with features"
85         pushd lightning-transaction-sync
86         cargo build --verbose --color always --features esplora-blocking
87         cargo test --verbose --color always --features esplora-blocking
88         cargo build --verbose --color always --features esplora-async
89         cargo test --verbose --color always --features esplora-async
90         cargo build --verbose --color always --features esplora-async-https
91         cargo test --verbose --color always --features esplora-async-https
92         popd
93 fi
94
95 echo -e "\n\nTest futures builds"
96 pushd lightning-background-processor
97 cargo test --verbose --color always --features futures
98 popd
99
100 if [ "$RUSTC_MINOR_VERSION" -gt 55 ]; then
101         echo -e "\n\nTest Custom Message Macros"
102         pushd lightning-custom-message
103         cargo test --verbose --color always
104         popd
105 fi
106
107 echo -e "\n\nTest Taproot builds"
108 pushd lightning
109 RUSTFLAGS="$RUSTFLAGS --cfg=taproot" cargo test --verbose --color always -p lightning
110 popd