X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=genbindings.sh;h=e85f14af5ac35e798fd34ab689bf4d55676e5b34;hb=80651edc00530ffa94cee1027d97291913865ab2;hp=7a876312ae2cc818533225ca81326e8f48adc526;hpb=ef46cb1ace8cbea503488436e0c3aa2df349e382;p=ldk-c-bindings diff --git a/genbindings.sh b/genbindings.sh index 7a87631..e85f14a 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -87,9 +87,16 @@ fi PATH="$(pwd)/deterministic-build-wrappers:$PATH:~/.cargo/bin" # Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file cd lightning-c-bindings + # Remap paths so that our builds are deterministic export RUSTFLAGS="--remap-path-prefix $LIGHTNING_PATH=rust-lightning --remap-path-prefix $(pwd)=ldk-c-bindings --remap-path-prefix $HOME/.cargo= -C target-cpu=generic" + +# If the C compiler supports it, also set -ffile-prefix-map +echo "int main() {}" > genbindings_path_map_test_file.c +clang -o /dev/null -ffile-prefix-map=$HOME/.cargo= genbindings_path_map_test_file.c > /dev/null 2>&1 && +# Now that we've done our last non-LTO build, turn on LTO in CFLAGS as well export CFLAGS="-ffile-prefix-map=$HOME/.cargo=" +rm genbindings_path_map_test_file.c cargo build cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1 @@ -271,7 +278,11 @@ if [ "$HOST_PLATFORM" != "host: x86_64-apple-darwin" -a "$CLANGPP" != "" ]; then # or Ubuntu packages). This should work fine on Distros which do more involved # packaging than simply shipping the rustup binaries (eg Debian should Just Work # here). - export CFLAGS="$CFLAGS -flto" + # The cc-rs crate tries to force -fdata-sections and -ffunction-sections on, which + # breaks -fembed-bitcode, so we turn off cc-rs' default flags and specify exactly + # what we want here. + export CFLAGS="$CFLAGS -O3 -fPIC -fembed-bitcode" + export CRATE_CC_NO_DEFAULTS=true # Rust doesn't recognize CFLAGS changes, so we need to clean build artifacts cargo clean --release CARGO_PROFILE_RELEASE_LTO=true cargo rustc -v --release -- -C linker-plugin-lto -C lto -C link-arg=-fuse-ld=lld