Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
07371ca964 Improve CMake download/extract reliability by switching to curl/tar
This improves reliability of WebKit downloads that were causing intermittent
build failures with errors like:

    ninja: error: '<dir>/webkit-<sha>/lib/libWTF.a', needed by 'bun-profile', missing and no known rule to make it

Root cause: CMake's file(DOWNLOAD) and file(ARCHIVE_EXTRACT) can have timing
issues when downloads/extracts are interrupted or when filesystems are slow.

Changes:
- Replace file(DOWNLOAD) with curl in DownloadUrl.cmake for more reliable downloads
- Replace file(ARCHIVE_EXTRACT) with tar/unzip for more atomic extraction
- Update SetupWebKit.cmake to use the DownloadUrl.cmake script wrapper
- Add proper error handling and directory creation

Note: This still runs during CMake's configure phase (not build phase) because
the library files must be known at configure time for target_link_libraries().
Moving to build phase would require significant refactoring of how WebKit
libraries are referenced. The curl/tar approach provides better atomicity and
error handling than the built-in file() commands.

Testing:
- Deleted WebKit cache and verified clean build works
- WebKit downloads and extracts correctly using curl/tar
- Build completes successfully with all libraries present

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 03:11:48 +00:00
2 changed files with 71 additions and 22 deletions

View File

