[Openmp-commits] [llvm] [openmp] [Runtimes] Drop 'flang' from runtimes configure dependency (PR #198205)
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Fri May 29 12:53:53 PDT 2026
https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/198205
>From 0c87651f335c1abfca4013f78213861b02375228 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Sun, 17 May 2026 13:23:36 -0500
Subject: [PATCH] [Runtimes] Drop 'flang' from runtimes configure dependency
Summary:
This PR cuts `flang` out of the core runtimes configure dependency. We
will need the runtimes infrastructure to handle `flang` module
generation, but this dependency poisons the entire dependency stack.
`flang` and `mlir` are by far the heavily parts of the LLVM stack and
for distribution we want to only build it when absolutely necessary,
which as of now is only to install flang module files.
The approach here is to simply remove the `flang` target from the core
dependency tree, but intead configure it for the top-level `module`
targets which are part of `all`. To make this work we need to pass
COMPILER_WORKS and set up a dummy location so that configuration passes.
it's a little backdoor, but this is an extremely important quality of
life improvement for LLVM distribution support.
comment
---
flang-rt/lib/runtime/CMakeLists.txt | 20 ++++++++++
llvm/CMakeLists.txt | 8 ++++
.../modules/LLVMExternalProjectUtils.cmake | 5 +--
llvm/runtimes/CMakeLists.txt | 37 +++++++++++++++++--
openmp/module/CMakeLists.txt | 13 ++++++-
runtimes/cmake/config-Fortran.cmake | 19 +++++++---
6 files changed, 87 insertions(+), 15 deletions(-)
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index 20aa3effeec94..fbd63b24de94c 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -305,6 +305,26 @@ if (FLANG_RT_FORTRAN_MODULES)
add_dependencies(flang_rt.mod flang_rt.mod.intrinsics.barrier)
flang_module_target(flang_rt.mod PUBLIC)
add_module_barrier(flang-rt-mod flang_rt.mod)
+
+ if (RUNTIMES_FORTRAN_MODULES)
+ set(_mod_install_dest "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}/..")
+ cmake_path(NORMAL_PATH _mod_install_dest)
+ install(DIRECTORY "${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}"
+ DESTINATION "${_mod_install_dest}"
+ COMPONENT flang-rt-mod
+ )
+
+ if (NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-flang-rt-mod
+ DEPENDS flang-rt-mod
+ COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+ --component flang-rt-mod)
+ add_custom_target(install-flang-rt-mod-stripped
+ DEPENDS flang-rt-mod
+ COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+ --component flang-rt-mod --strip)
+ endif ()
+ endif ()
endif ()
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 4509fbaba1d25..58b8e56c8555b 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -1465,6 +1465,14 @@ if( LLVM_INCLUDE_TESTS )
endif()
set_target_properties(test-depends PROPERTIES FOLDER "LLVM/Tests")
add_dependencies(check-all test-depends)
+
+ # Projects that need runtimes for their tests (e.g. flang needs flang-rt).
+ get_property(runtimes_test_consumers GLOBAL PROPERTY LLVM_TEST_DEPENDS_ON_RUNTIMES)
+ foreach(target ${runtimes_test_consumers})
+ if (TARGET ${target})
+ add_dependencies(${target} test-depends)
+ endif()
+ endforeach()
endif()
if (LLVM_INCLUDE_DOCS)
diff --git a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
index 1c44a106e94af..47b12dc9a3d8c 100644
--- a/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
+++ b/llvm/cmake/modules/LLVMExternalProjectUtils.cmake
@@ -100,9 +100,6 @@ function(llvm_ExternalProject_Add name source_dir)
if(NOT ARG_TOOLCHAIN_TOOLS)
set(ARG_TOOLCHAIN_TOOLS clang)
- if (ARG_ENABLE_FORTRAN)
- list(APPEND ARG_TOOLCHAIN_TOOLS flang)
- endif ()
# AIX 64-bit XCOFF and big AR format is not yet supported in some of these tools.
if(NOT _cmake_system_name STREQUAL "AIX")
list(APPEND ARG_TOOLCHAIN_TOOLS lld llvm-ar llvm-ranlib llvm-nm llvm-objdump)
@@ -153,7 +150,7 @@ function(llvm_ExternalProject_Add name source_dir)
set(CLANG_IN_TOOLCHAIN On)
endif()
- if(flang IN_LIST TOOLCHAIN_TOOLS)
+ if(ARG_ENABLE_FORTRAN AND TARGET flang)
set(FLANG_IN_TOOLCHAIN On)
endif()
diff --git a/llvm/runtimes/CMakeLists.txt b/llvm/runtimes/CMakeLists.txt
index c2352e846f03f..e0e42016cd76c 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -115,6 +115,27 @@ macro(append_passthrough_options out type names)
endforeach()
endmacro()
+# Wire build-order dependencies on flang for targets that invoke it. This allows
+# us to build the runtimes separately without first building flang.
+macro(add_flang_mod_deps build_target extra_targets_list)
+ if(TARGET flang)
+ set(_fortran_deps flang)
+ if(TARGET module_files)
+ list(APPEND _fortran_deps module_files)
+ endif()
+ if(TARGET ${build_target})
+ add_dependencies(${build_target} ${_fortran_deps})
+ endif()
+ foreach(tgt IN LISTS ${extra_targets_list})
+ if(tgt MATCHES "-mod($|-)")
+ if(TARGET ${tgt})
+ add_dependencies(${tgt} ${_fortran_deps})
+ endif()
+ endif()
+ endforeach()
+ endif()
+endmacro()
+
function(builtin_default_target compiler_rt_path)
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
@@ -273,8 +294,11 @@ function(runtime_default_target)
endforeach()
if ("openmp" IN_LIST LLVM_ENABLE_RUNTIMES)
# The target libomp-mod is a dependee of check-flang needed to run its
- # OpenMP tests
+ # OpenMP tests. install-libomp-mod is a separate distribution component
+ # so that install-openmp does not require building flang.
list(APPEND extra_targets "libomp-mod")
+ list(APPEND extra_targets "install-libomp-mod")
+ list(APPEND extra_targets "install-libomp-mod-stripped")
# Let the "doxygen" build target also build openmp's doxygen, just like
# "check" and "install" also apply to the runtimes builds.
@@ -288,8 +312,12 @@ function(runtime_default_target)
endif ()
endif ()
if ("flang-rt" IN_LIST LLVM_ENABLE_RUNTIMES)
- # The target flang-rt-mod is a dependee of check-flang.
+ # The target flang-rt-mod is a dependee of check-flang. install-flang-rt-mod
+ # is a separate distribution component so that install-flang-rt does not
+ # require building flang.
list(APPEND extra_targets "flang-rt-mod")
+ list(APPEND extra_targets "install-flang-rt-mod")
+ list(APPEND extra_targets "install-flang-rt-mod-stripped")
endif ()
if(LLVM_INCLUDE_TESTS)
@@ -332,6 +360,8 @@ function(runtime_default_target)
TARGET_TRIPLE ${LLVM_TARGET_TRIPLE}
FOLDER "Runtimes"
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})
+
+ add_flang_mod_deps(runtimes-build extra_targets)
endfunction()
# runtime_register_target(name)
@@ -486,6 +516,8 @@ function(runtime_register_target name)
add_dependencies(install-${component} install-${component}-${name})
add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
endforeach()
+
+ add_flang_mod_deps(runtimes-${name}-build ${name}_extra_targets)
endfunction()
# Check if we have any runtimes to build.
@@ -509,7 +541,6 @@ if(build_runtimes)
if(LLVM_INCLUDE_TESTS)
foreach(dep FileCheck
clang
- flang
count
lld
lli
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index c0a873f9be552..fd29504d3ca34 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -32,7 +32,16 @@ add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/../runtime/src/omp_lib.h"
DESTINATION ${LIBOMP_HEADERS_INSTALL_PATH}
- COMPONENT openmp
+ COMPONENT libomp-mod
)
-openmp_register_meta_dep(libomp-mod)
+if (NOT CMAKE_CONFIGURATION_TYPES)
+ add_custom_target(install-libomp-mod
+ DEPENDS libomp-mod
+ COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+ --component libomp-mod)
+ add_custom_target(install-libomp-mod-stripped
+ DEPENDS libomp-mod
+ COMMAND "${CMAKE_COMMAND}" --install "${CMAKE_BINARY_DIR}"
+ --component libomp-mod --strip)
+endif ()
diff --git a/runtimes/cmake/config-Fortran.cmake b/runtimes/cmake/config-Fortran.cmake
index 74fd15021f0a0..32ae3dc8c78bb 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -88,15 +88,17 @@ if (CMAKE_Fortran_COMPILER)
# cannot use CMAKE_Fortran_COMPILER_ID.
cmake_path(GET CMAKE_Fortran_COMPILER STEM _Fortran_COMPILER_STEM)
if (_Fortran_COMPILER_STEM STREQUAL "flang-new" OR _Fortran_COMPILER_STEM STREQUAL "flang")
+ # Force the compiler ID so CMake does not try to run the compiler for
+ # identification. In a bootstrapping build the Flang binary may not be
+ # built yet at configure time (only CMAKE_Fortran_COMPILER_WORKS is set).
+ set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
+ set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
+ set(CMAKE_Fortran_COMPILER_FORCED TRUE)
+ set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
+
# CMake 3.24 is the first version of CMake that directly recognizes Flang.
# LLVM's requirement is only CMake 3.20, teach CMake 3.20-3.23 how to use Flang, if used.
if (CMAKE_VERSION VERSION_LESS "3.24")
- include(CMakeForceCompiler)
- CMAKE_FORCE_Fortran_COMPILER("${CMAKE_Fortran_COMPILER}" "LLVMFlang")
-
- set(CMAKE_Fortran_COMPILER_ID "LLVMFlang")
- set(CMAKE_Fortran_COMPILER_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
-
set(CMAKE_Fortran_SUBMODULE_SEP "-")
set(CMAKE_Fortran_SUBMODULE_EXT ".mod")
@@ -147,6 +149,11 @@ else ()
return ()
endif ()
+# In a bootstrapping build the Fortran compiler may not have been built yet.
+# Create a placeholder so CMake's enable_language() existence check passes.
+if (CMAKE_Fortran_COMPILER_FORCED AND NOT EXISTS "${CMAKE_Fortran_COMPILER}")
+ file(TOUCH "${CMAKE_Fortran_COMPILER}")
+endif ()
include(CheckLanguage)
check_language(Fortran)
More information about the Openmp-commits
mailing list