Build OSX releases on Linux if `MACOS_SDK` is set
[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 wget
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           RUSTFLAGS="--cfg=c_bindings" cargo check --features std
29       - name: Install cbindgen
30         run: |
31           git clone https://github.com/eqrion/cbindgen
32           cd cbindgen/
33           git checkout v0.20.0
34           cargo update -p indexmap --precise "1.6.2" --verbose
35           cargo install --locked --path .
36       - name: Checkout Rust-Lightning git
37         run: |
38           git clone https://github.com/rust-bitcoin/rust-lightning
39           cd rust-lightning
40           git checkout 0.0.115-bindings
41       - name: Fix Github Actions to not be broken
42         run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
43       - name: Rebuild bindings without std, and check the sample app builds + links
44         run: ./genbindings.sh ./rust-lightning false
45       - name: Rebuild bindings, and check the sample app builds + links
46         run: ./genbindings.sh ./rust-lightning true
47       - name: Check that the latest bindings are in git
48         run: |
49           git checkout lightning-c-bindings/Cargo.toml # genbindings edits this to update the path
50           if [ "$(git diff)" != "" ]; then
51             # cbindgen's bindings output order can be FS-dependant, so check that the lines are all the same:
52             mv lightning-c-bindings/include/lightning.h lightning-c-bindings/include/lightning.h.new
53             git checkout lightning-c-bindings/include/lightning.h
54             cat lightning-c-bindings/include/lightning.h | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.sorted
55             cat lightning-c-bindings/include/lightning.h.new | grep -v "Generated with cbindgen:[0-9\.]*" | sort > lightning-c-bindings/include/lightning.h.new.sorted
56             diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted
57             [ "$(diff lightning-c-bindings/include/lightning.h.sorted lightning-c-bindings/include/lightning.h.new.sorted)" != "" ] && exit 2
58             git diff --exit-code
59           fi
60
61   check_macos:
62     runs-on: ubuntu-latest
63     # Ubuntu's version of rustc uses its own LLVM instead of being a real native package.
64     # This leaves us with an incompatible LLVM version when linking. Instead, use a real OS.
65     container: debian:bookworm
66     env:
67       TOOLCHAIN: stable
68     steps:
69       - name: Install native Rust toolchain, Valgrind, and build utilitis
70         run: |
71           apt-get update
72           apt-get -y dist-upgrade
73           apt-get -y install cargo libstd-rust-dev-wasm32 valgrind lld git g++ clang wget rust-src
74       - name: Checkout source code
75         uses: actions/checkout@v2
76         with:
77           fetch-depth: 0
78       - name: Sanity test bindings against Cargo.toml RL
79         working-directory: lightning-c-bindings
80         run: |
81           # Note that the version tags aren't checked into git
82           touch src/version.rs
83           RUSTFLAGS="--cfg=c_bindings" cargo check --features std
84       - name: Install cbindgen
85         run: |
86           git clone https://github.com/eqrion/cbindgen
87           cd cbindgen/
88           git checkout v0.20.0
89           cargo update -p indexmap --precise "1.6.2" --verbose
90           cargo install --locked --path .
91       - name: Checkout Rust-Lightning git
92         run: |
93           git clone https://github.com/rust-bitcoin/rust-lightning
94           cd rust-lightning
95           git checkout 0.0.115-bindings
96       - name: Fix Github Actions to not be broken
97         run: git config --global --add safe.directory /__w/ldk-c-bindings/ldk-c-bindings
98       - name: Fetch MacOS SDK
99         run: |
100           wget https://bitcoincore.org/depends-sources/sdks/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
101           tar xvvf Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers.tar.gz
102       - name: Rebuild bindings, and check the sample app builds + links
103         run: |
104           # rust-src doesn't distribute the rustlib Cargo.lock, but an empty
105           # file seems to suffice to make `-Zbuild-std` happy.
106           touch /usr/lib/rustlib/src/rust/Cargo.lock
107           MACOS_SDK="$PWD/Xcode-12.2-12B45b-extracted-SDK-with-libcxx-headers" ./genbindings.sh ./rust-lightning true
108
109   osx:
110     strategy:
111       matrix:
112         include:
113           - platform: macos-10.15
114           - platform: macos-11
115     runs-on: ${{ matrix.platform }}
116     env:
117       TOOLCHAIN: stable
118     steps:
119       - name: Install other Rust platforms
120         run: rustup target install aarch64-apple-darwin
121       - name: Fetch upstream LLVM/clang snapshot
122         run: |
123           wget -O clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.3/clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz
124           if [ "$(shasum -a 256 clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz | awk '{ print $1 }')" != "ac668586b2b3d068f1e43520a3ef0b1592e5dc3eff1a4a4b772e29803b428a69" ]; then
125             echo "Bad hash"
126             exit 1
127           fi
128       - name: Unpack upstream LLVM+clang and use it by default
129         run: |
130           tar xvvf clang+llvm-15.0.3-x86_64-apple-darwin.tar.xz
131       - name: Checkout source code
132         uses: actions/checkout@v2
133         with:
134           fetch-depth: 0
135       - name: Install cbindgen
136         run: cargo install cbindgen
137       - name: Checkout Rust-Lightning git
138         run: |
139           git clone https://github.com/rust-bitcoin/rust-lightning
140           cd rust-lightning
141           git checkout 0.0.115-bindings
142       - name: Rebuild bindings using Apple clang, and check the sample app builds + links
143         run: ./genbindings.sh ./rust-lightning true
144       - name: Rebuild bindings using upstream clang, and check the sample app builds + links
145         run: |
146           export PATH=`pwd`/clang+llvm-15.0.3-x86_64-apple-darwin/bin:$PATH
147           CC=clang ./genbindings.sh ./rust-lightning true