Skip to content

Conversation

@arthurqiu
Copy link
Contributor

The PR fixes a misconfigured dependency that causes CMake error "No rule to make target 'NATIVE/bin/mlir-irdl-to-cpp'" for cross-compilation.

@llvmbot llvmbot added the mlir label Jun 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 25, 2025

@llvm/pr-subscribers-mlir

Author: None (arthurqiu)

Changes

The PR fixes a misconfigured dependency that causes CMake error "No rule to make target 'NATIVE/bin/mlir-irdl-to-cpp'" for cross-compilation.


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

1 Files Affected:

  • (modified) mlir/cmake/modules/IRDLToCpp.cmake (+1-1)
diff --git a/mlir/cmake/modules/IRDLToCpp.cmake b/mlir/cmake/modules/IRDLToCpp.cmake
index 8470ccdf55166..2457773ef2565 100644
--- a/mlir/cmake/modules/IRDLToCpp.cmake
+++ b/mlir/cmake/modules/IRDLToCpp.cmake
@@ -5,7 +5,7 @@ function(add_irdl_to_cpp_target target irdl_file)
 
     # The command output depends on the executable to ensure IRDL sources are properly rebuilt
     # if the tool changes.
-    DEPENDS ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file}
+    DEPENDS ${MLIR_IRDL_TO_CPP_TARGET} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file}
     COMMENT "Building ${irdl_file}..."
   )
   add_custom_target(${target} DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc)

@arthurqiu
Copy link
Contributor Author

@Moxinilian request for review. Thanks!

Copy link
Member

@Moxinilian Moxinilian left a comment

Choose a reason for hiding this comment

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

Have you checked the comment above? Can you make sure that it still correctly rebuilds the sources if the tool changes? If this is not the case you may want to depend on both the target and the executable.

@arthurqiu
Copy link
Contributor Author

Have you checked the comment above? Can you make sure that it still correctly rebuilds the sources if the tool changes? If this is not the case you may want to depend on both the target and the executable.

Not sure if I miss anything, but I think IRDL source should still be rebuilt if it depends on MLIR_IRDL_TO_CPP_TARGET.

https://cmake.org/cmake/help/latest/command/add_custom_command.html

If the argument is the name of a target (created by the add_custom_target(), add_executable(), or add_library() command) a target-level dependency is created to make sure the target is built before any target using this custom command. Additionally, if the target is an executable or library, a file-level dependency is created to cause the custom command to re-run whenever the target is recompiled.

@Moxinilian
Copy link
Member

Moxinilian commented Jul 1, 2025

Could you please try? This is what I did the first time and it did not work.

In parallel I am asking for help on the Discord server. It would be nice if there was a way to test the build system for this property automatically somehow, but this seems tricky to set up.

@makslevental
Copy link
Contributor

makslevental commented Jul 1, 2025

I'm not 100% sure on what's going on here but generally these tools are referred to by *_EXE instead of the target for cross-compile (specifically the NATIVE stuff you're seeing) because they're precursors that need to run on the host. So eg mlir-linalg-ods-yaml-gen is built for host instead of target because it generates source at build time of mlir-opt and etc:

add_mlir_tool(mlir-linalg-ods-yaml-gen
mlir-linalg-ods-yaml-gen.cpp
)
llvm_update_compile_flags(mlir-linalg-ods-yaml-gen)
target_link_libraries(mlir-linalg-ods-yaml-gen PRIVATE
MLIRIR
MLIRSupport
MLIRParser
)
setup_host_tool(mlir-linalg-ods-yaml-gen MLIR_LINALG_ODS_YAML_GEN MLIR_LINALG_ODS_YAML_GEN_EXE MLIR_LINALG_ODS_YAML_GEN_TARGET)

Looking at mlir-irdl-to-cpp/CMakeLists.txt I see someone tried to maybe do the same thing?? but didn't quite nail it? Then again I'm not sure what the intent for this tool is. But certainly if you want add_irdl_to_cpp_target to be run in the service of e.g. building mlir-opt then you need a host tool and so you wouldn't want to DEPEND on the target.

@makslevental
Copy link
Contributor

Hmm looking at the custom command for add_linalg_ods_yaml_gen I see it does depend on MLIR_LINALG_ODS_YAML_GEN_TARGET:

COMMAND ${MLIR_LINALG_ODS_YAML_GEN_EXE} ${YAML_AST_SOURCE} -o-ods-decl=${GEN_ODS_FILE} -o-impl=${GEN_CPP_FILE}
MAIN_DEPENDENCY
${YAML_AST_SOURCE}
DEPENDS
${MLIR_LINALG_ODS_YAML_GEN_TARGET})

Okay in the case maybe this is kosher - although that CMake for the tool itself is still fishy but 🤷.

@Moxinilian
Copy link
Member

Moxinilian commented Jul 3, 2025

This tool behaves exactly like mlir-tblgen (in fact it serves the same purpose). So it should be built on the host platform, not on the target platform. I also understood it should be referenced via EXE as it is obtained from the NATIVE build. So the problem seems to be that in your environment @arthurqiu it is not able to find how to build it? I had tried before that it works while cross-compiling and it did. Are you sure your environment is correctly configured? In any case it should work no matter what, so I’d like to know what failed in your set up.

@Moxinilian
Copy link
Member

Also maybe I just misremember what I did at the time and this works for incremental rebuilds if the tool change. I can verify it does if you don’t have time but I don’t have much time either right now so it may take a bit.

@Moxinilian
Copy link
Member

Moxinilian commented Jul 3, 2025

I have reproduced the problem I was referring to with this patch applied. But the good news is that I also tried having the target depend on both $MLIR_IRDL_TO_CPP_EXE and $MLIR_IRDL_TO_CPP_TARGET and it seems to not reproduce the problem (because the EXE dependency still retriggers the build). If I understand your problem correctly, it should also solve yours. Please let me know if that works.

@arthurqiu arthurqiu force-pushed the aq/fix_irtdtocpp_cross_compile branch from f872c41 to 24e5428 Compare July 4, 2025 07:57
@arthurqiu arthurqiu force-pushed the aq/fix_irtdtocpp_cross_compile branch from 24e5428 to 4ab2b9a Compare July 4, 2025 07:58
@arthurqiu
Copy link
Contributor Author

I have reproduced the problem I was referring to with this patch applied. But the good news is that I also tried having the target depend on both $MLIR_IRDL_TO_CPP_EXE and $MLIR_IRDL_TO_CPP_TARGET and it seems to not reproduce the problem (because the EXE dependency still retriggers the build). If I understand your problem correctly, it should also solve yours. Please let me know if that works.

It works for me. And this explains why we need both:

# We need both _TABLEGEN_TARGET and _TABLEGEN_EXE in the DEPENDS list
# (both the target and the file) to have .inc files rebuilt on
# a tablegen change, as cmake does not propagate file-level dependencies
# of custom targets. See the following ticket for more information:
# https://cmake.org/Bug/view.php?id=15858
# The dependency on both, the target and the file, produces the same
# dependency twice in the result file when
# ("${${project}_TABLEGEN_TARGET}" STREQUAL "${${project}_TABLEGEN_EXE}")
# but lets us having smaller and cleaner code here.

@Moxinilian Moxinilian merged commit 03cfba4 into llvm:main Jul 4, 2025
9 checks passed
@Moxinilian
Copy link
Member

Well it seems like I can’t accept now that I merged it. Anyway, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants