Skip to content

Commit e6e8ac5

Browse files
authored
[Flang] Optionally do not compile the runtime in-tree (#122336)
Introduce the CMake switch FLANG_INCLUDE_RUNTIME. When set to off, do not add build instructions for the runtime. This is required for Flang-RT (#110217) and the current runtime CMake code to co-exist. When using `LLVM_ENABLE_RUNTIME=flang-rt`, the in-tree build instructions are in conflict and must be disabled.
1 parent 343bbda commit e6e8ac5

File tree

11 files changed

+47
-20
lines changed

11 files changed

+47
-20
lines changed

flang/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ else()
247247
include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
248248
endif()
249249

250+
option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON)
251+
250252
set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
251253
"Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
252254
mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
@@ -487,7 +489,9 @@ if (FLANG_BUILD_TOOLS)
487489
add_subdirectory(tools)
488490
endif()
489491

490-
add_subdirectory(runtime)
492+
if (FLANG_INCLUDE_RUNTIME)
493+
add_subdirectory(runtime)
494+
endif ()
491495

492496
if (LLVM_INCLUDE_EXAMPLES)
493497
add_subdirectory(examples)

flang/examples/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
add_subdirectory(ExternalHelloWorld)
1+
if (FLANG_INCLUDE_RUNTIME)
2+
add_subdirectory(ExternalHelloWorld)
3+
endif ()
24
add_subdirectory(PrintFlangFunctionNames)
35
add_subdirectory(FlangOmpReport)
46
add_subdirectory(FeatureList)

flang/test/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS
7171
llvm-objdump
7272
llvm-readobj
7373
split-file
74-
FortranRuntime
7574
FortranDecimal
7675
)
76+
77+
if (FLANG_INCLUDE_RUNTIME)
78+
list(APPEND FLANG_TEST_DEPENDS FortranRuntime)
79+
endif ()
80+
7781
if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
7882
list(APPEND FLANG_TEST_DEPENDS Bye)
7983
endif()

flang/test/Driver/ctofortran.f90

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
! UNSUPPORTED: system-windows
2+
! REQUIRES: flang-rt
23
! RUN: split-file %s %t
34
! RUN: chmod +x %t/runtest.sh
45
! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s

flang/test/Driver/exec.f90

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
! UNSUPPORTED: system-windows
2+
! REQUIRES: flang-rt
23
! Verify that flang can correctly build executables.
34

45
! RUN: %flang %s -o %t

flang/test/Runtime/no-cpp-dep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime
33
library. It tries to link this simple file against libFortranRuntime.a with
44
a C compiler.
55
6-
REQUIRES: c-compiler
6+
REQUIRES: c-compiler, flang-rt
77
88
RUN: %if system-aix %{ export OBJECT_MODE=64 %}
99
RUN: %cc -std=c99 %s -I%include %libruntime -lm \

flang/test/lit.cfg.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,13 @@
163163
ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal")
164164
)
165165

166+
if config.flang_include_runtime:
167+
config.available_features.add("flang-rt")
168+
166169
# Define some variables to help us test that the flang runtime doesn't depend on
167170
# the C++ runtime libraries. For this we need a C compiler. If for some reason
168171
# we don't have one, we can just disable the test.
169-
if config.cc:
172+
if config.flang_include_runtime and config.cc:
170173
libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
171174
include = os.path.join(config.flang_src_dir, "include")
172175

flang/test/lit.site.cfg.py.in

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

33
import sys
4+
import lit.util
45

56
config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
67
config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
@@ -32,6 +33,7 @@ else:
3233
config.openmp_module_dir = None
3334
config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
3435
config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
36+
config.flang_include_runtime = lit.util.pythonize_bool("@FLANG_INCLUDE_RUNTIME@")
3537

3638
import lit.llvm
3739
lit.llvm.initialize(lit_config, config)

flang/tools/f18/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ if (NOT CMAKE_CROSSCOMPILING)
109109
set(compile_with "-fsyntax-only")
110110
set(object_output "")
111111
set(include_in_link FALSE)
112-
if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
112+
if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION AND FLANG_INCLUDE_RUNTIME)
113113
set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
114114
set(compile_with -c -o ${object_output})
115115
set(include_in_link TRUE)

flang/unittests/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include(AddFlangOffloadRuntime)
2+
13
if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
24
# If Fortran runtime is built as CUDA library, the linking
35
# of targets that link FortranRuntime must be done
@@ -11,6 +13,11 @@ add_custom_target(FlangUnitTests)
1113
set_target_properties(FlangUnitTests PROPERTIES FOLDER "Flang/Tests")
1214

1315
function(add_flang_unittest_offload_properties target)
16+
# Do not apply runtime properties if not even compiling the runtime.
17+
if (NOT FLANG_INCLUDE_RUNTIME)
18+
return ()
19+
endif ()
20+
1421
# Set CUDA_RESOLVE_DEVICE_SYMBOLS.
1522
if (FLANG_EXPERIMENTAL_CUDA_RUNTIME)
1623
set_target_properties(${target}
@@ -75,5 +82,7 @@ add_subdirectory(Optimizer)
7582
add_subdirectory(Common)
7683
add_subdirectory(Decimal)
7784
add_subdirectory(Evaluate)
78-
add_subdirectory(Runtime)
85+
if (FLANG_INCLUDE_RUNTIME)
86+
add_subdirectory(Runtime)
87+
endif ()
7988
add_subdirectory(Frontend)

flang/unittests/Evaluate/CMakeLists.txt

+14-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ add_flang_nongtest_unittest(intrinsics
3333
FortranDecimal
3434
FortranSemantics
3535
FortranParser
36-
FortranRuntime
3736
)
3837

3938
add_flang_nongtest_unittest(logical
@@ -56,19 +55,21 @@ add_flang_nongtest_unittest(real
5655
)
5756
llvm_update_compile_flags(real.test)
5857

59-
add_flang_nongtest_unittest(reshape
60-
NonGTestTesting
61-
FortranSemantics
62-
FortranEvaluate
63-
FortranRuntime
64-
)
58+
if (FLANG_INCLUDE_RUNTIME)
59+
add_flang_nongtest_unittest(reshape
60+
NonGTestTesting
61+
FortranSemantics
62+
FortranEvaluate
63+
FortranRuntime
64+
)
6565

66-
add_flang_nongtest_unittest(ISO-Fortran-binding
67-
NonGTestTesting
68-
FortranEvaluate
69-
FortranSemantics
70-
FortranRuntime
71-
)
66+
add_flang_nongtest_unittest(ISO-Fortran-binding
67+
NonGTestTesting
68+
FortranEvaluate
69+
FortranSemantics
70+
FortranRuntime
71+
)
72+
endif ()
7273

7374
add_flang_nongtest_unittest(folding
7475
FortranSupport

0 commit comments

Comments
 (0)