Skip to content

Commit da072ea

Browse files
committed
Calculate version range in init-compiler.sh script
1 parent 3648b56 commit da072ea

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

eng/common/native/init-compiler.sh

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ case "$compiler" in
2424
if [ -z "$minorVersion" ] && [ -n "$majorVersion" ] && [ "$majorVersion" -le 6 ]; then
2525
minorVersion=0;
2626
fi
27+
28+
# LLVM based on v18 released in early 2024, with two releases per year
29+
maxVersion="$((18 + ((($(date +%Y) - 2024) * 12 + $(date +%m) - 3) / 6)))"
2730
compiler=clang
2831
;;
2932

@@ -32,6 +35,9 @@ case "$compiler" in
3235
version="$(echo "$compiler" | tr -d '[:alpha:]-=')"
3336
majorVersion="${version%%.*}"
3437
[ -z "${version##*.*}" ] && minorVersion="${version#*.}"
38+
39+
# GCC based on v14 released in early 2024, with one release per year
40+
maxVersion="$((14 + ((($(date +%Y) - 2024) * 12 + $(date +%m) - 3) / 12)))"
3541
compiler=gcc
3642
;;
3743
esac
@@ -84,38 +90,25 @@ if [ -z "$CLR_CC" ]; then
8490

8591
# Set default versions
8692
if [ -z "$majorVersion" ]; then
87-
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
88-
if [ "$compiler" = "clang" ]; then versions="18 17 16 15 14 13 12 11 10 9 8 7 6.0 5.0 4.0 3.9 3.8 3.7 3.6 3.5"
89-
elif [ "$compiler" = "gcc" ]; then versions="14 13 12 11 10 9 8 7 6 5 4.9"; fi
90-
91-
for version in $versions; do
93+
i="$((maxVersion + 1))" # +1 for headspace
94+
minVersion=8
95+
while [ "$i" -ge $minVersion ]; do
9296
_major="${version%%.*}"
9397
[ -z "${version##*.*}" ] && _minor="${version#*.}"
9498
desired_version="$(check_version_exists "$_major" "$_minor")"
9599
if [ "$desired_version" != "-1" ]; then majorVersion="$_major"; break; fi
100+
i=$((i - 1))
96101
done
97102

98103
if [ -z "$majorVersion" ]; then
99104
if ! command -v "$compiler" > /dev/null; then
100-
echo "Error: No usable version of $compiler found."
105+
echo "Error: No compatible version of $compiler was found within the range of $minVersion to $maxVersion. Please upgrade your toolchain or specify the compiler explicitly using CLR_CC and CLR_CXX environment variables."
101106
exit 1
102107
fi
103108

104109
CC="$(command -v "$compiler" 2> /dev/null)"
105110
CXX="$(command -v "$cxxCompiler" 2> /dev/null)"
106111
set_compiler_version_from_CC
107-
else
108-
if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ] && { [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; }; then
109-
# If a major version was provided explicitly, and it was too old, find a newer compiler instead
110-
if ! command -v "$compiler" > /dev/null; then
111-
echo "Error: Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
112-
exit 1
113-
fi
114-
115-
CC="$(command -v "$compiler" 2> /dev/null)"
116-
CXX="$(command -v "$cxxCompiler" 2> /dev/null)"
117-
set_compiler_version_from_CC
118-
fi
119112
fi
120113
else
121114
desired_version="$(check_version_exists "$majorVersion" "$minorVersion")"

0 commit comments

Comments
 (0)