Skip to content

IRDL-to-C++: support cross-compilation #17

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

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mlir/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ include_directories(BEFORE
# Adding tools/mlir-tblgen here as calling add_tablegen sets some variables like
# MLIR_TABLEGEN_EXE in PARENT_SCOPE which gets lost if that folder is included
# from another directory like tools
add_subdirectory(tools/mlir-irdl-to-cpp)
add_subdirectory(tools/mlir-linalg-ods-gen)
add_subdirectory(tools/mlir-pdll)
add_subdirectory(tools/mlir-tblgen)
Expand Down
4 changes: 2 additions & 2 deletions mlir/cmake/modules/IRDLToCpp.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function(add_irdl_to_cpp_target target irdl_file)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
COMMAND $<TARGET_FILE:mlir-irdl-to-cpp> ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
DEPENDS mlir-irdl-to-cpp ${irdl_file}
COMMAND ${MLIR_IRDL_TO_CPP_EXE} ${CMAKE_CURRENT_SOURCE_DIR}/${irdl_file} -o ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc
DEPENDS ${MLIR_IRDL_TO_CPP_TARGET} ${irdl_file}
COMMENT "Building ${irdl_file}..."
)
add_custom_target(${target} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${irdl_file}.cpp.inc)
Expand Down
1 change: 0 additions & 1 deletion mlir/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
add_subdirectory(mlir-irdl-to-cpp)
add_subdirectory(mlir-lsp-server)
add_subdirectory(mlir-opt)
add_subdirectory(mlir-parser-fuzzer)
Expand Down
23 changes: 22 additions & 1 deletion mlir/tools/mlir-irdl-to-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
add_mlir_tool(mlir-irdl-to-cpp
add_llvm_executable(mlir-irdl-to-cpp
mlir-irdl-to-cpp.cpp
)
mlir_target_link_libraries(mlir-irdl-to-cpp
PRIVATE
MLIRTargetIRDLToCpp
)

# Set up a native build when cross-compiling.
if(LLVM_USE_HOST_TOOLS)
build_native_tool(
mlir-irdl-to-cpp
MLIR_IRDL_TO_CPP_EXE

# Native tool must depend on target tool so that the native tool gets
# properly rebuilt when the target tool changes.
DEPENDS mlir-irdl-to-cpp
)
add_custom_target(mlir-irdl-to-cpp-host DEPENDS ${MLIR_IRDL_TO_CPP_EXE})
set(MLIR_IRDL_TO_CPP_TARGET mlir-irdl-to-cpp-host)
else()
set(MLIR_IRDL_TO_CPP_EXE $<TARGET_FILE:mlir-irdl-to-cpp>)
set(MLIR_IRDL_TO_CPP_TARGET mlir-irdl-to-cpp)
endif()

# Save the executable path and target name to the cache to expose it globally.
set(MLIR_IRDL_TO_CPP_EXE "${MLIR_IRDL_TO_CPP_EXE}" CACHE INTERNAL "")
set(MLIR_IRDL_TO_CPP_TARGET "${MLIR_IRDL_TO_CPP_TARGET}" CACHE INTERNAL "")