Make build output deterministic by remapping paths
[ldk-c-bindings] / genbindings.sh
index 6358e30d59d4cad1ba979c21635f8357f9c0361c..ee46f4e6aad5a3c3d4739a69ca0e5ac37cb9b0f4 100755 (executable)
@@ -7,7 +7,12 @@ if [ ! -d "$1/lightning" ]; then
        echo "USAGE: $0 path-to-rust-lightning"
        exit 1
 fi
-LIGHTNING_PATH="$(realpath "$1/lightning")"
+
+# On reasonable systems, we can use realpath here, but OSX is a diva with 20-year-old software.
+ORIG_PWD="$(pwd)"
+cd "$1/lightning"
+LIGHTNING_PATH="$(pwd)"
+cd "$ORIG_PWD"
 
 # Generate (and reasonably test) C bindings
 
@@ -45,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