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

[CMake]Fully delete the deprecated LLVM_USE_CRT* #66850

Merged
merged 1 commit into from
Sep 21, 2023
Merged

[CMake]Fully delete the deprecated LLVM_USE_CRT* #66850

merged 1 commit into from
Sep 21, 2023

Conversation

Naville
Copy link
Contributor

@Naville Naville commented Sep 20, 2023

This has been deprecated in favor of CMake's CMAKE_MSVC_RUNTIME_LIBRARY in c6bd873 .
Current release branch still contains it in deprecated status so no existing end-users will be affected

@llvmbot llvmbot added cmake Build system in general and CMake in particular clang Clang issues not falling into any other category labels Sep 20, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 20, 2023

@llvm/pr-subscribers-clang

Changes

Ref

Notes

  • ChooseMSVCCRT.cmake is the automatic translation layer that's been completely removed
  • The old implementation seems to support MultiConfiguration generators that I personally don't use , so some guidance from the reviewer on that topic would help
  • The CRT allocator code has already been fixed to not use LLVM_USE_CRT

Full diff: https://github.com/llvm/llvm-project/pull/66850.diff

7 Files Affected:

  • (modified) clang/cmake/caches/CrossWinToARMLinux.cmake (-1)
  • (modified) clang/cmake/caches/Fuchsia-stage2.cmake (-1)
  • (modified) clang/cmake/caches/Fuchsia.cmake (-4)
  • (removed) llvm/cmake/modules/ChooseMSVCCRT.cmake (-58)
  • (modified) llvm/cmake/modules/HandleLLVMOptions.cmake (+1-2)
  • (modified) llvm/cmake/modules/LLVMConfig.cmake.in (+1-4)
  • (modified) llvm/docs/CMake.rst (-6)
diff --git a/clang/cmake/caches/CrossWinToARMLinux.cmake b/clang/cmake/caches/CrossWinToARMLinux.cmake
index e6f5650eac4668f..bbb4b9e71be2d3d 100644
--- a/clang/cmake/caches/CrossWinToARMLinux.cmake
+++ b/clang/cmake/caches/CrossWinToARMLinux.cmake
@@ -95,7 +95,6 @@ set(CLANG_DEFAULT_LINKER                    "lld" CACHE STRING "")
 
 if(WIN32)
   set(CMAKE_MSVC_RUNTIME_LIBRARY            "MultiThreaded" CACHE STRING "")
-  set(LLVM_USE_CRT_RELEASE                  "MT" CACHE STRING "")
 endif()
 
 # Set up RPATH for the target runtime/builtin libraries.
diff --git a/clang/cmake/caches/Fuchsia-stage2.cmake b/clang/cmake/caches/Fuchsia-stage2.cmake
index bc4d9f1462b1814..803d41a2c87179a 100644
--- a/clang/cmake/caches/Fuchsia-stage2.cmake
+++ b/clang/cmake/caches/Fuchsia-stage2.cmake
@@ -30,7 +30,6 @@ set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
 set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")
 
 if(WIN32)
-  set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
   set(FUCHSIA_DISABLE_DRIVER_BUILD ON)
 endif()
 
diff --git a/clang/cmake/caches/Fuchsia.cmake b/clang/cmake/caches/Fuchsia.cmake
index c599f141f9e5b1b..9c68be0bfe54b69 100644
--- a/clang/cmake/caches/Fuchsia.cmake
+++ b/clang/cmake/caches/Fuchsia.cmake
@@ -70,10 +70,6 @@ foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
   endif()
 endforeach()
 
-if(WIN32)
-  set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
-endif()
-
 set(CLANG_DEFAULT_CXX_STDLIB libc++ CACHE STRING "")
 set(CLANG_DEFAULT_LINKER lld CACHE STRING "")
 set(CLANG_DEFAULT_OBJCOPY llvm-objcopy CACHE STRING "")
