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