Skip to content
Merged
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
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, you could use FetchContent to enable building without the .git directory. This will allow us to completely remove .gitmodules and the 3rdparty directory.

An example: https://github.com/metaopt/optree/blob/4b2aad3276ec391cc68b9445cf18d163dea8aa9c/CMakeLists.txt#L258-L283

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I'll take alook

Copy link
Member Author

Choose a reason for hiding this comment

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

I think at least the 3rdparty/tvm directory isn’t very stable — we occasionally need to update it. Managing it with Git would make things much more convenient. Once it becomes more stable, we can consider switching to that approach.

find_package(Git QUIET)
if(Git_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
)
if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0)
message(
FATAL_ERROR
"Failed to initialize git submodules. Please run "
"`git submodule update --init --recursive` and re-run CMake."
)
endif()
Comment on lines +16 to +27
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Prevent hangs and improve diagnostics for submodule update

Add non-interactive env, timeouts, and capture stderr/stdout. Otherwise CMake can hang (e.g., auth prompts, offline CI) and failures lack context.

-    execute_process(
-      COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
-      WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
-      RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
-    )
+    # Sync URLs and update submodules non-interactively with timeouts
+    execute_process(
+      COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
+              ${GIT_EXECUTABLE} submodule sync --recursive
+      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+      RESULT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_RESULT
+      OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_OUT
+      ERROR_VARIABLE  TILELANG_GIT_SUBMODULE_SYNC_ERR
+      TIMEOUT 120
+    )
+    execute_process(
+      COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
+              ${GIT_EXECUTABLE} submodule update --init --recursive
+      WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+      RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
+      OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_OUT
+      ERROR_VARIABLE  TILELANG_GIT_SUBMODULE_ERR
+      TIMEOUT 600
+    )
     if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0)
       message(
         FATAL_ERROR
-          "Failed to initialize git submodules. Please run "
-          "`git submodule update --init --recursive` and re-run CMake."
+          "Failed to initialize git submodules. Please run "
+          "`git submodule update --init --recursive` and re-run CMake.\n"
+          "Git stderr:\n${TILELANG_GIT_SUBMODULE_ERR}"
       )
     endif()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
execute_process(
COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
)
if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0)
message(
FATAL_ERROR
"Failed to initialize git submodules. Please run "
"`git submodule update --init --recursive` and re-run CMake."
)
endif()
# Sync URLs and update submodules non-interactively with timeouts
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
${GIT_EXECUTABLE} submodule sync --recursive
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_RESULT
OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_OUT
ERROR_VARIABLE TILELANG_GIT_SUBMODULE_SYNC_ERR
TIMEOUT 120
)
execute_process(
COMMAND ${CMAKE_COMMAND} -E env "GIT_TERMINAL_PROMPT=0"
${GIT_EXECUTABLE} submodule update --init --recursive
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
RESULT_VARIABLE TILELANG_GIT_SUBMODULE_RESULT
OUTPUT_VARIABLE TILELANG_GIT_SUBMODULE_OUT
ERROR_VARIABLE TILELANG_GIT_SUBMODULE_ERR
TIMEOUT 600
)
if(NOT TILELANG_GIT_SUBMODULE_RESULT EQUAL 0)
message(
FATAL_ERROR
"Failed to initialize git submodules. Please run "
"`git submodule update --init --recursive` and re-run CMake.\n"
"Git stderr:\n${TILELANG_GIT_SUBMODULE_ERR}"
)
endif()

else()
message(
FATAL_ERROR
"Git is required to initialize TileLang submodules. "
"Please install git or fetch the submodules manually."
)
endif()
endif()

find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}" CACHE STRING "C compiler launcher")
Expand Down
Loading