Skip to content

Commit 7248fc9

Browse files
committed
Add all the manually-generated bits for the c-bindings crate
Including: * A script to automatically generate all the rest, * Cargo.toml and cbindgen.toml, * manually-written wrapper types for a few types
1 parent 186cc67 commit 7248fc9

File tree

7 files changed

+739
-0
lines changed

7 files changed

+739
-0
lines changed

genbindings.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
3+
set -e
4+
cd c-bindings-gen && cargo build && cd ..
5+
GEN="$(pwd)/c-bindings-gen/target/debug/c-bindings-gen"
6+
SRC="$(pwd)/lightning/src"
7+
OUT="$(pwd)/lightning-c-bindings/src"
8+
OUT_F="$(pwd)/lightning-c-bindings/include/rust_types.h"
9+
echo > $OUT_F
10+
11+
rm lightning-c-bindings/src/{ln,util,chain}/*
12+
RUST_BACKTRACE=1 $GEN $SRC/ $OUT/ lightning "" $OUT_F
13+
14+
cd lightning-c-bindings
15+
cargo build
16+
PATH="$PATH:~/.cargo/bin"
17+
cbindgen -v --config cbindgen.toml -o include/lightning.h
18+
gcc -static -pthread demo.c ../target/debug/liblightning.a -ldl
19+
echo "Bin size w/o optimization:"
20+
ls -lha a.out
21+
22+
cargo rustc -v --release -- -C lto
23+
clang -flto -O2 -static -pthread demo.c ../target/release/liblightning.a -ldl
24+
echo "Bin size with only RL optimized:"
25+
ls -lha a.out
26+
27+
cargo rustc -v --release -- -C linker-plugin-lto -C lto
28+
clang -flto -O2 -static -pthread demo.c ../target/release/liblightning.a -ldl
29+
echo "Bin size with cross-language LTO:"
30+
ls -lha a.out

lightning-c-bindings/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "lightning-c-bindings"
3+
version = "0.0.1"
4+
authors = ["Matt Corallo"]
5+
license = "Apache-2.0"
6+
edition = "2018"
7+
description = """
8+
Utilities to fetch the chain from Bitcoin Core REST/RPC Interfaces and feed them into Rust Lightning.
9+
"""
10+
11+
[lib]
12+
name = "lightning"
13+
crate-type = ["staticlib"]
14+
15+
[dependencies]
16+
bitcoin = "0.23"
17+
lightning = { version = "0.0.11", path = "../lightning" }

0 commit comments

Comments
 (0)