mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
### What does this PR do?
Before this change, downloading WebKit would fail silently if there were
e.g. a connection or TLS certificate issue. I experienced this when
trying to build bun in an overly-restrictive sandbox.
After this change, the failure reason will be visible.
### How did you verify your code works?
<details>
<summary>Brought down my network interface and ran the build:</summary>
```sh
$ node ./scripts/build.mjs \
-GNinja \
-DCMAKE_BUILD_TYPE=Debug \
-B build/debug \
--log-level=NOTICE \
-DBUN_EXECUTABLE="$(which node)" \
-DNPM_EXECUTABLE="$(which npm)" \
-DZIG_EXECUTABLE="$(which zig)" \
-DENABLE_ASAN=OFF
Globbed 1971 sources [180.67ms]
CMake Configure
$ cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -B /work/bun/build/debug --log-level NOTICE -DBUN_EXECUTABLE=/bin/node -DNPM_EXECUTABLE=/bin/npm -DZIG_EXECUTABLE=/bin/zig -DENABLE_ASAN=OFF -S /work/bun -DCACHE_STRATEGY=auto
sccache: Using local cache strategy.
...
```
</details>
Result:
```
CMake Error at cmake/tools/SetupWebKit.cmake:99 (message):
Failed to download WebKit: 6;"Could not resolve hostname"
Call Stack (most recent call first):
cmake/targets/BuildBun.cmake:1204 (include)
CMakeLists.txt:66 (include)
```
109 lines
3.3 KiB
CMake
109 lines
3.3 KiB
CMake
option(WEBKIT_VERSION "The version of WebKit to use")
|
|
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
|
|
|
|
if(NOT WEBKIT_VERSION)
|
|
set(WEBKIT_VERSION 863778130931e0081a688f48e8479b8ee61b9507)
|
|
endif()
|
|
|
|
string(SUBSTRING ${WEBKIT_VERSION} 0 16 WEBKIT_VERSION_PREFIX)
|
|
|
|
if(WEBKIT_LOCAL)
|
|
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
|
|
else()
|
|
set(DEFAULT_WEBKIT_PATH ${CACHE_PATH}/webkit-${WEBKIT_VERSION_PREFIX})
|
|
endif()
|
|
|
|
option(WEBKIT_PATH "The path to the WebKit directory")
|
|
|
|
if(NOT WEBKIT_PATH)
|
|
set(WEBKIT_PATH ${DEFAULT_WEBKIT_PATH})
|
|
endif()
|
|
|
|
set(WEBKIT_INCLUDE_PATH ${WEBKIT_PATH}/include)
|
|
set(WEBKIT_LIB_PATH ${WEBKIT_PATH}/lib)
|
|
|
|
if(WEBKIT_LOCAL)
|
|
if(EXISTS ${WEBKIT_PATH}/cmakeconfig.h)
|
|
# You may need to run:
|
|
# make jsc-compile-debug jsc-copy-headers
|
|
include_directories(
|
|
${WEBKIT_PATH}
|
|
${WEBKIT_PATH}/JavaScriptCore/Headers/JavaScriptCore
|
|
${WEBKIT_PATH}/JavaScriptCore/PrivateHeaders
|
|
${WEBKIT_PATH}/bmalloc/Headers
|
|
${WEBKIT_PATH}/WTF/Headers
|
|
${WEBKIT_PATH}/JavaScriptCore/DerivedSources/inspector
|
|
${WEBKIT_PATH}/JavaScriptCore/PrivateHeaders/JavaScriptCore
|
|
)
|
|
endif()
|
|
|
|
# After this point, only prebuilt WebKit is supported
|
|
return()
|
|
endif()
|
|
|
|
if(WIN32)
|
|
set(WEBKIT_OS "windows")
|
|
elseif(APPLE)
|
|
set(WEBKIT_OS "macos")
|
|
elseif(UNIX)
|
|
set(WEBKIT_OS "linux")
|
|
else()
|
|
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}")
|
|
endif()
|
|
|
|
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
|
set(WEBKIT_ARCH "arm64")
|
|
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|x64|AMD64")
|
|
set(WEBKIT_ARCH "amd64")
|
|
else()
|
|
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
|
|
endif()
|
|
|
|
if(LINUX AND ABI STREQUAL "musl")
|
|
set(WEBKIT_SUFFIX "-musl")
|
|
endif()
|
|
|
|
if(DEBUG)
|
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-debug")
|
|
elseif(ENABLE_LTO)
|
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-lto")
|
|
else()
|
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}")
|
|
endif()
|
|
|
|
if(ENABLE_ASAN)
|
|
# We cannot mix and match ASan Bun + non-ASan WebKit, or vice versa, because some WebKit classes
|
|
# change their layout according to whether ASan is used, for example:
|
|
# https://github.com/oven-sh/WebKit/blob/eda8b0fb4fb1aa23db9c2b00933df8b58bcdd289/Source/WTF/wtf/Vector.h#L682
|
|
set(WEBKIT_SUFFIX "${WEBKIT_SUFFIX}-asan")
|
|
endif()
|
|
|
|
setx(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
|
set(WEBKIT_FILENAME ${WEBKIT_NAME}.tar.gz)
|
|
setx(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_FILENAME})
|
|
|
|
if(EXISTS ${WEBKIT_PATH}/package.json)
|
|
file(READ ${WEBKIT_PATH}/package.json WEBKIT_PACKAGE_JSON)
|
|
|
|
if(WEBKIT_PACKAGE_JSON MATCHES ${WEBKIT_VERSION})
|
|
return()
|
|
endif()
|
|
endif()
|
|
|
|
file(
|
|
DOWNLOAD ${WEBKIT_DOWNLOAD_URL} ${CACHE_PATH}/${WEBKIT_FILENAME} SHOW_PROGRESS
|
|
STATUS WEBKIT_DOWNLOAD_STATUS
|
|
)
|
|
if(NOT "${WEBKIT_DOWNLOAD_STATUS}" MATCHES "^0;")
|
|
message(FATAL_ERROR "Failed to download WebKit: ${WEBKIT_DOWNLOAD_STATUS}")
|
|
endif()
|
|
|
|
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})
|
|
|
|
if(APPLE)
|
|
file(REMOVE_RECURSE ${WEBKIT_INCLUDE_PATH}/unicode)
|
|
endif()
|