Only link dead code when necessary in CI.
[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       matrix:
9         toolchain: [ stable,
10                      beta,
11                      # 1.30.0 is MSRV for Rust-Lightning
12                      1.30.0,
13                      # 1.34.2 is Debian stable
14                      1.34.2,
15                      # 1.39.0 is MSRV for lightning-net-tokio and generates coverage
16                      1.39.0]
17         include:
18           - toolchain: stable
19             build-net-tokio: true
20           - toolchain: beta
21             build-net-tokio: true
22           - toolchain: 1.39.0
23             build-net-tokio: true
24             coverage: true
25           - toolchain: 1.34.2
26     runs-on: ubuntu-latest
27     steps:
28       - name: Checkout source code
29         uses: actions/checkout@v2
30       - name: Install Rust ${{ matrix.toolchain }} toolchain
31         uses: actions-rs/toolchain@v1
32         with:
33           toolchain: ${{ matrix.toolchain }}
34           override: true
35           profile: minimal
36       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio
37         if: "matrix.build-net-tokio && !matrix.coverage"
38         run: cargo build --verbose --color always
39       - name: Build on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
40         if: matrix.coverage
41         run: RUSTFLAGS="-C link-dead-code" cargo build --verbose --color always
42       - name: Build on Rust ${{ matrix.toolchain }}
43         if: "! matrix.build-net-tokio"
44         run: cargo build --verbose  --color always -p lightning
45       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio
46         if: "matrix.build-net-tokio && !matrix.coverage"
47         run: cargo test --verbose --color always
48       - name: Test on Rust ${{ matrix.toolchain }} with net-tokio and full code-linking for coverage generation
49         if: matrix.coverage
50         run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
51       - name: Test on Rust ${{ matrix.toolchain }}
52         if: "! matrix.build-net-tokio"
53         run: cargo test --verbose --color always  -p lightning
54       - name: Install deps for kcov
55         if: matrix.coverage
56         run: |
57           sudo apt-get update
58           sudo apt-get -y install binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev
59       - name: Install kcov
60         if: matrix.coverage
61         run: |
62           wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz
63           tar xzf master.tar.gz
64           cd kcov-master && mkdir build && cd build
65           cmake ..
66           make
67           make install DESTDIR=../../kcov-build
68           cd ../.. && rm -rf kcov-master master.tar.gz
69       - name: Generate coverage report
70         if: matrix.coverage
71         run: |
72           for file in target/debug/lightning-*; do
73             [ -x "${file}" ] || continue;
74             mkdir -p "target/cov/$(basename $file)";
75             ./kcov-build/usr/local/bin/kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file";
76           done
77       - name: Upload coverage
78         if: matrix.coverage
79         uses: codecov/codecov-action@v1
80         with:
81           # Could you use this to fake the coverage report for your PR? Sure.
82           # Will anyone be impressed by your amazing coverage? No
83           # Maybe if codecov wasn't broken we wouldn't need to do this...
84           token: f421b687-4dc2-4387-ac3d-dc3b2528af57
85           fail_ci_if_error: true
86
87   check_commits:
88     runs-on: ubuntu-latest
89     env:
90       TOOLCHAIN: stable
91     steps:
92       - name: Checkout source code
93         uses: actions/checkout@v2
94         with:
95           fetch-depth: 0
96       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
97         uses: actions-rs/toolchain@v1
98         with:
99           toolchain: ${{ env.TOOLCHAIN }}
100           override: true
101           profile: minimal
102       - name: Fetch full tree and rebase on upstream
103         run: |
104           git remote add upstream https://github.com/rust-bitcoin/rust-lightning
105           git fetch upstream
106           git rebase upstream/main
107       - name: For each commit, run cargo check (including in fuzz)
108         run: ci/check-each-commit.sh upstream/main
109
110   fuzz:
111     runs-on: ubuntu-latest
112     env:
113       TOOLCHAIN: stable
114     steps:
115       - name: Checkout source code
116         uses: actions/checkout@v2
117       - name: Install Rust ${{ env.TOOLCHAIN }} toolchain
118         uses: actions-rs/toolchain@v1
119         with:
120           toolchain: ${{ env.TOOLCHAIN }}
121           override: true
122           profile: minimal
123       - name: Install dependencies for honggfuzz
124         run: |
125           sudo apt-get update
126           sudo apt-get -y install build-essential binutils-dev libunwind-dev
127       - name: Sanity check fuzz targets on Rust ${{ env.TOOLCHAIN }}
128         run: cd fuzz && cargo test --verbose --color always
129       - name: Run fuzzers
130         run: cd fuzz && ./ci-fuzz.sh
131
132   check_bindings:
133     runs-on: ubuntu-latest
134     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
135     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
136     # We further (temporarily) use Debian experimental since testing links rustc against the
137     # brand-new llvm-10, but clang/llvm still default to LLVM 9.
138     container: debian:experimental
139     env:
140       TOOLCHAIN: stable
141     steps:
142       - name: Install native Rust toolchain, Valgrind, and build utilitis
143         run: |
144           echo 'Package: llvm llvm-runtime clang lld' > /etc/apt/preferences.d/99-llvm10
145           echo 'Pin: release n=experimental' >> /etc/apt/preferences.d/99-llvm10
146           echo 'Pin-Priority: 995' >> /etc/apt/preferences.d/99-llvm10
147           apt-get update
148           apt-get -y dist-upgrade
149           apt-get -y install cargo valgrind lld git g++ clang
150       - name: Checkout source code
151         uses: actions/checkout@v2
152       - name: Sanity test bindings
153         working-directory: lightning-c-bindings
154         run: cargo check
155       - name: Install cbindgen
156         run: cargo install --force cbindgen
157       - name: Rebuild bindings, and check the sample app builds + links
158         run: ./genbindings.sh
159       - name: Check that the latest bindings are in git
160         run: |
161           if [ "$(git diff)" != "" ]; then
162             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
163             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
164             git checkout lightning-c-bindings/include/lightning.h
165             cat lightning-c-bindings/include/lightning.h | sort > lightning-c-bindings/include/lightning.h.sorted
166             cat lightning-c-bindings/include/lightning.h.new | sort > lightning-c-bindings/include/lightning.h.new.sorted
167             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
168             #
169             mv lightning-c-bindings/include/lightningpp.hpp lightning-c-bindings/include/lightningpp.hpp.new
170             git checkout lightning-c-bindings/include/lightningpp.hpp
171             cat lightning-c-bindings/include/lightningpp.hpp | sort > lightning-c-bindings/include/lightningpp.hpp.sorted
172             cat lightning-c-bindings/include/lightningpp.hpp.new | sort > lightning-c-bindings/include/lightningpp.hpp.new.sorted
173             diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted
174             #
175             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
176             [ "$(diff lightning-c-bindings/include/lightningpp.hpp.sorted lightning-c-bindings/include/lightningpp.hpp.new.sorted)" != "" ] && exit 3
177             git diff --exit-code
178           fi