Skip to content

Commit 2eced1f

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

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

eng/common/native/init-compiler.sh

100644100755
Lines changed: 16 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..."
@@ -62,6 +64,7 @@ if [ -z "$CLR_CC" ]; then
6264

6365
# Set default versions
6466
if [ -z "$majorVersion" ]; then
67+
6568
# note: gcc (all versions) and clang versions higher than 6 do not have minor version in file name, if it is zero.
6669
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"
6770
elif [ "$compiler" = "gcc" ]; then versions="13 12 11 10 9 8 7 6 5 4.9"; fi
@@ -75,11 +78,14 @@ if [ -z "$CLR_CC" ]; then
7578

7679
if [ -z "$majorVersion" ]; then
7780
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
8181
CC="$(command -v "$compiler")"
8282
CXX="$(command -v "$cxxCompiler")"
83+
version="$("$CC" -dumpversion)"
84+
# gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
85+
IFS=. read -r majorVersion minorVersion patchVersion <<EOF
86+
$version
87+
EOF
88+
unset patchVersion
8389
else
8490
echo "No usable version of $compiler found."
8591
exit 1
@@ -88,7 +94,6 @@ if [ -z "$CLR_CC" ]; then
8894
if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ]; then
8995
if [ "$build_arch" = "arm" ] || [ "$build_arch" = "armel" ]; then
9096
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."
9297
CC="$(command -v "$compiler")"
9398
CXX="$(command -v "$cxxCompiler")"
9499
else
@@ -110,6 +115,12 @@ if [ -z "$CLR_CC" ]; then
110115
CC="$(command -v "$compiler$desired_version")"
111116
CXX="$(command -v "$cxxCompiler$desired_version")"
112117
if [ -z "$CXX" ]; then CXX="$(command -v "$cxxCompiler")"; fi
118+
version="$("$CC" -dumpversion)"
119+
# gcc and clang often display 3 part versions. However, gcc can show only 1 part in some environments.
120+
IFS=. read -r majorVersion minorVersion patchVersion <<EOF
121+
$version
122+
EOF
123+
unset patchVersion
113124
fi
114125
else
115126
if [ ! -f "$CLR_CC" ]; then

0 commit comments

Comments
 (0)