From: Matt Corallo Date: Tue, 23 Mar 2021 04:46:03 +0000 (-0400) Subject: Make build output deterministic by remapping paths X-Git-Tag: v0.0.98~20^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bcbf891d3fd4452080692bbb980864ceeaeb0736;p=ldk-c-bindings Make build output deterministic by remapping paths --- diff --git a/deterministic-build-wrappers/rustc b/deterministic-build-wrappers/rustc new file mode 100755 index 0000000..2f35677 --- /dev/null +++ b/deterministic-build-wrappers/rustc @@ -0,0 +1,30 @@ +#!/bin/bash +# rustc calculates a unique metadata tag to mangle symbols which includes the +# actual path to the crate. This breaks our deterministic builds as we depend +# on a copy of rust-lightning via a path. We insert this shim between cargo and +# rustc and edit the metadata tag for rust-lightning. +# While we could just set RUSTFLAGS="-C metadata=42", this would break if we +# ever (indirectly) depend on multiple versions of the same crate. +args=("$@") +IS_LIGHTNING=false +for ((i=0; i<"${#args[@]}"; ++i)); do + case ${args[i]} in + --crate-name) + if [ "${args[i+1]}" = "lightning" ]; then + IS_LIGHTNING=true + fi + ;; + esac +done +for ((i=0; i<"${#args[@]}"; ++i)); do + case ${args[i]} in + metadata*) + if [ "$IS_LIGHTNING" = "true" ]; then + # Pick any random value for metadata, it doesn't matter + args[i]="metadata=42" + fi + ;; + esac +done + +/usr/bin/rustc "${args[@]}" diff --git a/genbindings.sh b/genbindings.sh index 0d8a691..ee46f4e 100755 --- a/genbindings.sh +++ b/genbindings.sh @@ -50,9 +50,14 @@ else sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml fi +# Set path to include our rustc wrapper as well as cbindgen +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 -PATH="$PATH:~/.cargo/bin" 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" +export CFLAGS="-ffile-prefix-map=$HOME/.cargo=" + cargo build cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1