Skip to content

Commit bcbf891

Browse files
committed
Make build output deterministic by remapping paths
1 parent 4d85902 commit bcbf891

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

deterministic-build-wrappers/rustc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
# rustc calculates a unique metadata tag to mangle symbols which includes the
3+
# actual path to the crate. This breaks our deterministic builds as we depend
4+
# on a copy of rust-lightning via a path. We insert this shim between cargo and
5+
# rustc and edit the metadata tag for rust-lightning.
6+
# While we could just set RUSTFLAGS="-C metadata=42", this would break if we
7+
# ever (indirectly) depend on multiple versions of the same crate.
8+
args=("$@")
9+
IS_LIGHTNING=false
10+
for ((i=0; i<"${#args[@]}"; ++i)); do
11+
case ${args[i]} in
12+
--crate-name)
13+
if [ "${args[i+1]}" = "lightning" ]; then
14+
IS_LIGHTNING=true
15+
fi
16+
;;
17+
esac
18+
done
19+
for ((i=0; i<"${#args[@]}"; ++i)); do
20+
case ${args[i]} in
21+
metadata*)
22+
if [ "$IS_LIGHTNING" = "true" ]; then
23+
# Pick any random value for metadata, it doesn't matter
24+
args[i]="metadata=42"
25+
fi
26+
;;
27+
esac
28+
done
29+
30+
/usr/bin/rustc "${args[@]}"

genbindings.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ else
5050
sed -i 's|lightning = { .*|lightning = { path = "'"$LIGHTNING_PATH"'" }|' lightning-c-bindings/Cargo.toml
5151
fi
5252

53+
# Set path to include our rustc wrapper as well as cbindgen
54+
PATH="$(pwd)/deterministic-build-wrappers:$PATH:~/.cargo/bin"
5355
# Now cd to lightning-c-bindings, build the generated bindings, and call cbindgen to build a C header file
54-
PATH="$PATH:~/.cargo/bin"
5556
cd lightning-c-bindings
57+
# Remap paths so that our builds are deterministic
58+
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"
59+
export CFLAGS="-ffile-prefix-map=$HOME/.cargo="
60+
5661
cargo build
5762
cbindgen -v --config cbindgen.toml -o include/lightning.h >/dev/null 2>&1
5863

0 commit comments

Comments
 (0)