Merge pull request #1028 from lightning-signer/2021-08-no-std
[rust-lightning] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   build:
7     strategy:
8       fail-fast: false
9       matrix:
10         platform: [ ubuntu-latest ]
11         toolchain: [ stable,
12                      beta,
13                      # 1.36.0 is MSRV for Rust-Lightning, lightning-invoice, and lightning-persister
14                      1.36.0,
15                      # 1.41.0 is Debian stable
16                      1.41.0,
17                      # 1.45.2 is MSRV for lightning-net-tokio, lightning-block-sync, and coverage generation
18                      1.45.2,
19                      # 1.47.0 will be the MSRV for no-std builds using hashbrown once core2 is updated
20                      1.47.0]
21         include:
22           - toolchain: stable
23             build-net-tokio: true
24             build-no-std: true
25           - toolchain: stable
26             platform: macos-latest
27             build-net-tokio: true
28             build-no-std: true
29           - toolchain: beta
30             platform: macos-latest
31             build-net-tokio: true
32             build-no-std: true
33           - toolchain: stable
34             platform: windows-latest
35             build-net-tokio: true
36             build-no-std: true
37           - toolchain: beta
38             platform: windows-latest
39             build-net-tokio: true
40             build-no-std: true
41           - toolchain: beta
42             build-net-tokio: true
43             build-no-std: true
44           - toolchain: 1.36.0
45             build-no-std: false
46           - toolchain: 1.41.0
47             build-no-std: false
48           - toolchain: 1.45.2
49             build-net-tokio: true
50             build-no-std: false
51             coverage: true
52           - toolchain: 1.47.0
53             build-no-std: false
54     runs-on: ${{ matrix.platform }}
55     steps:
56       - name: Checkout source code
57         uses: actions/checkout@v2
58       - name: Install Rust ${{ matrix.toolchain }} toolchain
59         uses: actions-rs/toolchain@v1
60         with:
61           toolchain: ${{ matrix.toolchain }}
62           override: true
63           profile: minimal
64       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
65         if: "matrix.build-net-tokio && !matrix.coverage"
66         run: cargo build --verbose --color always
67       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
68         if: matrix.coverage
69         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
70       - name: Build on Rust ${{ matrix.toolchain }}
71         if: "! matrix.build-net-tokio"
72         run: |
73           cargo build --verbose  --color always -p lightning
74           cargo build --verbose  --color always -p lightning-invoice
75           cargo build --verbose  --color always -p lightning-persister
76       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features
77         if: "matrix.build-net-tokio && !matrix.coverage"
78         run: |
79           cd lightning-block-sync
80           cargo build --verbose --color always --features rest-client
81           cargo build --verbose --color always --features rpc-client
82           cargo build --verbose --color always --features rpc-client,rest-client
83           cargo build --verbose --color always --features rpc-client,rest-client,tokio
84       - name: Build Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
85         if: matrix.coverage
86         run: |
87           cd lightning-block-sync
88           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rest-client
89           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client
90           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client
91           RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always --features rpc-client,rest-client,tokio
92       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
93         if: "matrix.build-net-tokio && !matrix.coverage"
94         run: cargo test --verbose --color always
95       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
96         if: matrix.coverage
97         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
98       - name: Test on no-std bullds Rust ${{ matrix.toolchain }}
99         if: "matrix.build-no-std && !matrix.coverage"
100         run: |
101           cd lightning
102           cargo test --verbose --color always --no-default-features --features no-std
103           # check if there is a conflict between no-std and the default std feature
104           cargo test --verbose --color always --features no-std
105           cd ..
106       - name: Test on no-std builds Rust ${{ matrix.toolchain }} and full code-linking for coverage generation
107         if: "matrix.build-no-std && matrix.coverage"
108         run: |
109           cd lightning
110           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --no-default-features --features no-std
111           cd ..
112       - name: Test on Rust ${{ matrix.toolchain }}
113         if: "! matrix.build-net-tokio"
114         run: |
115           cargo test --verbose --color always  -p lightning
116           cargo test --verbose --color always  -p lightning-invoice
117           cargo build --verbose  --color always -p lightning-persister
118       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features
119         if: "matrix.build-net-tokio && !matrix.coverage"
120         run: |
121           cd lightning-block-sync
122           cargo test --verbose --color always --features rest-client
123           cargo test --verbose --color always --features rpc-client
124           cargo test --verbose --color always --features rpc-client,rest-client
125           cargo test --verbose --color always --features rpc-client,rest-client,tokio
126       - name: Test Block Sync Clients on Rust ${{ matrix.toolchain }} with features and full code-linking for coverage generation
127         if: matrix.coverage
128         run: |
129           cd lightning-block-sync
130           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rest-client
131           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client
132           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client
133           RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always --features rpc-client,rest-client,tokio
134       - name: Install deps for kcov
135         if: matrix.coverage
136         run: |
137           sudo apt-get update
138           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
139       - name: Install kcov
140         if: matrix.coverage
141         run: |
142           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
143           tar xzf master.tar.gz
144           cd kcov-master && mkdir build && cd build
145           cmake ..
146           make
147           make install DESTDIR=../../kcov-build
148           cd ../.. && rm -rf kcov-master master.tar.gz
149       - name: Generate coverage report
150         if: matrix.coverage
151         run: |
152           for file in target/debug/deps/lightning*; do
153             [ -x "${file}" ] || continue;
154             mkdir -p "target/cov/$(basename $file)";
155             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
156           done
157       - name: Upload coverage
158         if: matrix.coverage
159         uses: codecov/codecov-action@v1
160         with:
161           # Could you use this to fake the coverage report for your PR? Sure.
162           # Will anyone be impressed by your amazing coverage? No
163           # Maybe if codecov wasn't broken we wouldn't need to do this...
164           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
165           fail_ci_if_error: true
166
167   benchmark:
168     runs-on: ubuntu-latest
169     env:
170       TOOLCHAIN: nightly
171     steps:
172       - name: Checkout source code
173         uses: actions/checkout@v2
174       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
175         uses: actions-rs/toolchain@v1
176         with:
177           toolchain: ${{ env.TOOLCHAIN }}
178           override: true
179           profile: minimal
180       - name: Cache routing graph snapshot
181         id: cache-graph
182         uses: actions/cache@v2
183         with:
184           path: lightning/net_graph-2021-05-31.bin
185           key: ldk-net_graph-v0.0.15-2021-05-31.bin
186       - name: Fetch routing graph snapshot
187         if: steps.cache-graph.outputs.cache-hit != 'true'
188         run: |
189           wget -O lightning/net_graph-2021-05-31.bin https://bitcoin.ninja/ldk-net_graph-v0.0.15-2021-05-31.bin
190           if [ "$(sha256sum lightning/net_graph-2021-05-31.bin | awk '{ print $1 }')" != "05a5361278f68ee2afd086cc04a1f927a63924be451f3221d380533acfacc303" ]; then
191             echo "Bad hash"
192             exit 1
193           fi
194       - name: Test with Network Graph on Rust ${{ matrix.toolchain }}
195         run: |
196           cd lightning
197           RUSTFLAGS="--cfg=require_route_graph_test" cargo test
198           RUSTFLAGS="--cfg=require_route_graph_test" cargo test --features hashbrown
199           cd ..
200       - name: Run benchmarks on Rust ${{ matrix.toolchain }}
201         run: |
202           cargo bench --features unstable
203
204   check_commits:
205     runs-on: ubuntu-latest
206     env:
207       # rustc 1.53 regressed and panics when building our (perfectly fine) docs.
208       # See https://github.com/rust-lang/rust/issues/84738
209       TOOLCHAIN: 1.52.1
210     steps:
211       - name: Checkout source code
212         uses: actions/checkout@v2
213         with:
214           fetch-depth: 0
215       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
216         uses: actions-rs/toolchain@v1
217         with:
218           toolchain: ${{ env.TOOLCHAIN }}
219           override: true
220           profile: minimal
221       - name: Fetch full tree and rebase on upstream
222         run: |
223           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
224           git fetch upstream
225           export GIT_COMMITTER_EMAIL="rl-ci@example.com"
226           export GIT_COMMITTER_NAME="RL CI"
227           git rebase upstream/main
228       - name: For each commit, run cargo check (including in fuzz)
229         run: ci/check-each-commit.sh upstream/main
230
231   fuzz:
232     runs-on: ubuntu-latest
233     env:
234       TOOLCHAIN: stable
235     steps:
236       - name: Checkout source code
237         uses: actions/checkout@v2
238       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
239         uses: actions-rs/toolchain@v1
240         with:
241           toolchain: ${{ env.TOOLCHAIN }}
242           override: true
243           profile: minimal
244       - name: Install dependencies for honggfuzz
245         run: |
246           sudo apt-get update
247           sudo apt-get -y install build-essential binutils-dev libunwind-dev
248       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
249         run: cd fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose --color always
250       - name: Run fuzzers
251         run: cd fuzz && ./ci-fuzz.sh && cd ..
252       - name: Run lightning-invoice fuzzers
253         run: cd lightning-invoice/fuzz && RUSTFLAGS="--cfg=fuzzing" cargo test --verbose && ./ci-fuzz.sh
254
255   linting:
256     runs-on: ubuntu-latest
257     env:
258       TOOLCHAIN: 1.45.2
259     steps:
260       - name: Checkout source code
261         uses: actions/checkout@v2
262       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
263         uses: actions-rs/toolchain@v1
264         with:
265           toolchain: ${{ env.TOOLCHAIN }}
266           override: true
267           profile: minimal
268       - name: Install clippy
269         run: |
270           rustup component add clippy
271       - name: Run default clippy linting
272         run: |
273           cargo clippy -- -Aclippy::erasing_op -Aclippy::never_loop -Aclippy::if_same_then_else -Dclippy::try_err