mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
### What does this PR do? Lets us write and run unit tests directly in Zig. Running Zig unit tests in CI is blocked by https://github.com/ziglang/zig/issues/23281. We can un-comment relevant code once this is fixed. #### Workflow > I'll finish writing this up later, but some initial points are below. > Tl;Dr: `bun build:test` Test binaries can be made for any kind of build. They are called `<bun>-test` and live next to their corresponding `bun` bin. For example, debug tests compile to `build/debug/bun-debug-test`. Test binaries re-use most cmake/zig build steps from normal bun binaries, so building one after a normal bun build is pretty fast. ### How did you verify your code works? I tested that my tests run tests.
72 lines
2.1 KiB
CMake
72 lines
2.1 KiB
CMake
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
|
|
message(STATUS "Running script: ${SCRIPT_NAME}")
|
|
|
|
if(NOT ZIG_PATH OR NOT ZIG_COMMIT)
|
|
message(FATAL_ERROR "ZIG_PATH and ZIG_COMMIT required")
|
|
endif()
|
|
|
|
if(CMAKE_HOST_APPLE)
|
|
set(ZIG_OS_ABI "macos-none")
|
|
elseif(CMAKE_HOST_WIN32)
|
|
set(ZIG_OS_ABI "windows-gnu")
|
|
elseif(CMAKE_HOST_UNIX)
|
|
set(ZIG_OS_ABI "linux-musl")
|
|
else()
|
|
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_HOST_SYSTEM_NAME}")
|
|
endif()
|
|
|
|
# In script mode, using -P, this variable is not set
|
|
if(NOT DEFINED CMAKE_HOST_SYSTEM_PROCESSOR)
|
|
cmake_host_system_information(RESULT CMAKE_HOST_SYSTEM_PROCESSOR QUERY OS_PLATFORM)
|
|
endif()
|
|
|
|
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
|
|
set(ZIG_ARCH "aarch64")
|
|
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
|
|
set(ZIG_ARCH "x86_64")
|
|
else()
|
|
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
|
|
endif()
|
|
|
|
set(ZIG_NAME bootstrap-${ZIG_ARCH}-${ZIG_OS_ABI})
|
|
if(ZIG_COMPILER_SAFE)
|
|
set(ZIG_NAME ${ZIG_NAME}-ReleaseSafe)
|
|
endif()
|
|
set(ZIG_FILENAME ${ZIG_NAME}.zip)
|
|
|
|
if(CMAKE_HOST_WIN32)
|
|
set(ZIG_EXE "zig.exe")
|
|
else()
|
|
set(ZIG_EXE "zig")
|
|
endif()
|
|
|
|
set(ZIG_DOWNLOAD_URL https://github.com/oven-sh/zig/releases/download/autobuild-${ZIG_COMMIT}/${ZIG_FILENAME})
|
|
|
|
execute_process(
|
|
COMMAND
|
|
${CMAKE_COMMAND}
|
|
-DDOWNLOAD_URL=${ZIG_DOWNLOAD_URL}
|
|
-DDOWNLOAD_PATH=${ZIG_PATH}
|
|
-P ${CMAKE_CURRENT_LIST_DIR}/DownloadUrl.cmake
|
|
ERROR_STRIP_TRAILING_WHITESPACE
|
|
ERROR_VARIABLE
|
|
ZIG_DOWNLOAD_ERROR
|
|
RESULT_VARIABLE
|
|
ZIG_DOWNLOAD_RESULT
|
|
)
|
|
|
|
if(NOT ZIG_DOWNLOAD_RESULT EQUAL 0)
|
|
message(FATAL_ERROR "Download failed: ${ZIG_DOWNLOAD_ERROR}")
|
|
endif()
|
|
|
|
if(NOT EXISTS ${ZIG_PATH}/${ZIG_EXE})
|
|
message(FATAL_ERROR "Executable not found: \"${ZIG_PATH}/${ZIG_EXE}\"")
|
|
endif()
|
|
|
|
# Tools like VSCode need a stable path to the zig executable, on both Unix and Windows
|
|
# To workaround this, we create a `zig.exe` & `zls.exe` symlink on Unix.
|
|
if(NOT WIN32)
|
|
file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC)
|
|
file(CREATE_LINK ${ZIG_PATH}/zls ${ZIG_PATH}/zls.exe SYMBOLIC)
|
|
endif()
|