Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded list of compiler versions in init-compiler.sh #14696

Merged

Conversation

omajid
Copy link
Member

@omajid omajid commented Apr 5, 2024

If a version-specific compiler (eg, clang-17) is passed to the script, it works as before. However, if a generic compiler (eg, clang) is passed to the script, it uses the version in $PATH. This is a change from earlier, where it was iterating through a known list of versions to find the latest version of the compiler and using that.

This change can break or modify existing build scenarios where the following are all true:

  • The script is called with a generic compiler name, without a version
  • Multiple versions of compilers are installed on the system
  • The default compiler ($compiler) is not the latest version

In this scenario, an older version of the compiler will be used, which may not be desired.

With a generic compiler, this script now also invokes it via $compiler -dumpversion (which works on both clang and gcc) to find the version for various (existing) version checks. The compiler was already being invoked to check if -fuse-ld=lld is supported.

Fixes: #14632

@omajid omajid force-pushed the remove-hardcoded-compiler-list-init-compiler branch from d8e7a35 to 6f4c49a Compare April 5, 2024 15:23
@omajid omajid marked this pull request as ready for review April 5, 2024 19:49
@omajid
Copy link
Member Author

omajid commented Apr 5, 2024

I tested building the VMR on Fedora with this. That worked. Any particular environments I should try out?

@omajid
Copy link
Member Author

omajid commented Apr 5, 2024

cc @akoeplinger @janvorli @tmds

omajid added a commit to omajid/dotnet-runtime that referenced this pull request Apr 8, 2024
akoeplinger
akoeplinger previously approved these changes Apr 8, 2024
EOF
unset patchVersion

if [ "$compiler" = "clang" ] && [ "$majorVersion" -lt 5 ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the old script errored for clang < 3.5 and gcc < 4.9, I think those are probably old enough that we don't need to care, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release dates:

These will be more than 10 years old by the time of .NET 9 GA. I am okay with dropping these both.

@akoeplinger
Copy link
Member

/cc @am11

@akoeplinger
Copy link
Member

akoeplinger commented Apr 8, 2024

I tested building the VMR on Fedora with this. That worked. Any particular environments I should try out?

Building runtime should be a good test case, I see you're hitting some issues in dotnet/runtime#100761 so let's hold off on merging this.

@am11
Copy link
Member

am11 commented Apr 8, 2024

The rationale behind having explicit versions was @janvorli's: we validate each version before adding it to the list. We do not want to use any version on the PATH. That's why we have maintained it this way over years.

@akoeplinger
Copy link
Member

Yeah he mentioned that in #14572 (comment).

I don't think it's worth being explicit anymore, especially given that we use clang from PATH on macOS and Apple ships new clang releases constantly so we need to fix issues anyway and there's also still the option of setting CLR_CC=clang-XX to override the detection.

@am11
Copy link
Member

am11 commented Apr 8, 2024

Apple versions are always behind the Linux versions in our environments.

@omajid
Copy link
Member Author

omajid commented Apr 11, 2024

I have reworked the change entirely. Please see the new commit message:

    Make init-compiler.sh fall back to and work with generic compiler
    
    If a version-specific compiler (eg, clang-17) is passed to the script,
    it works as before. And like before, if a generic compiler (eg clang) is
    passed to the script, it prefers to find and use the few
    specific/known/tested versions of compilers (eg, clang means use
    clang-18 if possible). However, unlike before, if none of those specific
    known versions are found, it correctly falls back to the generic
    compiler binary (eg clang) in $PATH.
    
    The script was actually supposed to do all this already, but it seems to
    have been broken when warning messages were added. These warning
    messages were parsed by msbuild. Msbuild would see the warning messages
    and fail the build.
    
    With a generic compiler, this script now also invokes it via $compiler
    -dumpversion (which works on both clang and gcc) to find the version for
    various (existing) version checks. The compiler was already being
    invoked to check if -fuse-ld=lld is supported.
    
    Fixes: #14632

And here's CI exercising the change: dotnet/runtime#100828

@omajid omajid force-pushed the remove-hardcoded-compiler-list-init-compiler branch 3 times, most recently from 6e5805f to a3c7a59 Compare April 11, 2024 21:38
If a version-specific compiler (eg, clang-17) is passed to the script,
it works as before. And like before, if a generic compiler (eg clang) is
passed to the script, it prefers to find and use the few
specific/known/tested versions of compilers (eg, clang means use
clang-18 if possible). However, unlike before, if none of those specific
known versions are found, it correctly falls back to the generic
compiler binary (eg clang) in $PATH.

The script was actually supposed to do all this already, but it seems to
have been broken when warning messages were added. These warning
messages were parsed by msbuild. Msbuild would see the warning messages
and fail the build.

With a generic compiler, this script now also invokes it via $compiler
-dumpversion (which works on both clang and gcc) to find the version for
various (existing) version checks. The compiler was already being
invoked to check if -fuse-ld=lld is supported.

Fixes: dotnet#14632
@omajid omajid force-pushed the remove-hardcoded-compiler-list-init-compiler branch from a3c7a59 to b8698e4 Compare April 12, 2024 16:01
@omajid
Copy link
Member Author

omajid commented Apr 19, 2024

Any further thoughts or comments? Is this okay to go in?

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@janvorli janvorli merged commit 65fb7aa into dotnet:main Apr 23, 2024
11 checks passed
akoeplinger added a commit that referenced this pull request Apr 23, 2024
@akoeplinger
Copy link
Member

We're seeing a build break caused by this in dotnet/installer#19562, reverting this for now: #14734

       Commencing build of "install" target in "native libraries component" for iossimulator.arm64.Release in /Users/runner/work/1/vmr/src/runtime/artifacts/obj/native/net9.0-iossimulator-Release-arm64
      Invoking "/Users/runner/work/1/vmr/src/runtime/eng/native/gen-buildsys.sh" "/Users/runner/work/1/vmr/src/runtime/src/native/libs" "/Users/runner/work/1/vmr/src/runtime/artifacts/obj/native/net9.0-iossimulator-Release-arm64" arm64 iossimulator clang Release ""  -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 -C /Users/runner/work/1/vmr/src/runtime/eng/native/tryrun_ios_tvos.cmake -DCMAKE_USE_PTHREADS=0 -DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0 
    EXEC : error : Specific version of clang not found [/Users/runner/work/1/vmr/src/runtime/src/native/libs/build-native.proj]
      Failed to generate "native libraries component" build project!

else
echo "No usable version of $compiler found."
if [ "$(uname)" == "Darwin" ]; then
echo "Error: Specific version of $compiler not found"
exit 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be "$(uname)" != "Darwin? we won't have majorVersion set on Darwin.
It should also stay a warning and not fail the build on other platforms I think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good point. Let me think about this some more.

Any warning printed by this script (especially if it is prefixed by error: or warning:) will fail the build.

@jakubch1
Copy link
Member

jakubch1 commented Apr 23, 2024

This change caused issue in coverage repo on macOS:

EXEC : error : Specific version of clang not found [/Users/runner/work/1/s/src/Microsoft.CleverTestsSelection.InstrumentationMethod/Microsoft.CleverTestsSelection.InstrumentationMethod.proj]
##[error]EXEC(0,0): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Specific version of clang not found

before this change output was:

  -- The CXX compiler identification is AppleClang 13.0.0.13000029
  -- The CXX compiler identification is AppleClang 13.0.0.13000029

I've tried to specify: clang-13 and clang-13.0 but also got errors. Any suggestion how I can fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow building with newer clang versions without changing init-compilers.sh.
5 participants