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

[Flang] Optionally do not compile the runtime in-tree #122336

Merged
merged 49 commits into from
Feb 8, 2025

Conversation

Meinersbur
Copy link
Member

@Meinersbur Meinersbur commented Jan 9, 2025

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.

Extracted out of #110217

Copy link

github-actions bot commented Jan 9, 2025

✅ With the latest revision this PR passed the Python code formatter.

@@ -33,7 +33,6 @@ add_flang_nongtest_unittest(intrinsics
FortranDecimal
FortranSemantics
FortranParser
FortranRuntime
Copy link
Member Author

Choose a reason for hiding this comment

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

This test actually does not depend on the runtime

@Meinersbur Meinersbur marked this pull request as ready for review January 11, 2025 21:13
@llvmbot llvmbot added flang:driver flang Flang issues not falling into any other category flang:semantics labels Jan 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 11, 2025

@llvm/pr-subscribers-flang-driver

@llvm/pr-subscribers-flang-semantics

Author: Michael Kruse (Meinersbur)

Changes

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 exist at the same time. When using LLVM_ENABLE_RUNTIME=flang-rt, the in-tree build instructions are in conflict and must be disabled.

Extracted out of #110217


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

10 Files Affected:

  • (modified) flang/CMakeLists.txt (+5-1)
  • (modified) flang/test/CMakeLists.txt (+5-1)
  • (modified) flang/test/Driver/ctofortran.f90 (+1)
  • (modified) flang/test/Driver/exec.f90 (+1)
  • (modified) flang/test/Runtime/no-cpp-dep.c (+1-1)
  • (modified) flang/test/lit.cfg.py (+4-1)
  • (modified) flang/test/lit.site.cfg.py.in (+2)
  • (modified) flang/tools/f18/CMakeLists.txt (+2-2)
  • (modified) flang/unittests/CMakeLists.txt (+3-1)
  • (modified) flang/unittests/Evaluate/CMakeLists.txt (+14-13)
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 68947eaa9c9bd7..d5f2602334b19e 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -233,6 +233,8 @@ else()
   include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR})
 endif()
 
+option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON)
+
 set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH
     "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')")
 mark_as_advanced(FLANG_TOOLS_INSTALL_DIR)
@@ -473,7 +475,9 @@ if (FLANG_CUF_RUNTIME)
   find_package(CUDAToolkit REQUIRED)
 endif()
 
-add_subdirectory(runtime)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(runtime)
+endif ()
 
 if (LLVM_INCLUDE_EXAMPLES)
   add_subdirectory(examples)
diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt
index cab214c2ef4c8c..e398e0786147aa 100644
--- a/flang/test/CMakeLists.txt
+++ b/flang/test/CMakeLists.txt
@@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS
   llvm-objdump
   llvm-readobj
   split-file
-  FortranRuntime
   FortranDecimal
 )
+
+if (FLANG_INCLUDE_RUNTIME)
+  list(APPEND FLANG_TEST_DEPENDS FortranRuntime)
+endif ()
+
 if (LLVM_ENABLE_PLUGINS AND NOT WIN32)
   list(APPEND FLANG_TEST_DEPENDS Bye)
 endif()
diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90
index 78eac32133b18e..10c7adaccc9588 100644
--- a/flang/test/Driver/ctofortran.f90
+++ b/flang/test/Driver/ctofortran.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! RUN: split-file %s %t
 ! RUN: chmod +x %t/runtest.sh
 ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s
diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90
index fd174005ddf62a..9ca91ee24011c9 100644
--- a/flang/test/Driver/exec.f90
+++ b/flang/test/Driver/exec.f90
@@ -1,4 +1,5 @@
 ! UNSUPPORTED: system-windows
+! REQUIRES: flang-rt
 ! Verify that flang can correctly build executables.
 
 ! RUN: %flang %s -o %t
diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c
index b1a5fa004014cc..7303ce63fdec41 100644
--- a/flang/test/Runtime/no-cpp-dep.c
+++ b/flang/test/Runtime/no-cpp-dep.c
@@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime
 library. It tries to link this simple file against libFortranRuntime.a with
 a C compiler.
 
-REQUIRES: c-compiler
+REQUIRES: c-compiler, flang-rt
 
 RUN: %if system-aix %{ export OBJECT_MODE=64 %}
 RUN: %cc -std=c99 %s -I%include %libruntime -lm  \
diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py
index c452b6d231c89f..f4580afc8c47b1 100644
--- a/flang/test/lit.cfg.py
+++ b/flang/test/lit.cfg.py
@@ -163,10 +163,13 @@
         ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal")
     )
 
+if config.flang_include_runtime:
+    config.available_features.add("flang-rt")
+
 # Define some variables to help us test that the flang runtime doesn't depend on
 # the C++ runtime libraries. For this we need a C compiler. If for some reason
 # we don't have one, we can just disable the test.
-if config.cc:
+if config.flang_include_runtime and config.cc:
     libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a")
     include = os.path.join(config.flang_src_dir, "include")
 
diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in
index d1a0ac763cf8a0..697ba3fa797633 100644
--- a/flang/test/lit.site.cfg.py.in
+++ b/flang/test/lit.site.cfg.py.in
@@ -1,6 +1,7 @@
 @LIT_SITE_CFG_IN_HEADER@
 
 import sys
+import lit.util
 
 config.llvm_tools_dir = lit_config.substitute("@LLVM_TOOLS_DIR@")
 config.llvm_shlib_dir = lit_config.substitute(path(r"@SHLIBDIR@"))
@@ -32,6 +33,7 @@ else:
     config.openmp_module_dir = None
 config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@"
 config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@"
+config.flang_include_runtime = lit.util.pythonize_bool("@FLANG_INCLUDE_RUNTIME@")
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 4362fcf0537616..e22a12c4ff0742 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -72,7 +72,7 @@ if (NOT CMAKE_CROSSCOMPILING)
       set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_builtins.mod)
     else()
       set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
-      if(${filename} STREQUAL "iso_fortran_env")
+      if(${filename} STREQUAL "iso_fortran_env" AND FLANG_INCLUDE_RUNTIME)
         set(depends ${depends} ${FLANG_INTRINSIC_MODULES_DIR}/iso_fortran_env_impl.mod)
       endif()
       if(${filename} STREQUAL "ieee_arithmetic" OR
@@ -105,7 +105,7 @@ if (NOT CMAKE_CROSSCOMPILING)
     set(compile_with "-fsyntax-only")
     set(object_output "")
     set(include_in_link FALSE)
-    if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION)
+    if(${filename} IN_LIST MODULES_WITH_IMPLEMENTATION AND FLANG_INCLUDE_RUNTIME)
       set(object_output "${CMAKE_CURRENT_BINARY_DIR}/${filename}${CMAKE_CXX_OUTPUT_EXTENSION}")
       set(compile_with -c -o ${object_output})
       set(include_in_link TRUE)
diff --git a/flang/unittests/CMakeLists.txt b/flang/unittests/CMakeLists.txt
index 945067fed4f82d..14e792de4895db 100644
--- a/flang/unittests/CMakeLists.txt
+++ b/flang/unittests/CMakeLists.txt
@@ -75,5 +75,7 @@ add_subdirectory(Optimizer)
 add_subdirectory(Common)
 add_subdirectory(Decimal)
 add_subdirectory(Evaluate)
-add_subdirectory(Runtime)
+if (FLANG_INCLUDE_RUNTIME)
+  add_subdirectory(Runtime)
+endif ()
 add_subdirectory(Frontend)
diff --git a/flang/unittests/Evaluate/CMakeLists.txt b/flang/unittests/Evaluate/CMakeLists.txt
index 8111ecd72cfc7d..1c3fac29cd2982 100644
--- a/flang/unittests/Evaluate/CMakeLists.txt
+++ b/flang/unittests/Evaluate/CMakeLists.txt
@@ -33,7 +33,6 @@ add_flang_nongtest_unittest(intrinsics
   FortranDecimal
   FortranSemantics
   FortranParser
-  FortranRuntime
 )
 
 add_flang_nongtest_unittest(logical
@@ -56,19 +55,21 @@ add_flang_nongtest_unittest(real
 )
 llvm_update_compile_flags(real.test)
 
-add_flang_nongtest_unittest(reshape
-  NonGTestTesting
-  FortranSemantics
-  FortranEvaluate
-  FortranRuntime
-)
+if (FLANG_INCLUDE_RUNTIME)
+  add_flang_nongtest_unittest(reshape
+    NonGTestTesting
+    FortranSemantics
+    FortranEvaluate
+    FortranRuntime
+  )
 
-add_flang_nongtest_unittest(ISO-Fortran-binding
-  NonGTestTesting
-  FortranEvaluate
-  FortranSemantics
-  FortranRuntime
-)
+  add_flang_nongtest_unittest(ISO-Fortran-binding
+    NonGTestTesting
+    FortranEvaluate
+    FortranSemantics
+    FortranRuntime
+  )
+endif ()
 
 add_flang_nongtest_unittest(folding
   FortranSupport

@Meinersbur Meinersbur force-pushed the users/meinersbur/flang_runtime_Testing branch from f007594 to 71015c8 Compare January 24, 2025 18:42
Base automatically changed from users/meinersbur/flang_runtime_Testing to users/meinersbur/flang_runtime_FortranDecimal January 24, 2025 18:42
@Meinersbur Meinersbur force-pushed the users/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME branch from b68700b to 4c676f4 Compare January 24, 2025 18:42
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
…rs/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME
Base automatically changed from users/meinersbur/flang_runtime_FortranDecimal to main February 7, 2025 11:55
@Meinersbur
Copy link
Member Author

This PR still needs a review

Copy link
Contributor

@jhuber6 jhuber6 left a comment

Choose a reason for hiding this comment

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

Makes sense, should be fine to transition since we just hit a release milestone.

@Meinersbur Meinersbur merged commit e6e8ac5 into main Feb 8, 2025
8 checks passed
@Meinersbur Meinersbur deleted the users/meinersbur/flang_runtime_FLANG_INCLUDE_RUNTIME branch February 8, 2025 00:06
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
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 (llvm#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:driver flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants