Re: [PATCH 1/2] kbuild: rust: add `CONFIG_RUSTC_LLVM_VERSION`

From: Miguel Ojeda
Date: Fri Oct 11 2024 - 02:59:20 EST


On Fri, Oct 11, 2024 at 4:04 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
>
> Please notice there is no reason to process
> rustc_version and rustc_llvm_version in the same script
> because they are completely independent.
> It even invokes "rustc --version" twice.
>
> If you implement it this way, you do not need to
> touch scripts/rustc-version.sh at all.
>
> If both rustc_version and rustc_llvm_version were
> retrieved from the single invocation of "rustc --version",
> I would agree "OK, it makes sense to implement it in the
> same script". But, it isn't.

Yeah, I think we can do that: one is `--verbose`, the other isn't, but
the verbose one should (hopefully) always contain the non-verbose as
the first line. Since it is in the first line, we can directly do the
`set` without having to "extract" that line -- something like [1]
below?

Independent scripts would be simpler, so that sounds good too.

By the way, this is a prerequisite for an actual fix we need, so I
would like to send it as part of a `rust-fixes` PR -- your Ack would
be great!

Cheers,
Miguel

[1]

if ! output=$("$@" --version --verbose 2>/dev/null); then
echo 0 0
exit 1
fi

set -- $output
rustc_version=$(get_rustc_canonical_version $2)

if ! output=$(echo "$output" | grep ^LLVM); then
echo $rustc_version 0
exit 1
fi

set -- $output
echo $rustc_version $(get_llvm_canonical_version $3)