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

[mlir][cmake] Do not export MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR #125842

Merged
merged 2 commits into from
Feb 11, 2025

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Feb 5, 2025

MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR point to the source directory, which is not installed. As such, the installed MLIRConfig.cmake also should not reference it.

The comment indicates that these are needed for mlir_tablegen(), but I don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source directory doesn't exist anymore, and that cannot be overridden with the correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.

For MLIR_INCLUDE_DIR there already is an exported MLIR_INCLUDE_DIRS, which can be used instead.

MLIR_MAIN_SRC_DIR points to the source directory, which is not
installed. As such, the installed MLIRConfig.cmake also should
not reference it.

The comment indicates that this is needed for mlir_tablegen(),
but I don't see any related uses.

The motivation for this is the use in flang, where we end up
inheriting a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR
build, whose source directory obviously doesn't exist anymore,
and that cannot be overridden with the correct path, because it's
not a cached variable.

Instead do what all the other projects do (for LLVM_MAIN_SRC_DIR)
and initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.
@llvmbot llvmbot added mlir flang Flang issues not falling into any other category labels Feb 5, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 5, 2025

@llvm/pr-subscribers-flang-fir-hlfir

@llvm/pr-subscribers-mlir

Author: Nikita Popov (nikic)

Changes

MLIR_MAIN_SRC_DIR points to the source directory, which is not installed. As such, the installed MLIRConfig.cmake also should not reference it.

The comment indicates that this is needed for mlir_tablegen(), but I don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source directory doesn't exist anymore, and that cannot be overridden with the correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.


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

2 Files Affected:

  • (modified) flang/CMakeLists.txt (+2-1)
  • (modified) mlir/cmake/modules/MLIRConfig.cmake.in (-1)
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index 2e27bc2279ac47..90881adf0c92db 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -79,6 +79,8 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
   message(FATAL_ERROR "flang isn't supported on 32 bit CPUs")
 endif()
 
