-
Notifications
You must be signed in to change notification settings - Fork 45
/
no_meta_rustc_wrapper.sh
executable file
·46 lines (40 loc) · 1.46 KB
/
no_meta_rustc_wrapper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
# Licensed under the Apache-2.0 license
set -e
is_firmware="false"
for arg in "$@"; do
if [[ ${last_arg} == "--target" ]] && [[ ${arg} == "riscv32imc-unknown-none-elf" ]]; then
is_firmware="true"
fi
last_arg="${arg}"
done
if [[ $is_firmware == "false" ]]; then
# Don't do anything special for non-firmware targets.
exec "$@"
exit $?
fi
# rustc accepts a "-C metadata=<DATA>" flag, which is use to feed entropy into the
# name mangling hash. This is useful in complex Rust software that imports
# multiple versions of the same crate, as the hash prevents symbol collisions.
# Unfortunately, Cargo mixes the identity of non-firmware dependencies like
# openssl used by build.rs into this hash. There is no way to opt out other
# than rewriting the rustc arguments with a RUSTC_WRAPPER script (this
# solution), or using a build system other than Cargo.
#
# We can't allow the name mangling hash to change, as that can cause some
# symbols to be re-ordered by the linker when otherwise
# non-firmware-binary-affecting build-time deps like openssl are upgraded (for
# security fixes and whatnot).
#
# See https://doc.rust-lang.org/rustc/codegen-options/index.html#metadata for
# more information
args=()
for arg in "$@"; do
if [[ ${#args[@]} -gt 0 ]] && [[ ${args[${#args[@]}-1]} == "-C" ]] && [[ ${arg} == metadata=* ]]; then
# Remove -C
unset 'args[${#args[@]}-1]'
else
args+=("${arg}")
fi
done
exec "${args[@]}"