rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
#!@shell@
|
|
|
|
|
2023-12-17 00:22:04 +00:00
|
|
|
defaultSysroot=(@sysroot@)
|
|
|
|
|
|
|
|
for arg; do
|
|
|
|
case "$arg" in
|
2024-01-27 18:01:40 +00:00
|
|
|
--sysroot|--sysroot=*)
|
2023-12-17 00:22:04 +00:00
|
|
|
defaultSysroot=()
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2024-02-28 22:10:07 +00:00
|
|
|
extraBefore=(@defaultArgs@ "${defaultSysroot[@]}")
|
2024-03-02 12:03:26 +00:00
|
|
|
extraAfter=($@extraFlagsVar@)
|
2023-11-16 11:19:36 +00:00
|
|
|
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
# Optionally print debug info.
|
|
|
|
if (( "${NIX_DEBUG:-0}" >= 1 )); then
|
2023-11-16 11:19:36 +00:00
|
|
|
echo "extra flags before to @prog@:" >&2
|
|
|
|
printf " %q\n" "${extraBefore[@]}" >&2
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
echo "original flags to @prog@:" >&2
|
|
|
|
printf " %q\n" "$@" >&2
|
|
|
|
echo "extra flags after to @prog@:" >&2
|
2023-11-16 11:19:36 +00:00
|
|
|
printf " %q\n" "${extraAfter[@]}" >&2
|
rustc: add a compiler wrapper
We keep running into situations where we can't get the right
combination of rustc flags through build systems into rustc.
RUSTFLAGS is the only variable supported across build systems, but if
RUSTFLAGS is set, Cargo will ignore all other ways of specifying rustc
flags, including the target-specific ones, which we need to make
dynamic musl builds work. (This is why pkgsCross.musl64.crosvm is
currently broken — it works if you unset separateDebugInfo, which
causes RUSTFLAGS not to be set.)
So, we need to do the same thing we do for C and C++ compilers, and
add a compiler wrapper so we can inject the flags we need, regardless
of the build system.
Currently the wrapper only supports a single mechanism for injecting
flags — the NIX_RUSTFLAGS environment variable. As time goes on,
we'll probably want to add additional features, like target-specific
environment variables.
2023-10-18 11:02:45 +00:00
|
|
|
fi
|
|
|
|
|
2023-11-16 11:19:36 +00:00
|
|
|
exec @prog@ "${extraBefore[@]}" "$@" "${extraAfter[@]}"
|