@@ -23,6 +23,7 @@ set(DOWNLOAD_TMP_PATH ${TMP_PATH}/${DOWNLOAD_ID}-${RANDOM_ID})
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_PATH}/tmp)
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
file(MAKE_DIRECTORY ${DOWNLOAD_TMP_PATH})
if(DOWNLOAD_ACCEPT_HEADER)
set(DOWNLOAD_ACCEPT_HEADER "Accept: ${DOWNLOAD_ACCEPT_HEADER}")
@@ -38,19 +39,23 @@ foreach(i RANGE 10)
else()
message(STATUS "Downloading ${DOWNLOAD_URL}... (retry ${i})")
endif()
file(DOWNLOAD
${DOWNLOAD_URL}
${DOWNLOAD_TMP_FILE_${i}}
HTTPHEADER "User-Agent: cmake/${CMAKE_VERSION}"
HTTPHEADER ${DOWNLOAD_ACCEPT_HEADER}
STATUS DOWNLOAD_STATUS
INACTIVITY_TIMEOUT 60
TIMEOUT 180
SHOW_PROGRESS
# Use curl instead of file(DOWNLOAD) for better reliability
execute_process(
COMMAND curl
-L
--fail
--connect-timeout 60
--max-time 180
-H "User-Agent: cmake/${CMAKE_VERSION}"
-H "${DOWNLOAD_ACCEPT_HEADER}"
-o ${DOWNLOAD_TMP_FILE_${i}}
${DOWNLOAD_URL}
RESULT_VARIABLE DOWNLOAD_STATUS_CODE
ERROR_VARIABLE DOWNLOAD_STATUS_TEXT
ERROR_STRIP_TRAILING_WHITESPACE
)
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_STATUS_CODE)
if(DOWNLOAD_STATUS_CODE EQUAL 0)
if(NOT EXISTS ${DOWNLOAD_TMP_FILE_${i}})
message(WARNING "Download failed: result is ok, but file does not exist: ${DOWNLOAD_TMP_FILE_${i}}")
@@ -61,7 +66,6 @@ foreach(i RANGE 10)
break()
endif()
list(GET DOWNLOAD_STATUS 1 DOWNLOAD_STATUS_TEXT)
file(REMOVE ${DOWNLOAD_TMP_FILE_${i}})
message(WARNING "Download failed: ${DOWNLOAD_STATUS_CODE} ${DOWNLOAD_STATUS_TEXT}")
endforeach()
@@ -76,11 +80,45 @@ if(DOWNLOAD_FILENAME MATCHES "\\.(zip|tar|gz|xz)$")
message(STATUS "Extracting ${DOWNLOAD_FILENAME}...")
set(DOWNLOAD_TMP_EXTRACT ${DOWNLOAD_TMP_PATH}/extract)
file(ARCHIVE_EXTRACT
INPUT ${DOWNLOAD_TMP_FILE}
DESTINATION ${DOWNLOAD_TMP_EXTRACT}
TOUCH
)
file(MAKE_DIRECTORY ${DOWNLOAD_TMP_EXTRACT})
# Use tar/unzip instead of file(ARCHIVE_EXTRACT) for better reliability
if(DOWNLOAD_FILENAME MATCHES "\\.zip$")
execute_process(
COMMAND unzip -q ${DOWNLOAD_TMP_FILE} -d ${DOWNLOAD_TMP_EXTRACT}
RESULT_VARIABLE EXTRACT_RESULT
ERROR_VARIABLE EXTRACT_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
elseif(DOWNLOAD_FILENAME MATCHES "\\.(tar\\.gz|tgz)$")
execute_process(
COMMAND tar -xzf ${DOWNLOAD_TMP_FILE} -C ${DOWNLOAD_TMP_EXTRACT}
RESULT_VARIABLE EXTRACT_RESULT
ERROR_VARIABLE EXTRACT_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
elseif(DOWNLOAD_FILENAME MATCHES "\\.(tar\\.xz|txz)$")
execute_process(
COMMAND tar -xJf ${DOWNLOAD_TMP_FILE} -C ${DOWNLOAD_TMP_EXTRACT}
RESULT_VARIABLE EXTRACT_RESULT
ERROR_VARIABLE EXTRACT_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
elseif(DOWNLOAD_FILENAME MATCHES "\\.tar$")
execute_process(
COMMAND tar -xf ${DOWNLOAD_TMP_FILE} -C ${DOWNLOAD_TMP_EXTRACT}
RESULT_VARIABLE EXTRACT_RESULT
ERROR_VARIABLE EXTRACT_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
else()
message(FATAL_ERROR "Unsupported archive format: ${DOWNLOAD_FILENAME}")
endif()
if(NOT EXTRACT_RESULT EQUAL 0)
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
message(FATAL_ERROR "Extract failed: ${EXTRACT_ERROR}")
endif()
file(REMOVE ${DOWNLOAD_TMP_FILE})

View File

@@ -90,11 +90,22 @@ if(EXISTS ${WEBKIT_PATH}/package.json)
endif()
endif()
file(DOWNLOAD ${WEBKIT_DOWNLOAD_URL} ${CACHE_PATH}/${WEBKIT_FILENAME} SHOW_PROGRESS)
file(ARCHIVE_EXTRACT INPUT ${CACHE_PATH}/${WEBKIT_FILENAME} DESTINATION ${CACHE_PATH} TOUCH)
file(REMOVE ${CACHE_PATH}/${WEBKIT_FILENAME})
file(REMOVE_RECURSE ${WEBKIT_PATH})
file(RENAME ${CACHE_PATH}/bun-webkit ${WEBKIT_PATH})
# Use DownloadUrl.cmake script for reliable download/extract with curl/tar
# This still runs at configure time, but curl/tar are more atomic than file() commands
execute_process(
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_URL=${WEBKIT_DOWNLOAD_URL}
-DDOWNLOAD_PATH=${WEBKIT_PATH}
-P ${CMAKE_CURRENT_LIST_DIR}/../scripts/DownloadUrl.cmake
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE WEBKIT_DOWNLOAD_ERROR
RESULT_VARIABLE WEBKIT_DOWNLOAD_RESULT
)
if(NOT WEBKIT_DOWNLOAD_RESULT EQUAL 0)
message(FATAL_ERROR "WebKit download failed: ${WEBKIT_DOWNLOAD_ERROR}")
endif()
if(APPLE)
file(REMOVE_RECURSE ${WEBKIT_INCLUDE_PATH}/unicode)