Skip to content

Commit 253af8d

Browse files
authored
Merge pull request #618 from TheBlueMatt/2020-05-sample-c-bindings
C/C++ Bindings
2 parents 2dd8b3e + 0ab7f90 commit 253af8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+26438
-9
lines changed

.github/workflows/build.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ jobs:
1717
include:
1818
- toolchain: stable
1919
build-net-tokio: true
20+
build-bindings: true
2021
- toolchain: beta
2122
build-net-tokio: true
23+
build-bindings: true
2224
- toolchain: 1.39.0
2325
build-net-tokio: true
26+
build-bindings: true
2427
coverage: true
28+
- toolchain: 1.34.2
29+
build-bindings: true
2530
runs-on: ubuntu-latest
2631
steps:
2732
- name: Checkout source code
@@ -38,6 +43,9 @@ jobs:
3843
- name: Build on Rust ${{ matrix.toolchain }}
3944
if: "! matrix.build-net-tokio"
4045
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
4149
- name: Test on Rust ${{ matrix.toolchain }} with net-tokio
4250
if: matrix.build-net-tokio
4351
run: RUSTFLAGS="-C link-dead-code" cargo test --verbose --color always
@@ -98,3 +106,48 @@ jobs:
98106
run: cd fuzz && cargo test --verbose --color always
99107
- name: Run fuzzers
100108
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

Cargo.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,17 @@
33
members = [
44
"lightning",
55
"lightning-net-tokio",
6+
"lightning-c-bindings",
67
]
78

89
# Our tests do actual crypo and lots of work, the tradeoff for -O1 is well worth it
9-
[profile.dev]
10+
[profile.test]
1011
opt-level = 1
12+
13+
[profile.dev]
14+
panic = "abort"
15+
16+
[profile.release]
17+
opt-level = 3
18+
lto = true
19+
panic = "abort"

c-bindings-gen/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "c-bindings-gen"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
syn = { version = "1", features = ["full", "extra-traits"] }
9+
proc-macro2 = "1"
10+
11+
# We're not in the workspace as we're just a binary code generator:
12+
[workspace]

0 commit comments

Comments
 (0)