[Openmp-commits] [openmp] 5b6236c - [Runtimes] Drop 'flang' from runtimes configure dependency (#198205)
via Openmp-commits
openmp-commits at lists.llvm.org
Mon Jun 8 06:47:10 PDT 2026
Author: Joseph Huber
Date: 2026-06-08T08:47:04-05:00
New Revision: 5b6236c37658b2b1341b20e9b2463d075745d108
URL: https://github.com/llvm/llvm-project/commit/5b6236c37658b2b1341b20e9b2463d075745d108
DIFF: https://github.com/llvm/llvm-project/commit/5b6236c37658b2b1341b20e9b2463d075745d108.diff
LOG: [Runtimes] Drop 'flang' from runtimes configure dependency (#198205)
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.
Added:
Modified:
flang-rt/lib/runtime/CMakeLists.txt
llvm/cmake/modules/LLVMExternalProjectUtils.cmake
llvm/runtimes/CMakeLists.txt
openmp/module/CMakeLists.txt
runtimes/cmake/config-Fortran.cmake
Removed:
################################################################################
diff --git a/flang-rt/lib/runtime/CMakeLists.txt b/flang-rt/lib/runtime/CMakeLists.txt
index 20aa3effeec94..a956cda31b52d 100644
--- a/flang-rt/lib/runtime/CMakeLists.txt
+++ b/flang-rt/lib/runtime/CMakeLists.txt
@@ -305,6 +305,27 @@ 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
+ EXCLUDE_FROM_ALL
+ )
+
+ 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/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 707451408f091..bbc91a709c553 100644
--- a/llvm/runtimes/CMakeLists.txt
+++ b/llvm/runtimes/CMakeLists.txt
@@ -115,6 +115,25 @@ macro(append_passthrough_options out type names)
endforeach()
endmacro()
+# Wire build-order dependencies on flang for targets that invoke it. This
+# allows us to configure the runtimes without first building flang. Attaches the
+# flang dependency to the main build target and any fortran module file builds,
+# like 'install-libomp-mod' or `install-flang-rt-mod'.
+function(add_flang_mod_deps build_target)
+ if(TARGET flang)
+ if(TARGET ${build_target})
+ add_dependencies(${build_target} flang)
+ endif()
+ foreach(tgt IN LISTS ARGN)
+ if(tgt MATCHES "-mod($|-)")
+ if(TARGET ${tgt})
+ add_dependencies(${tgt} flang)
+ endif()
+ endif()
+ endforeach()
+ endif()
+endfunction()
+
function(builtin_default_target compiler_rt_path)
cmake_parse_arguments(ARG "" "" "DEPENDS" ${ARGN})
@@ -278,8 +297,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.
@@ -293,8 +315,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)
@@ -337,6 +363,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)
@@ -491,6 +519,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.
@@ -514,7 +544,6 @@ if(build_runtimes)
if(LLVM_INCLUDE_TESTS)
foreach(dep FileCheck
clang
- flang
count
lld
lli
@@ -800,11 +829,18 @@ ${_flag_values}\
if(LLVM_INCLUDE_TESTS)
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_DEPENDS runtimes-test-depends)
+ # Flang is not in extra_deps to avoid making runtimes configure depend on
+ # it being fully built, but tests still need it.
+ set(extra_test_deps ${extra_deps})
+ if(TARGET flang)
+ list(APPEND extra_test_deps flang)
+ endif()
+
foreach(target ${test_targets} ${SUB_CHECK_TARGETS})
- add_dependencies(${target} ${extra_deps})
+ add_dependencies(${target} ${extra_test_deps})
endforeach()
- set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_deps})
+ set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS runtimes ${extra_test_deps})
endif()
# Flang tests depend on module files built by the runtimes.
diff --git a/openmp/module/CMakeLists.txt b/openmp/module/CMakeLists.txt
index 3bd7e7684bb37..c4b9554bdffa4 100644
--- a/openmp/module/CMakeLists.txt
+++ b/openmp/module/CMakeLists.txt
@@ -38,7 +38,17 @@ add_dependencies(libomp-mod ${RUNTIMES_FORTRAN_BUILD_DEPS})
install(FILES
"${RUNTIMES_OUTPUT_RESOURCE_MOD_DIR}/omp_lib.h"
DESTINATION "${RUNTIMES_INSTALL_RESOURCE_MOD_PATH}"
- COMPONENT openmp
+ COMPONENT libomp-mod
+ EXCLUDE_FROM_ALL
)
-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..c4e65656ccb6a 100644
--- a/runtimes/cmake/config-Fortran.cmake
+++ b/runtimes/cmake/config-Fortran.cmake
@@ -88,15 +88,18 @@ 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}")
+ set(CMAKE_Fortran_SIMULATE_ID "GNU")
+
# 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 +150,21 @@ 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.
+# The build-order dependency in add_flang_mod_deps ensures the real binary is
+# built before anything tries to invoke this placeholder.
+if (CMAKE_Fortran_COMPILER_FORCED AND NOT EXISTS "${CMAKE_Fortran_COMPILER}")
+ get_filename_component(_compiler_dir "${CMAKE_Fortran_COMPILER}" DIRECTORY)
+ file(MAKE_DIRECTORY "${_compiler_dir}")
+ file(WRITE "${CMAKE_Fortran_COMPILER}" "stub")
+ # Ninja uses file mtimes to decide whether build outputs are up-to-date.
+ # If this placeholder's mtime is recent it may match what is recorded in
+ # .ninja_log, causing ninja to skip building the real compiler binary.
+ # Set it so that any subsequent real build always has a newer mtime.
+ execute_process(COMMAND touch -t 197001020000 "${CMAKE_Fortran_COMPILER}"
+ ERROR_QUIET)
+endif ()
include(CheckLanguage)
check_language(Fortran)
More information about the Openmp-commits
mailing list