diff --git a/llvm/cmake/modules/ChooseMSVCCRT.cmake b/llvm/cmake/modules/ChooseMSVCCRT.cmake
deleted file mode 100644
index 6d52ac97bac2092..000000000000000
--- a/llvm/cmake/modules/ChooseMSVCCRT.cmake
+++ /dev/null
@@ -1,58 +0,0 @@
-# The macro choose_msvc_crt() takes a list of possible
-# C runtimes to choose from, in the form of compiler flags,
-# to present to the user. (MTd for /MTd, etc)
-#
-# The macro is invoked at the end of the file.
-#
-# This mechanism is deprecated, but kept for transitioning users.
-#
-# This reads the LLVM_USE_CRT_<CONFIG> options and sets
-# CMAKE_MSVC_RUNTIME_LIBRARY accordingly. The previous mechanism allowed
-# setting different choices for different build configurations (for
-# multi-config generators), but translating multiple differing choices to
-# the corresponding CMAKE_MSVC_RUNTIME_LIBRARY generator expression isn't
-# supported by this transitional helper.
-
-macro(choose_msvc_crt MSVC_CRT)
-  if(LLVM_USE_CRT)
-    message(FATAL_ERROR
-      "LLVM_USE_CRT is deprecated. Use the CMAKE_BUILD_TYPE-specific
-variables (LLVM_USE_CRT_DEBUG, etc) instead.")
-  endif()
-
-  foreach(build_type ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE})
-    string(TOUPPER "${build_type}" build)
-    if (NOT "${LLVM_USE_CRT_${build}}" STREQUAL "")
-      if (NOT ${LLVM_USE_CRT_${build}} IN_LIST ${MSVC_CRT})
-        message(FATAL_ERROR
-          "Invalid value for LLVM_USE_CRT_${build}: ${LLVM_USE_CRT_${build}}. Valid options are one of: ${${MSVC_CRT}}")
-      endif()
-      set(library "MultiThreaded")
-      if ("${LLVM_USE_CRT_${build}}" MATCHES "d$")
-        set(library "${library}Debug")
-      endif()
-      if ("${LLVM_USE_CRT_${build}}" MATCHES "^MD")
-        set(library "${library}DLL")
-      endif()
-      if(${runtime_library_set})
-        message(WARNING "Conflicting LLVM_USE_CRT_* options")
-      else()
-        message(WARNING "The LLVM_USE_CRT_* options are deprecated, use the CMake provided CMAKE_MSVC_RUNTIME_LIBRARY setting instead")
-      endif()
-      set(CMAKE_MSVC_RUNTIME_LIBRARY "${library}" CACHE STRING "" FORCE)
-      message(STATUS "Using VC++ CRT: ${CMAKE_MSVC_RUNTIME_LIBRARY}")
-      set(runtime_library_set 1)
-    endif()
-  endforeach(build_type)
-endmacro(choose_msvc_crt MSVC_CRT)
-
-
-# List of valid CRTs for MSVC
-set(MSVC_CRT
-  MD
-  MDd
-  MT
-  MTd)
-
-choose_msvc_crt(MSVC_CRT)
-
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 4e87c6d1c3eb868..f72c41aaffb5061 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -470,7 +470,6 @@ endif()
 option(LLVM_ENABLE_WARNINGS "Enable compiler warnings." ON)
 
 if( MSVC )
