[llvm] [llvm] Enable LLVM_LINK_LLVM_DYLIB by default on non-Windows platforms (PR #138187)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 25 21:02:14 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Reid Kleckner (rnk)

<details>
<summary>Changes</summary>

As discussed in the RFC thread [1], this build configuration is a better
default because it uses less RAM and disk to build LLVM, which makes it
more accessible to beginners. The downside to the libLLVM build is that
it increases tool binary startup time, which can have major impacts on
configuration script times and the LLVM test suite itself. However, it
is better for new users configuring LLVM builds for the first time.

Long-time developers with beefy machines who prefer the finer grained
dependencies of static linking can still use the old model by opting out
with -DLLVM_LINK_LLVM_DYLIB=OFF. The fine-grained shared lib build is
also still supported via -DBUILD_SHARED_LIBS=ON.

MLIR's dylib build is configured to follow the LLVM dylib build, so this
changes the default for MLIR as well.

[1] https://discourse.llvm.org/t/rfc-llvm-link-llvm-dylib-should-default-to-on-on-posix-platforms/85908/1


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


4 Files Affected:

- (modified) bolt/unittests/Profile/CMakeLists.txt (-2) 
- (modified) llvm/CMakeLists.txt (+10-2) 
- (modified) llvm/docs/ReleaseNotes.md (+5) 
- (modified) llvm/lib/Testing/Support/CMakeLists.txt (+2) 


``````````diff
diff --git a/bolt/unittests/Profile/CMakeLists.txt b/bolt/unittests/Profile/CMakeLists.txt
index ce01c6c4b949e..4d468372f27fc 100644
--- a/bolt/unittests/Profile/CMakeLists.txt
+++ b/bolt/unittests/Profile/CMakeLists.txt
@@ -15,8 +15,6 @@ target_link_libraries(ProfileTests
   PRIVATE
   LLVMBOLTCore
   LLVMBOLTProfile
-  LLVMTargetParser
-  LLVMTestingSupport
   )
 
 foreach (tgt ${BOLT_TARGETS_TO_BUILD})
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 4b9e70fad2152..cd2adf1cddace 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -919,14 +919,22 @@ if(NOT MSVC OR LLVM_BUILD_LLVM_DYLIB_VIS)
   set(CAN_BUILD_LLVM_DYLIB ON)
 endif()
 
-cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library" OFF
+# Link the tools against the libllvm DSO by default.
+set(LLVM_LINK_LLVM_DYLIB_default ON)
+if (BUILD_SHARED_LIBS OR WIN32)
+  set(LLVM_LINK_LLVM_DYLIB_default OFF)
+endif()
+
+cmake_dependent_option(LLVM_LINK_LLVM_DYLIB "Link tools against the libllvm dynamic library"
+                       "${LLVM_LINK_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 set(LLVM_BUILD_LLVM_DYLIB_default OFF)
 if(LLVM_LINK_LLVM_DYLIB OR LLVM_BUILD_LLVM_C_DYLIB)
   set(LLVM_BUILD_LLVM_DYLIB_default ON)
 endif()
-cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library" ${LLVM_BUILD_LLVM_DYLIB_default}
+cmake_dependent_option(LLVM_BUILD_LLVM_DYLIB "Build libllvm dynamic library"
+                       "${LLVM_BUILD_LLVM_DYLIB_default}"
                        "CAN_BUILD_LLVM_DYLIB" OFF)
 
 cmake_dependent_option(LLVM_DYLIB_EXPORT_INLINES "Force inline members of classes to be DLL exported when
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 4a1005667692d..d4b1e353499f5 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -90,6 +90,11 @@ Changes to LLVM infrastructure
 Changes to building LLVM
 ------------------------
 
+* On non-Windows platforms, LLVM now builds as a large shared library, libLLVM,
+  by default. To revert to the old behavior of producing and linking static
+  libraries, pass ``-DLLVM_LINK_LLVM_DYLIB=OFF`` to CMake when configuring your
+  build.
+
 Changes to TableGen
 -------------------
 
diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt
index 6955271239ca6..e5f3af23a6a13 100644
--- a/llvm/lib/Testing/Support/CMakeLists.txt
+++ b/llvm/lib/Testing/Support/CMakeLists.txt
@@ -14,6 +14,8 @@ add_llvm_library(LLVMTestingSupport
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support
 
+  DISABLE_LLVM_LINK_LLVM_DYLIB
+
   LINK_COMPONENTS
   Support
   )

``````````

</details>


https://github.com/llvm/llvm-project/pull/138187


More information about the llvm-commits mailing list