Add OSX CI
[ldk-c-bindings] / .github / workflows / build.yml
1 name: Continuous Integration Checks
2
3 on: [push, pull_request]
4
5 jobs:
6   check_bindings:
7     runs-on: ubuntu-latest
8     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
9     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
10     container: debian:bullseye
11     env:
12       TOOLCHAIN: stable
13     steps:
14       - name: Install native Rust toolchain, Valgrind, and build utilitis
15         run: |
16           apt-get update
17           apt-get -y dist-upgrade
18           apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang
19       - name: Checkout source code
20         uses: actions/checkout@v2
21         with:
22           fetch-depth: 0
23       - name: Sanity test bindings against Cargo.toml RL
24         working-directory: lightning-c-bindings
25         run: |
26           # Note that the version tags aren't checked into git
27           touch src/version.rs
28           cargo check
29       - name: Install cbindgen
30         run: cargo install --force cbindgen
31       - name: Checkout Rust-Lightning git
32         run: git clone https://github.com/rust-bitcoin/rust-lightning
33       - name: Rebuild bindings without std, and check the sample app builds + links
34         run: ./genbindings.sh ./rust-lightning false
35       - name: Rebuild bindings, and check the sample app builds + links
36         run: ./genbindings.sh ./rust-lightning true
37       - name: Check that the latest bindings are in git
38         run: |
39           git checkout lightning-c-bindings/Cargo.toml # genbindings edits this to update the path
40           if [ "$(git diff)" != "" ]; then
41             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
42             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
43             git checkout lightning-c-bindings/include/lightning.h
44             cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted
45             cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted
46             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
47             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
48             git diff --exit-code
49           fi
50
51   osx:
52     strategy:
53       matrix:
54         include:
55           - platform: macos-10.15
56           - platform: macos-11
57     runs-on: ${{ matrix.platform }}
58     env:
59       TOOLCHAIN: stable
60     steps:
61       - name: Install other Rust platforms
62         run: rustup target install aarch64-apple-darwin
63       - name: Cache upstream LLVM/clang
64         id: cache-llvm
65         uses: actions/cache@v2
66         with:
67           path: clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
68           key: clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
69       - name: Fetch upstream LLVM/clang snapshot
70         if: steps.cache-llvm.outputs.cache-hit != 'true'
71         run: |
72           wget -O clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
73           if [ "$(shasum -a 256 clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "7bc2259bf75c003f644882460fc8e844ddb23b27236fe43a2787870a4cd8ab50" ]; then
74             echo "Bad hash"
75             exit 1
76           fi
77       - name: Unpack upstream LLVM+clang and use it by default
78         run: |
79           tar xvvf clang+llvm-12.0.0-x86_64-apple-darwin.tar.xz
80       - name: Checkout source code
81         uses: actions/checkout@v2
82         with:
83           fetch-depth: 0
84       - name: Install cbindgen
85         run: cargo install --force cbindgen
86       - name: Checkout Rust-Lightning git
87         run: git clone https://github.com/rust-bitcoin/rust-lightning
88       - name: Rebuild bindings using Apple clang, and check the sample app builds + links
89         run: ./genbindings.sh ./rust-lightning true
90       - name: Rebuild bindings using upstream clang, and check the sample app builds + links
91         run: |
92           export PATH=`pwd`/clang+llvm-12.0.0-x86_64-apple-darwin/bin:$PATH
93           CC=clang ./genbindings.sh ./rust-lightning true