Skip to content

Commit dc74e82

Browse files
committed
Help out cargo when it forgets to provide compiler_builtins
1 parent a08363e commit dc74e82

File tree

1 file changed

+34
-1
lines changed
  • deterministic-build-wrappers

1 file changed

+34
-1
lines changed

deterministic-build-wrappers/rustc

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
args=("$@")
99
IS_LIGHTNING=false
1010
SKIP_EMBED_BITCODE=false
11+
MAY_NEED_COMPILER_BUILTINS=false
12+
DEP_PATH=""
1113
for ((i=0; i<"${#args[@]}"; ++i)); do
1214
case ${args[i]} in
1315
--crate-name)
1416
if [ "${args[i+1]}" = "lightning" -o "${args[i+1]}" = "lightning_types" -o "${args[i+1]}" = "lightning_background_processor" -o "${args[i+1]}" = "lightning_invoice" -o "${args[i+1]}" = "lightning_persister" -o "${args[i+1]}" = "lightning_rapid_gossip_sync" -o "${args[i+1]}" = "lightning_liquidity" -o "${args[i+1]}" = "lightning_transaction_sync" -o "${args[i+1]}" = "ldk" ]; then
1517
IS_LIGHTNING=true
18+
elif [ "${args[i+1]}" = "memchr" -o "${args[i+1]}" = "rustc_demangle" -o "${args[i+1]}" = "unwind" ]; then
19+
MAY_NEED_COMPILER_BUILTINS=true
1620
fi
1721
;;
1822
--crate-type)
@@ -22,6 +26,10 @@ for ((i=0; i<"${#args[@]}"; ++i)); do
2226
SKIP_EMBED_BITCODE=true
2327
fi
2428
;;
29+
--extern)
30+
IFS="=" PAIR=(${args[i+1]})
31+
DEP_PATH="$(dirname ${PAIR[1]})"
32+
;;
2533
esac
2634
done
2735
for ((i=0; i<"${#args[@]}"; ++i)); do
@@ -44,4 +52,29 @@ for ((i=0; i<"${#args[@]}"; ++i)); do
4452
;;
4553
esac
4654
done
47-
$LDK_RUSTC_PATH "${args[@]}"
55+
56+
# For some reason, sometimes when building with build-std cargo forgets to give crates a path to
57+
# their `compiler_builtin` dependencies. This obviously shouldn't happen but we fix it here.
58+
EXTRA_ARGS=()
59+
if [ "$MAY_NEED_COMPILER_BUILTINS" = "true" ]; then
60+
if [ -z "$DEP_PATH" ]; then
61+
echo "WARNING: Need at least one other dependency to know where to look, build may to fail if cargo is buggy" > /dev/stderr
62+
else
63+
COUNT=0
64+
CB_PATH="$(echo "$DEP_PATH"/libcompiler_builtins-*.rmeta)"
65+
while [ ! -f "$CB_PATH" ]; do
66+
# Wait until compiler_builtins finishes building...
67+
sleep 1
68+
COUNT="$(( $COUNT + 1 ))"
69+
if [ "$COUNT" -gt 120 ]; then
70+
echo "Took too long to get compiler_builtins built" > /dev/stderr
71+
exit 1
72+
fi
73+
CB_PATH="$(echo "$DEP_PATH"/libcompiler_builtins-*.rmeta)"
74+
done
75+
sleep 1
76+
EXTRA_ARGS=("--extern" compiler_builtins="$CB_PATH")
77+
fi
78+
fi
79+
80+
$LDK_RUSTC_PATH "${args[@]}" "${EXTRA_ARGS[@]}"

0 commit comments

Comments
 (0)