+set(MLIR_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../mlir" CACHE PATH "Path to MLIR source tree")
+
 if (FLANG_STANDALONE_BUILD)
   set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   set(CMAKE_INCLUDE_CURRENT_DIR ON)
@@ -240,7 +242,6 @@ else()
     set(FLANG_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
   endif()
 
-  set(MLIR_MAIN_SRC_DIR ${LLVM_MAIN_SRC_DIR}/../mlir ) # --src-root
   set(MLIR_INCLUDE_DIR ${MLIR_MAIN_SRC_DIR}/include ) # --includedir
   set(MLIR_TABLEGEN_OUTPUT_DIR ${CMAKE_BINARY_DIR}/tools/mlir/include)
   include_directories(SYSTEM ${MLIR_INCLUDE_DIR})
diff --git a/mlir/cmake/modules/MLIRConfig.cmake.in b/mlir/cmake/modules/MLIRConfig.cmake.in
index 7076d94a32f2bc..c09af1e4eeee9f 100644
--- a/mlir/cmake/modules/MLIRConfig.cmake.in
+++ b/mlir/cmake/modules/MLIRConfig.cmake.in
@@ -18,7 +18,6 @@ set(MLIR_ENABLE_EXECUTION_ENGINE "@MLIR_ENABLE_EXECUTION_ENGINE@")
 
 # For mlir_tablegen()
 set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@")
-set(MLIR_MAIN_SRC_DIR "@MLIR_MAIN_SRC_DIR@")
 
 set_property(GLOBAL PROPERTY MLIR_ALL_LIBS "@MLIR_ALL_LIBS@")
 set_property(GLOBAL PROPERTY MLIR_DIALECT_LIBS "@MLIR_DIALECT_LIBS@")

Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

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

I don't quite understand why the line you removed in mlir/cmake/modules/MLIRConfig.cmake.in was there, but if it break something we can always revert an document better the setup.

What about the line before you left: set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@") ?

@nikic
Copy link
Contributor Author

nikic commented Feb 6, 2025

What about the line before you left: set(MLIR_INCLUDE_DIR "@MLIR_INCLUDE_DIR@") ?

Good point. It also points to the include directory in the source tree, so it should be dropped as well.

@nikic
Copy link
Contributor Author

nikic commented Feb 6, 2025

I've updated this to drop MLIR_INCLUDE_DIR now. Note that there already is MLIR_INCLUDE_DIRS, which is set up correctly depending on whether it's the installed or the build-tree config.

I've dropped the MLIR_INCLUDE_DIR use for FIROps.td because I don't think it's actually necessary. We already add the MLIR_INCLUDE_DIRS to the include directories at a higher level, so we don't need to do so again here. (Otherwise I could switch this to use EXTRA_INCLUDES with MLIR_INCLUDE_DIRS.)

@nikic
Copy link
Contributor Author

nikic commented Feb 11, 2025

@joker-eph Would you mind taking another look at this (now that it also removes MLIR_INCLUDE_DIR)?

@nikic nikic changed the title [mlir][cmake] Do not export MLIR_MAIN_SRC_DIR [mlir][cmake] Do not export MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR Feb 11, 2025
Copy link
Collaborator

@joker-eph joker-eph left a comment

Choose a reason for hiding this comment

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

Sorry, I had approve before and thought it was enough, but happy to re-approve explicitly of course. Thanks.

@nikic nikic merged commit 82bd148 into llvm:main Feb 11, 2025
9 checks passed
@nikic nikic deleted the mlir-main-src-dir branch February 11, 2025 13:32
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 11, 2025

LLVM Buildbot has detected a new failure on builder ppc64-flang-aix running on ppc64-flang-aix-test while building flang,mlir at step 5 "build-unified-tree".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/201/builds/2906

Here is the relevant piece of the build log for the reference
Step 5 (build-unified-tree) failure: build (failure)
...
8719.101 [236/10/7768] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/obj2yaml.cpp.o
8722.602 [235/10/7769] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/coff2yaml.cpp.o
8722.722 [234/10/7770] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/minidump2yaml.cpp.o
8723.166 [233/10/7771] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/dxcontainer2yaml.cpp.o
8723.431 [232/10/7772] Building CXX object tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-stacks.cpp.o
8723.796 [231/10/7773] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/offload2yaml.cpp.o
8724.084 [230/10/7774] Building CXX object tools/llvm-xray/CMakeFiles/llvm-xray.dir/xray-account.cpp.o
8724.875 [229/10/7775] Linking CXX executable bin/llvm-xray
8725.082 [228/10/7776] Building CXX object tools/remarks-shlib/CMakeFiles/Remarks.dir/libremarks.cpp.o
8725.196 [227/10/7777] Linking CXX shared library lib/libRemarks.a
FAILED: lib/libRemarks.a 
: && "/opt/freeware/share/cmake-3.30/Modules/Platform/AIX/ExportImportList" -o tools/remarks-shlib/CMakeFiles/Remarks.dir/exports.exp -c /home/llvm/llvm-external-buildbots/clang.17.0.2/bin/clang++  tools/remarks-shlib/CMakeFiles/Remarks.dir/libremarks.cpp.o && /home/llvm/llvm-external-buildbots/clang.17.0.2/bin/clang++ -fPIC -Wl,-bE:tools/remarks-shlib/CMakeFiles/Remarks.dir/exports.exp -mcmodel=large -fPIC -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,-bglink=large -shared   -Wl,-bE:/home/llvm/llvm-external-buildbots/workers/ppc64-flang-aix-test/ppc64-flang-aix-build/llvm-project/llvm/tools/remarks-shlib/Remarks.exports -shared -Wl,-bnoipath -o libRemarks.so.21.0git tools/remarks-shlib/CMakeFiles/Remarks.dir/libremarks.cpp.o  -Wl,-blibpath:"\$ORIGIN/../lib:/usr/lib:/lib"  lib/libLLVMRemarks.a  lib/libLLVMBitstreamReader.a  lib/libLLVMSupport.a  -lrt  -lld  -lpthreads  -lm  lib/libLLVMDemangle.a && /home/llvm/llvm-external-buildbots/clang.17.0.2/bin/llvm-ar -X32_64 rc lib/libRemarks.a libRemarks.so.21.0git && rm -f libRemarks.so.21.0git && :
/bin/sh: /opt/freeware/share/cmake-3.30/Modules/Platform/AIX/ExportImportList:  not found
8725.919 [227/9/7778] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/dwarf2yaml.cpp.o
8727.422 [227/8/7779] Building CXX object tools/reduce-chunk-list/CMakeFiles/reduce-chunk-list.dir/reduce-chunk-list.cpp.o
8728.975 [227/7/7780] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/xcoff2yaml.cpp.o
8729.911 [227/6/7781] Building CXX object tools/llvm-readobj/CMakeFiles/llvm-readobj.dir/ELFDumper.cpp.o
8731.914 [227/5/7782] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/wasm2yaml.cpp.o
8735.950 [227/4/7783] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/macho2yaml.cpp.o
8742.540 [227/3/7784] Building CXX object tools/opt/CMakeFiles/LLVMOptDriver.dir/optdriver.cpp.o
8746.498 [227/2/7785] Building CXX object tools/opt/CMakeFiles/LLVMOptDriver.dir/NewPMDriver.cpp.o
8786.340 [227/1/7786] Building CXX object tools/obj2yaml/CMakeFiles/obj2yaml.dir/elf2yaml.cpp.o
ninja: build stopped: subcommand failed.

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
…lvm#125842)

MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR point to the source directory,
which is not installed. As such, the installed MLIRConfig.cmake also
should not reference it.

The comment indicates that these are needed for mlir_tablegen(), but I
don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting
a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source
directory doesn't exist anymore, and that cannot be overridden with the
correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and
initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.

For MLIR_INCLUDE_DIR there already is an exported MLIR_INCLUDE_DIRS,
which can be used instead.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
…lvm#125842)

MLIR_MAIN_SRC_DIR and MLIR_INCLUDE_DIR point to the source directory,
which is not installed. As such, the installed MLIRConfig.cmake also
should not reference it.

The comment indicates that these are needed for mlir_tablegen(), but I
don't see any related uses.

The motivation for this is the use in flang, where we end up inheriting
a meaningless MLIR_MAIN_SRC_DIR from a previous MLIR build, whose source
directory doesn't exist anymore, and that cannot be overridden with the
correct path, because it's not a cached variable.

Instead do what all the other projects do for LLVM_MAIN_SRC_DIR and
initialize MLIR_MAIN_SRC_DIR to CMAKE_CURRENT_SOURCE_DIR/../mlir.

For MLIR_INCLUDE_DIR there already is an exported MLIR_INCLUDE_DIRS,
which can be used instead.
mgorny added a commit to mgorny/llvm-project that referenced this pull request Feb 15, 2025
This change is no longer necessary after llvm#125842.  Thanks to @nikic
for letting me know.
mgorny added a commit that referenced this pull request Feb 15, 2025
This change is no longer necessary after #125842. Thanks to @nikic for
letting me know.
@nikic nikic added this to the LLVM 20.X Release milestone Feb 18, 2025
@nikic
Copy link
Contributor Author

nikic commented Feb 18, 2025

/cherry-pick 82bd148

@llvmbot
Copy link
Member

llvmbot commented Feb 18, 2025

/pull-request #127589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category mlir
Projects
Development

Successfully merging this pull request may close these issues.

4 participants