-  include(ChooseMSVCCRT)
 
   # Add definitions that make MSVC much less annoying.
   add_compile_definitions(
@@ -951,7 +950,7 @@ if(LLVM_USE_SANITIZER)
       endif()
       # Prepare ASAN runtime if needed
       if (LLVM_USE_SANITIZER MATCHES ".*Address.*")
-        if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
+        if (${CMAKE_MSVC_RUNTIME_LIBRARY} MATCHES "^(MultiThreaded|MultiThreadedDebug)$")
           append("/wholearchive:clang_rt.asan-${arch}.lib /wholearchive:clang_rt.asan_cxx-${arch}.lib"
             CMAKE_EXE_LINKER_FLAGS)
           append("/wholearchive:clang_rt.asan_dll_thunk-${arch}.lib"
diff --git a/llvm/cmake/modules/LLVMConfig.cmake.in b/llvm/cmake/modules/LLVMConfig.cmake.in
index 42dfd607f7e651a..5465e981f235545 100644
--- a/llvm/cmake/modules/LLVMConfig.cmake.in
+++ b/llvm/cmake/modules/LLVMConfig.cmake.in
@@ -14,10 +14,7 @@ set(LLVM_PACKAGE_BUGREPORT @PACKAGE_BUGREPORT@)
 
 set(LLVM_BUILD_TYPE @CMAKE_BUILD_TYPE@)
 
-set(LLVM_USE_CRT_DEBUG @LLVM_USE_CRT_DEBUG@)
-set(LLVM_USE_CRT_MINSIZEREL @LLVM_USE_CRT_MINSIZEREL@)
-set(LLVM_USE_CRT_RELEASE @LLVM_USE_CRT_RELEASE@)
-set(LLVM_USE_CRT_RELWITHDEBINFO @LLVM_USE_CRT_RELWITHDEBINFO@)
+set(CMAKE_MSVC_RUNTIME_LIBRARY @CMAKE_MSVC_RUNTIME_LIBRARY@)
 
 set(LLVM_USE_SPLIT_DWARF @LLVM_USE_SPLIT_DWARF@)
 
diff --git a/llvm/docs/CMake.rst b/llvm/docs/CMake.rst
index 67f740447ed7bfb..4d894212fb11d47 100644
--- a/llvm/docs/CMake.rst
+++ b/llvm/docs/CMake.rst
@@ -777,12 +777,6 @@ enabled sub-projects. Nearly all of these variable names begin with
   ``LLVM_USE_SANITIZER`` contains ``Undefined``. This can be used to override
   the default set of UBSan flags.
 
-**LLVM_USE_CRT_{target}**:STRING
-  On Windows, tells which version of the C runtime library (CRT) should be used.
-  For example, -DLLVM_USE_CRT_RELEASE=MT would statically link the CRT into the
-  LLVM tools and library. This is deprecated; use ``CMAKE_MSVC_RUNTIME_LIBRARY``
-  instead.
-
 **LLVM_USE_INTEL_JITEVENTS**:BOOL
   Enable building support for Intel JIT Events API. Defaults to OFF.
 

@Naville Naville marked this pull request as ready for review September 20, 2023 07:35
Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

This looks mostly good to me, but a few cases might need setting CMAKE_MSVC_RUNTIME_LIBRARY instead of the removed variable.

The commit message needs improving though. This isn't related to the discussion about crt allocators at all.

Instead the commit message should explain that this setting is deprecated by the new CMake mechanism that we now prefer, mention that this was already marked as deprecated since July (referencing the commit c6bd873), and mention that the current release branch, 17.x, still contains this option in deprecated form (so people upgrading through each major release won't have a silent break, but will get deprecation about using the old option form and have a chance to change it before it is removed).

@@ -30,7 +30,6 @@ set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")

if(WIN32)
set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
Copy link
Member

Choose a reason for hiding this comment

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

This case here seems to lack a corresponding setting of CMAKE_MSVC_RUNTIME_LIBRARY - I guess we should add that to make this a proper no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's been set at Line 57?

Copy link
Member

Choose a reason for hiding this comment

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

Right, I didn't see that one.

@@ -70,10 +70,6 @@ foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
endif()
endforeach()

if(WIN32)
set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
Copy link
Member

Choose a reason for hiding this comment

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

Same here - we should probably set CMAKE_MSVC_RUNTIME_LIBRARY instead of just removing the setting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, maybe Line57 is enough?

Copy link
Member

Choose a reason for hiding this comment

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

You mean line 91 here? Ok, that's also present elsewhere here.

@@ -951,7 +950,7 @@ if(LLVM_USE_SANITIZER)
endif()
# Prepare ASAN runtime if needed
if (LLVM_USE_SANITIZER MATCHES ".*Address.*")
if (${LLVM_USE_CRT_${uppercase_CMAKE_BUILD_TYPE}} MATCHES "^(MT|MTd)$")
if (${CMAKE_MSVC_RUNTIME_LIBRARY} MATCHES "^(MultiThreaded|MultiThreadedDebug)$")
Copy link
Member

Choose a reason for hiding this comment

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

Oh, I wonder how I had missed this one while doing the deprecation cleanup...

llvm/cmake/modules/LLVMConfig.cmake.in Show resolved Hide resolved
Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

Ok, the PR seems fine code-wise then - please update the commit message (PR description) and this should be fine.

@@ -30,7 +30,6 @@ set(LLDB_ENABLE_CURSES OFF CACHE BOOL "")
set(LLDB_ENABLE_LIBEDIT OFF CACHE BOOL "")

if(WIN32)
set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
Copy link
Member

Choose a reason for hiding this comment

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

Right, I didn't see that one.

@@ -70,10 +70,6 @@ foreach(variable ${_FUCHSIA_BOOTSTRAP_PASSTHROUGH})
endif()
endforeach()

if(WIN32)
set(LLVM_USE_CRT_RELEASE "MT" CACHE STRING "")
Copy link
Member

Choose a reason for hiding this comment

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

You mean line 91 here? Ok, that's also present elsewhere here.

This has been deprecated in favor of CMake's CMAKE_MSVC_RUNTIME_LIBRARY in c6bd873 .
Current release branch still contains it in deprecated status so no existing end-users will be affected
@Naville Naville changed the title [CMake]Remove LLVM_USE_CRT* [CMake]Fully delete the deprecated LLVM_USE_CRT* Sep 20, 2023
@Naville
Copy link
Contributor Author

Naville commented Sep 20, 2023

Updated the commit message @mstorsjo

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks. (But let's wait with landing it until e.g. tomorrow, in case someone else has comments on it.)

@mstorsjo
Copy link
Member

LGTM, thanks. (But let's wait with landing it until e.g. tomorrow, in case someone else has comments on it.)

I think this should be fine to land now. Do you have commit access, or do you want me to push the button?

@Naville
Copy link
Contributor Author

Naville commented Sep 21, 2023

Push the button for me please :D

@mstorsjo mstorsjo merged commit 618e5d2 into llvm:main Sep 21, 2023
aarongable pushed a commit to chromium/chromium that referenced this pull request Sep 22, 2023
…RT_RELEASE

This was made an error in
llvm/llvm-project#66850.

Bug: 1485646
Change-Id: Id106d4f9beeea7299befa4d866a75dd3153ba3b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4887702
Commit-Queue: Amy Huang <[email protected]>
Commit-Queue: Arthur Eubanks <[email protected]>
Reviewed-by: Amy Huang <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1200349}
@glandium
Copy link
Contributor

glandium commented Oct 6, 2023

This unveiled an interesting problem in our builds: llvm-config --cxxflags doesn't include the /MT//MD flag, so when building something that links with one of the .lib from LLVM, you can end up with a failure because you're not building with the same flag as LLVM was built with. Which used to be MT and with this change is now MD.

@glandium
Copy link
Contributor

glandium commented Oct 6, 2023

Which used to be MT and with this change is now MD.

(because our script was still using LLVM_USE_CRT_RELEASE)

@Naville
Copy link
Contributor Author

Naville commented Oct 7, 2023

I will can take a look at into improving llvm-config if no one else will

akoeplinger added a commit to dotnet/llvm-project that referenced this pull request Jul 17, 2024
radekdoulik pushed a commit to dotnet/llvm-project that referenced this pull request Jul 17, 2024
radekdoulik pushed a commit to dotnet/llvm-project that referenced this pull request Aug 16, 2024
radekdoulik pushed a commit to dotnet/llvm-project that referenced this pull request Sep 2, 2024
radekdoulik pushed a commit to dotnet/llvm-project that referenced this pull request Sep 12, 2024
radekdoulik pushed a commit to dotnet/llvm-project that referenced this pull request Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category cmake Build system in general and CMake in particular
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants