Skip to content

Commit 078a9fb

Browse files
committed
WIP: another workaround for hardcoded compiler versions
1 parent 7def0b7 commit 078a9fb

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

eng/common/native/init-compiler.sh

100644100755
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
# This file detects the C/C++ compiler and exports it to the CC/CXX environment variables
44
#
5-
# NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here!
5+
# NOTE: some scripts source this file and rely on stdout being empty, make sure
6+
# to not output *anything* here, unless it is an error message that fails the
7+
# build.
68

79
if [ -z "$build_arch" ] || [ -z "$compiler" ]; then
810
echo "Usage..."
@@ -58,10 +60,25 @@ check_version_exists() {
5860
echo "$desired_version"
5961
}
6062

63+
set_compiler_version_from_CC() {
64+
local patchVersion
65+
version="$("$CC" -dumpversion)"
66+
if [ "$version" = "" ]; then
67+
echo "$CC -dumpversion didn't provide a version"
68+
exit 1
69+
fi
70+
# gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
71+
IFS=. read -r majorVersion minorVersion patchVersion <<EOF
72+
$version
73+
EOF
74+
unset patchVersion
75+
}
76+
6177
if [ -z "$CLR_CC" ]; then
6278

6379
# Set default versions
6480
if [ -z "$majorVersion" ]; then
81+
6582
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
6683
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"
6784
elif [ "$compiler" = "gcc" ]; then versions="13 12 11 10 9 8 7 6 5 4.9"; fi
@@ -75,11 +92,9 @@ if [ -z "$CLR_CC" ]; then
7592

7693
if [ -z "$majorVersion" ]; then
7794
if command -v "$compiler" > /dev/null; then
78-
if [ "$(uname)" != "Darwin" ]; then
79-
echo "Warning: Specific version of $compiler not found, falling back to use the one in PATH."
80-
fi
8195
CC="$(command -v "$compiler")"
8296
CXX="$(command -v "$cxxCompiler")"
97+
set_compiler_version_from_CC
8398
else
8499
echo "No usable version of $compiler found."
85100
exit 1
@@ -88,9 +103,9 @@ if [ -z "$CLR_CC" ]; then
88103
if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ]; then
89104
if [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; then
90105
if command -v "$compiler" > /dev/null; then
91-
echo "Warning: Found clang version $majorVersion which is not supported on arm/armel architectures, falling back to use clang from PATH."
92106
CC="$(command -v "$compiler")"
93107
CXX="$(command -v "$cxxCompiler")"
108+
set_compiler_version_from_CC
94109
else
95110
echo "Found clang version $majorVersion which is not supported on arm/armel architectures, and there is no clang in PATH."
96111
exit 1
@@ -110,6 +125,7 @@ if [ -z "$CLR_CC" ]; then
110125
CC="$(command -v "$compiler$desired_version")"
111126
CXX="$(command -v "$cxxCompiler$desired_version")"
112127
if [ -z "$CXX" ]; then CXX="$(command -v "$cxxCompiler")"; fi
128+
set_compiler_version_from_CC
113129
fi
114130
else
115131
if [ ! -f "$CLR_CC" ]; then
@@ -118,6 +134,7 @@ else
118134
fi
119135
CC="$CLR_CC"
120136
CXX="$CLR_CXX"
137+
set_compiler_version_from_CC
121138
fi
122139

123140
if [ -z "$CC" ]; then

0 commit comments

Comments
 (0)