mirror of
https://github.com/oven-sh/bun
synced 2026-02-03 15:38:46 +00:00
Compare commits
53 Commits
jarred/rem
...
fix-format
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88063eaad5 | ||
|
|
da2d1e12ed | ||
|
|
6b54dbfa07 | ||
|
|
1dfa557ca4 | ||
|
|
29d1b4db74 | ||
|
|
85edb39a2f | ||
|
|
f0384f39b7 | ||
|
|
2e1b19b9fd | ||
|
|
53ce1ff6c1 | ||
|
|
eee9b51df3 | ||
|
|
f0036cc6c1 | ||
|
|
77a25c0188 | ||
|
|
a3777b8c22 | ||
|
|
0d9d7a3436 | ||
|
|
d5e7846eaf | ||
|
|
582a53e26e | ||
|
|
57d9cfc24d | ||
|
|
31dc58fa79 | ||
|
|
03bb9fd9b5 | ||
|
|
f270f235c8 | ||
|
|
8d1b5856d3 | ||
|
|
bf488d0b19 | ||
|
|
9dc0672840 | ||
|
|
b1d0cb0ea3 | ||
|
|
155ba7ebdf | ||
|
|
3757a3e30f | ||
|
|
4b443db0d8 | ||
|
|
d74ae08946 | ||
|
|
a7a5ed2fba | ||
|
|
7d7c9877a4 | ||
|
|
1cd43f5bae | ||
|
|
56b6ed6d97 | ||
|
|
85dd8ef0d4 | ||
|
|
6cb0de3921 | ||
|
|
2c1dcb5a1d | ||
|
|
d3f3900da7 | ||
|
|
ef18731db1 | ||
|
|
7fb15e5a03 | ||
|
|
2b017cd0ad | ||
|
|
9f857fa418 | ||
|
|
1cde69d0f1 | ||
|
|
800e378b6e | ||
|
|
dfe8fb50d9 | ||
|
|
0f6cfc0b16 | ||
|
|
019cfb7927 | ||
|
|
7887689fd0 | ||
|
|
888d8301ca | ||
|
|
704c169e04 | ||
|
|
c16e34078a | ||
|
|
bc9e022c86 | ||
|
|
a88b8130b9 | ||
|
|
2139e8442a | ||
|
|
f50a80a7c1 |
@@ -12,14 +12,14 @@ steps:
|
||||
- key: "darwin-aarch64"
|
||||
group: ":darwin: aarch64"
|
||||
steps:
|
||||
- key: "darwin-aarch64-build-deps"
|
||||
label: ":darwin: aarch64 - build-deps"
|
||||
- key: "darwin-aarch64-build-vendor"
|
||||
label: ":darwin: aarch64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-darwin"
|
||||
os: "darwin"
|
||||
arch: "aarch64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "darwin-aarch64-build-cpp"
|
||||
label: ":darwin: aarch64 - build-cpp"
|
||||
@@ -46,7 +46,7 @@ steps:
|
||||
os: "darwin"
|
||||
arch: "aarch64"
|
||||
depends_on:
|
||||
- "darwin-aarch64-build-deps"
|
||||
- "darwin-aarch64-build-vendor"
|
||||
- "darwin-aarch64-build-cpp"
|
||||
- "darwin-aarch64-build-zig"
|
||||
env:
|
||||
@@ -114,14 +114,14 @@ steps:
|
||||
- key: "darwin-x64"
|
||||
group: ":darwin: x64"
|
||||
steps:
|
||||
- key: "darwin-x64-build-deps"
|
||||
label: ":darwin: x64 - build-deps"
|
||||
- key: "darwin-x64-build-vendor"
|
||||
label: ":darwin: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-darwin"
|
||||
os: "darwin"
|
||||
arch: "x64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "darwin-x64-build-cpp"
|
||||
label: ":darwin: x64 - build-cpp"
|
||||
@@ -148,7 +148,7 @@ steps:
|
||||
os: "darwin"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "darwin-x64-build-deps"
|
||||
- "darwin-x64-build-vendor"
|
||||
- "darwin-x64-build-cpp"
|
||||
- "darwin-x64-build-zig"
|
||||
env:
|
||||
@@ -216,14 +216,14 @@ steps:
|
||||
- key: "linux-x64"
|
||||
group: ":linux: x64"
|
||||
steps:
|
||||
- key: "linux-x64-build-deps"
|
||||
label: ":linux: x64 - build-deps"
|
||||
- key: "linux-x64-build-vendor"
|
||||
label: ":linux: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-x64-build-cpp"
|
||||
label: ":linux: x64 - build-cpp"
|
||||
@@ -250,7 +250,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "linux-x64-build-deps"
|
||||
- "linux-x64-build-vendor"
|
||||
- "linux-x64-build-cpp"
|
||||
- "linux-x64-build-zig"
|
||||
env:
|
||||
@@ -349,8 +349,8 @@ steps:
|
||||
- key: "linux-x64-baseline"
|
||||
group: ":linux: x64-baseline"
|
||||
steps:
|
||||
- key: "linux-x64-baseline-build-deps"
|
||||
label: ":linux: x64-baseline - build-deps"
|
||||
- key: "linux-x64-baseline-build-vendor"
|
||||
label: ":linux: x64-baseline - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
@@ -358,7 +358,7 @@ steps:
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-x64-baseline-build-cpp"
|
||||
label: ":linux: x64-baseline - build-cpp"
|
||||
@@ -388,7 +388,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "linux-x64-baseline-build-deps"
|
||||
- "linux-x64-baseline-build-vendor"
|
||||
- "linux-x64-baseline-build-cpp"
|
||||
- "linux-x64-baseline-build-zig"
|
||||
env:
|
||||
@@ -488,14 +488,14 @@ steps:
|
||||
- key: "linux-aarch64"
|
||||
group: ":linux: aarch64"
|
||||
steps:
|
||||
- key: "linux-aarch64-build-deps"
|
||||
label: ":linux: aarch64 - build-deps"
|
||||
- key: "linux-aarch64-build-vendor"
|
||||
label: ":linux: aarch64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
arch: "aarch64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-aarch64-build-cpp"
|
||||
label: ":linux: aarch64 - build-cpp"
|
||||
@@ -522,7 +522,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "aarch64"
|
||||
depends_on:
|
||||
- "linux-aarch64-build-deps"
|
||||
- "linux-aarch64-build-vendor"
|
||||
- "linux-aarch64-build-cpp"
|
||||
- "linux-aarch64-build-zig"
|
||||
env:
|
||||
@@ -621,18 +621,14 @@ steps:
|
||||
- key: "windows-x64"
|
||||
group: ":windows: x64"
|
||||
steps:
|
||||
- key: "windows-x64-build-deps"
|
||||
label: ":windows: x64 - build-deps"
|
||||
- key: "windows-x64-build-vendor"
|
||||
label: ":windows: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "windows-x64-build-cpp"
|
||||
label: ":windows: x64 - build-cpp"
|
||||
@@ -640,10 +636,6 @@ steps:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
BUN_CPP_ONLY: "ON"
|
||||
command:
|
||||
@@ -663,13 +655,9 @@ steps:
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "windows-x64-build-deps"
|
||||
- "windows-x64-build-vendor"
|
||||
- "windows-x64-build-cpp"
|
||||
- "windows-x64-build-zig"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
BUN_LINK_ONLY: "ON"
|
||||
command:
|
||||
@@ -704,20 +692,16 @@ steps:
|
||||
- key: "windows-x64-baseline"
|
||||
group: ":windows: x64-baseline"
|
||||
steps:
|
||||
- key: "windows-x64-baseline-build-deps"
|
||||
label: ":windows: x64-baseline - build-deps"
|
||||
- key: "windows-x64-baseline-build-vendor"
|
||||
label: ":windows: x64-baseline - build-vendor"
|
||||
agents:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "windows-x64-baseline-build-cpp"
|
||||
label: ":windows: x64-baseline - build-cpp"
|
||||
@@ -725,10 +709,6 @@ steps:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
BUN_CPP_ONLY: "ON"
|
||||
@@ -751,13 +731,9 @@ steps:
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "windows-x64-baseline-build-deps"
|
||||
- "windows-x64-baseline-build-vendor"
|
||||
- "windows-x64-baseline-build-cpp"
|
||||
- "windows-x64-baseline-build-zig"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
BUN_LINK_ONLY: "ON"
|
||||
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -142,6 +142,9 @@ test/node.js/upstream
|
||||
scripts/env.local
|
||||
*.generated.ts
|
||||
|
||||
# Temporary files
|
||||
/tmp
|
||||
|
||||
# Dependencies
|
||||
/vendor
|
||||
|
||||
|
||||
52
.vscode/tasks.json
vendored
52
.vscode/tasks.json
vendored
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Install Dependencies",
|
||||
"command": "scripts/all-dependencies.sh",
|
||||
"windows": {
|
||||
"command": "scripts/all-dependencies.ps1",
|
||||
},
|
||||
"icon": {
|
||||
"id": "arrow-down",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Setup Environment",
|
||||
"dependsOn": ["Install Dependencies"],
|
||||
"command": "scripts/setup.sh",
|
||||
"windows": {
|
||||
"command": "scripts/setup.ps1",
|
||||
},
|
||||
"icon": {
|
||||
"id": "check",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Build Bun",
|
||||
"dependsOn": ["Setup Environment"],
|
||||
"command": "bun",
|
||||
"args": ["run", "build"],
|
||||
"icon": {
|
||||
"id": "gear",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
"isBuildCommand": true,
|
||||
"runOptions": {
|
||||
"instanceLimit": 1,
|
||||
"reevaluateOnRerun": true,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -38,4 +38,25 @@ include(SetupRust)
|
||||
|
||||
# --- Targets ---
|
||||
|
||||
include(BuildBoringSSL)
|
||||
include(BuildBrotli)
|
||||
include(BuildCares)
|
||||
include(BuildLibDeflate)
|
||||
include(BuildLibuv)
|
||||
include(BuildLolHtml)
|
||||
include(BuildLshpack)
|
||||
include(BuildMimalloc)
|
||||
include(BuildPicoHTTPParser)
|
||||
include(BuildTinyCC)
|
||||
include(BuildSQLite)
|
||||
include(BuildWebKit)
|
||||
include(BuildZlib)
|
||||
include(BuildLibArchive) # must be loaded after zlib
|
||||
include(BuildZstd)
|
||||
include(BuildBun)
|
||||
|
||||
# --- Analysis ---
|
||||
|
||||
include(RunClangFormat)
|
||||
include(RunClangTidy)
|
||||
include(RunZigFormat)
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# clang: https://clang.llvm.org/docs/CommandGuide/clang.html
|
||||
# clang-cl: https://clang.llvm.org/docs/UsersManual.html#id11
|
||||
|
||||
# --- Macros ---
|
||||
|
||||
macro(setb variable)
|
||||
if(${variable})
|
||||
set(${variable} ON)
|
||||
@@ -11,20 +9,20 @@ macro(setb variable)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(targets WIN32 APPLE UNIX LINUX)
|
||||
|
||||
foreach(target ${targets})
|
||||
setb(${target})
|
||||
set(bvariables WIN32 APPLE UNIX LINUX)
|
||||
foreach(bvariable ${bvariables})
|
||||
setb(${bvariable})
|
||||
endforeach()
|
||||
|
||||
# --- CPU target ---
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|arm64|ARM64|aarch64|AARCH64")
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
|
||||
if(APPLE)
|
||||
register_compiler_flags(-mcpu=apple-m1)
|
||||
else()
|
||||
register_compiler_flags(-march=armv8-a+crc -mtune=ampere1)
|
||||
endif()
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
|
||||
if(ENABLE_BASELINE)
|
||||
register_compiler_flags(-march=nehalem)
|
||||
else()
|
||||
@@ -35,6 +33,7 @@ else()
|
||||
endif()
|
||||
|
||||
# --- MSVC runtime ---
|
||||
|
||||
if(WIN32)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Use static MSVC runtime"
|
||||
@@ -45,6 +44,7 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
# --- Optimization level ---
|
||||
|
||||
if(DEBUG)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Disable optimization"
|
||||
@@ -66,6 +66,7 @@ else()
|
||||
endif()
|
||||
|
||||
# --- Debug level ---
|
||||
|
||||
if(WIN32)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Enable debug symbols (.pdb)"
|
||||
@@ -97,6 +98,7 @@ endif()
|
||||
# -fno-eliminate-unused-debug-types # Don't eliminate unused debug symbols
|
||||
|
||||
# --- C/C++ flags ---
|
||||
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Disable C/C++ exceptions"
|
||||
-fno-exceptions ${UNIX}
|
||||
@@ -104,8 +106,8 @@ register_compiler_flags(
|
||||
)
|
||||
|
||||
register_compiler_flags(
|
||||
LANGUAGE CXX
|
||||
DESCRIPTION "Disable C++ static destructors"
|
||||
LANGUAGES CXX
|
||||
-Xclang ${WIN32}
|
||||
-fno-c++-static-destructors
|
||||
)
|
||||
@@ -149,9 +151,9 @@ register_compiler_flags(
|
||||
/Gw ${WIN32}
|
||||
)
|
||||
|
||||
# having this enabled in debug mode on macOS >=14 causes libarchive to fail to configure with the error:
|
||||
# This causes libarchive to fail on macOS, with the error:
|
||||
# > pid_t doesn't exist on this platform?
|
||||
if((DEBUG AND LINUX) OR((NOT DEBUG) AND UNIX))
|
||||
if((DEBUG AND LINUX) OR ((NOT DEBUG) AND UNIX))
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Emit an address-significance table"
|
||||
-faddrsig
|
||||
@@ -171,6 +173,7 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
# --- Linker flags ---
|
||||
|
||||
if(LINUX)
|
||||
register_linker_flags(
|
||||
DESCRIPTION "Disable relocation read-only (RELRO)"
|
||||
@@ -182,6 +185,7 @@ endif()
|
||||
|
||||
# Note: This is a helpful guide about assertions:
|
||||
# https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++
|
||||
|
||||
if(ENABLE_ASSERTIONS)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Do not eliminate null-pointer checks"
|
||||
@@ -227,6 +231,7 @@ else()
|
||||
endif()
|
||||
|
||||
# --- Diagnostics ---
|
||||
|
||||
if(UNIX)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Enable color diagnostics"
|
||||
@@ -240,6 +245,7 @@ register_compiler_flags(
|
||||
)
|
||||
|
||||
# --- LTO ---
|
||||
|
||||
if(ENABLE_LTO)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Enable link-time optimization (LTO)"
|
||||
@@ -249,8 +255,8 @@ if(ENABLE_LTO)
|
||||
|
||||
if(UNIX)
|
||||
register_compiler_flags(
|
||||
LANGUAGE CXX
|
||||
DESCRIPTION "Enable virtual tables"
|
||||
LANGUAGES CXX
|
||||
-fforce-emit-vtables
|
||||
-fwhole-program-vtables
|
||||
)
|
||||
@@ -265,6 +271,7 @@ if(ENABLE_LTO)
|
||||
endif()
|
||||
|
||||
# --- Remapping ---
|
||||
|
||||
if(UNIX)
|
||||
register_compiler_flags(
|
||||
DESCRIPTION "Remap source files"
|
||||
@@ -282,6 +289,12 @@ if(ENABLE_VALGRIND AND ARCH STREQUAL "x64")
|
||||
register_compiler_definitions(__SSE4_2__=0)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
# The $NOCANCEL variants of various system calls are activated by compiling
|
||||
# with __DARWIN_NON_CANCELABLE, which prevents them from being pthread cancellation points.
|
||||
register_compiler_definitions(__DARWIN_NON_CANCELABLE=1)
|
||||
endif()
|
||||
|
||||
# --- Other ---
|
||||
|
||||
# Workaround for CMake and clang-cl bug.
|
||||
|
||||
@@ -298,19 +298,18 @@ endfunction()
|
||||
# SOURCES string[] - The files that this command depends on
|
||||
# OUTPUTS string[] - The files that this command produces
|
||||
# ARTIFACTS string[] - The files that this command produces, and uploads as an artifact in CI
|
||||
# ALWAYS_RUN bool - If true, the command will always run
|
||||
# TARGET string - The target to register the command with
|
||||
# TARGET_PHASE string - The target phase to register the command with (e.g. PRE_BUILD, PRE_LINK, POST_BUILD)
|
||||
# GROUP string - The group to register the command with (e.g. similar to JOB_POOL)
|
||||
function(register_command)
|
||||
set(options ALWAYS_RUN)
|
||||
set(args COMMENT CWD TARGET TARGET_PHASE GROUP)
|
||||
set(multiArgs COMMAND ENVIRONMENT TARGETS SOURCES OUTPUTS ARTIFACTS)
|
||||
cmake_parse_arguments(CMD "${options}" "${args}" "${multiArgs}" ${ARGN})
|
||||
cmake_parse_arguments(CMD "" "${args}" "${multiArgs}" ${ARGN})
|
||||
|
||||
if(NOT CMD_COMMAND)
|
||||
message(FATAL_ERROR "register_command: COMMAND is required")
|
||||
endif()
|
||||
parse_list(CMD_COMMAND CMD_COMMAND)
|
||||
|
||||
if(NOT CMD_CWD)
|
||||
set(CMD_CWD ${CWD})
|
||||
@@ -349,10 +348,6 @@ function(register_command)
|
||||
list(APPEND CMD_EFFECTIVE_DEPENDS ${source})
|
||||
endforeach()
|
||||
|
||||
if(NOT CMD_EFFECTIVE_DEPENDS AND NOT CMD_ALWAYS_RUN)
|
||||
message(FATAL_ERROR "register_command: TARGETS or SOURCES is required")
|
||||
endif()
|
||||
|
||||
set(CMD_EFFECTIVE_OUTPUTS)
|
||||
|
||||
foreach(output ${CMD_OUTPUTS})
|
||||
@@ -376,13 +371,14 @@ function(register_command)
|
||||
foreach(output ${CMD_EFFECTIVE_OUTPUTS})
|
||||
get_source_file_property(generated ${output} GENERATED)
|
||||
if(generated)
|
||||
list(REMOVE_ITEM CMD_EFFECTIVE_OUTPUTS ${output})
|
||||
list(APPEND CMD_EFFECTIVE_OUTPUTS ${output}.always_run)
|
||||
add_custom_target(${CMD_TARGET})
|
||||
message(WARNING "Skipping ${CMD_TARGET}, since ${output} is generated by another target")
|
||||
return()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(CMD_ALWAYS_RUN)
|
||||
list(APPEND CMD_EFFECTIVE_OUTPUTS ${CMD_CWD}/.always_run)
|
||||
if(NOT CMD_EFFECTIVE_OUTPUTS)
|
||||
list(APPEND CMD_EFFECTIVE_OUTPUTS ${CMD_CWD}/.always_run_${CMD_TARGET})
|
||||
endif()
|
||||
|
||||
if(CMD_TARGET_PHASE)
|
||||
@@ -403,10 +399,6 @@ function(register_command)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT CMD_EFFECTIVE_OUTPUTS)
|
||||
message(FATAL_ERROR "register_command: OUTPUTS or ARTIFACTS is required, or set ALWAYS_RUN")
|
||||
endif()
|
||||
|
||||
if(CMD_TARGET)
|
||||
if(TARGET ${CMD_TARGET})
|
||||
message(FATAL_ERROR "register_command: TARGET is already registered: ${CMD_TARGET}")
|
||||
@@ -419,6 +411,8 @@ function(register_command)
|
||||
if(TARGET clone-${CMD_TARGET})
|
||||
add_dependencies(${CMD_TARGET} clone-${CMD_TARGET})
|
||||
endif()
|
||||
set_property(TARGET ${CMD_TARGET} PROPERTY OUTPUT ${CMD_EFFECTIVE_OUTPUTS} APPEND)
|
||||
set_property(TARGET ${CMD_TARGET} PROPERTY DEPENDS ${CMD_EFFECTIVE_DEPENDS} APPEND)
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
@@ -575,14 +569,6 @@ function(register_repository)
|
||||
set(GIT_PATH ${VENDOR_PATH}/${GIT_NAME})
|
||||
endif()
|
||||
|
||||
if(GIT_COMMIT)
|
||||
set(GIT_REF ${GIT_COMMIT})
|
||||
elseif(GIT_TAG)
|
||||
set(GIT_REF refs/tags/${GIT_TAG})
|
||||
else()
|
||||
set(GIT_REF refs/heads/${GIT_BRANCH})
|
||||
endif()
|
||||
|
||||
set(GIT_EFFECTIVE_OUTPUTS)
|
||||
foreach(output ${GIT_OUTPUTS})
|
||||
list(APPEND GIT_EFFECTIVE_OUTPUTS ${GIT_PATH}/${output})
|
||||
@@ -597,296 +583,664 @@ function(register_repository)
|
||||
${CMAKE_COMMAND}
|
||||
-DGIT_PATH=${GIT_PATH}
|
||||
-DGIT_REPOSITORY=${GIT_REPOSITORY}
|
||||
-DGIT_REF=${GIT_REF}
|
||||
-DGIT_BRANCH=${GIT_BRANCH}
|
||||
-DGIT_TAG=${GIT_TAG}
|
||||
-DGIT_COMMIT=${GIT_COMMIT}
|
||||
-DGIT_NAME=${GIT_NAME}
|
||||
-P ${CWD}/cmake/scripts/GitClone.cmake
|
||||
OUTPUTS
|
||||
${GIT_PATH}
|
||||
${GIT_EFFECTIVE_OUTPUTS}
|
||||
)
|
||||
|
||||
register_outputs(TARGET clone-${GIT_NAME} ${GIT_PATH})
|
||||
endfunction()
|
||||
|
||||
# register_cmake_command()
|
||||
function(parse_language variable)
|
||||
if(NOT ${variable})
|
||||
set(${variable} C CXX PARENT_SCOPE)
|
||||
endif()
|
||||
foreach(value ${${variable}})
|
||||
if(NOT value MATCHES "^(C|CXX)$")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid language: \"${value}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(parse_target variable)
|
||||
foreach(value ${${variable}})
|
||||
if(NOT TARGET ${value})
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid target: \"${value}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(parse_path variable)
|
||||
foreach(value ${${variable}})
|
||||
if(NOT IS_ABSOLUTE ${value})
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: ${variable} is not an absolute path: \"${value}\"")
|
||||
endif()
|
||||
if(NOT ${value} MATCHES "^(${CWD}|${BUILD_PATH}|${CACHE_PATH}|${VENDOR_PATH})")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: ${variable} is not in the source, build, cache, or vendor path: \"${value}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(parse_list list variable)
|
||||
set(result)
|
||||
|
||||
macro(check_expression)
|
||||
if(DEFINED expression)
|
||||
if(NOT (${expression}))
|
||||
list(POP_BACK result)
|
||||
endif()
|
||||
unset(expression)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
foreach(item ${${list}})
|
||||
if(item MATCHES "^(ON|OFF|AND|OR|NOT)$")
|
||||
set(expression ${expression} ${item})
|
||||
else()
|
||||
check_expression()
|
||||
list(APPEND result ${item})
|
||||
endif()
|
||||
endforeach()
|
||||
check_expression()
|
||||
|
||||
set(${variable} ${result} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# register_target()
|
||||
# Description:
|
||||
# Registers a command that builds an external CMake project.
|
||||
# Registers a target that does nothing.
|
||||
# Arguments:
|
||||
# TARGET string - The target to register the command with
|
||||
# ARGS string[] - The arguments to pass to CMake (e.g. -DKEY=VALUE)
|
||||
# CWD string - The directory where the CMake files are located
|
||||
# BUILD_PATH string - The path to build the project to
|
||||
# LIB_PATH string - The path to the libraries
|
||||
# TARGETS string[] - The targets to build from CMake
|
||||
# LIBRARIES string[] - The libraries that are built
|
||||
# INCLUDES string[] - The include paths
|
||||
function(register_cmake_command)
|
||||
set(args TARGET CWD BUILD_PATH LIB_PATH)
|
||||
set(multiArgs ARGS TARGETS LIBRARIES INCLUDES)
|
||||
# Use "MAKE" instead of "CMAKE" to prevent conflicts with CMake's own CMAKE_* variables
|
||||
cmake_parse_arguments(MAKE "" "${args}" "${multiArgs}" ${ARGN})
|
||||
# target string - The name of the target
|
||||
function(register_target target)
|
||||
add_custom_target(${target})
|
||||
|
||||
if(NOT MAKE_TARGET)
|
||||
message(FATAL_ERROR "register_cmake_command: TARGET is required")
|
||||
endif()
|
||||
|
||||
if(TARGET ${MAKE_TARGET})
|
||||
message(FATAL_ERROR "register_cmake_command: TARGET is already a target: ${MAKE_TARGET}")
|
||||
endif()
|
||||
|
||||
if(NOT MAKE_CWD)
|
||||
set(MAKE_CWD ${VENDOR_PATH}/${MAKE_TARGET})
|
||||
endif()
|
||||
|
||||
if(NOT MAKE_BUILD_PATH)
|
||||
set(MAKE_BUILD_PATH ${BUILD_PATH}/${MAKE_TARGET})
|
||||
endif()
|
||||
|
||||
if(MAKE_LIB_PATH)
|
||||
set(MAKE_LIB_PATH ${MAKE_BUILD_PATH}/${MAKE_LIB_PATH})
|
||||
else()
|
||||
set(MAKE_LIB_PATH ${MAKE_BUILD_PATH})
|
||||
endif()
|
||||
|
||||
set(MAKE_EFFECTIVE_ARGS -B${MAKE_BUILD_PATH} ${CMAKE_ARGS})
|
||||
|
||||
set(setFlags GENERATOR BUILD_TYPE)
|
||||
set(appendFlags C_FLAGS CXX_FLAGS LINKER_FLAGS)
|
||||
set(specialFlags POSITION_INDEPENDENT_CODE)
|
||||
set(flags ${setFlags} ${appendFlags} ${specialFlags})
|
||||
|
||||
foreach(arg ${MAKE_ARGS})
|
||||
foreach(flag ${flags})
|
||||
if(arg MATCHES "-DCMAKE_${flag}=(.*)")
|
||||
if(DEFINED MAKE_${flag})
|
||||
message(FATAL_ERROR "register_cmake_command: CMAKE_${flag} was already set: \"${MAKE_${flag}}\"")
|
||||
endif()
|
||||
set(MAKE_${flag} ${CMAKE_MATCH_1})
|
||||
set(${arg}_USED ON)
|
||||
endif()
|
||||
endforeach()
|
||||
if(NOT ${arg}_USED)
|
||||
list(APPEND MAKE_EFFECTIVE_ARGS ${arg})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(flag ${setFlags})
|
||||
if(NOT DEFINED MAKE_${flag} AND DEFINED CMAKE_${flag})
|
||||
set(MAKE_${flag} ${CMAKE_${flag}})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(flag ${appendFlags})
|
||||
if(MAKE_${flag})
|
||||
set(MAKE_${flag} "${CMAKE_${flag}} ${MAKE_${flag}}")
|
||||
else()
|
||||
set(MAKE_${flag} ${CMAKE_${flag}})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(MAKE_POSITION_INDEPENDENT_CODE AND NOT WIN32)
|
||||
set(MAKE_C_FLAGS "${MAKE_C_FLAGS} -fPIC")
|
||||
set(MAKE_CXX_FLAGS "${MAKE_CXX_FLAGS} -fPIC")
|
||||
elseif(APPLE)
|
||||
set(MAKE_C_FLAGS "${MAKE_C_FLAGS} -fno-pic -fno-pie")
|
||||
set(MAKE_CXX_FLAGS "${MAKE_CXX_FLAGS} -fno-pic -fno-pie")
|
||||
endif()
|
||||
|
||||
set(effectiveFlags ${setFlags} ${appendFlags})
|
||||
foreach(flag ${effectiveFlags})
|
||||
list(APPEND MAKE_EFFECTIVE_ARGS "-DCMAKE_${flag}=${MAKE_${flag}}")
|
||||
endforeach()
|
||||
|
||||
if(DEFINED FRESH)
|
||||
list(APPEND MAKE_EFFECTIVE_ARGS --fresh)
|
||||
endif()
|
||||
|
||||
register_command(
|
||||
COMMENT "Configuring ${MAKE_TARGET}"
|
||||
TARGET configure-${MAKE_TARGET}
|
||||
COMMAND ${CMAKE_COMMAND} ${MAKE_EFFECTIVE_ARGS}
|
||||
CWD ${MAKE_CWD}
|
||||
OUTPUTS ${MAKE_BUILD_PATH}/CMakeCache.txt
|
||||
)
|
||||
|
||||
if(TARGET clone-${MAKE_TARGET})
|
||||
add_dependencies(configure-${MAKE_TARGET} clone-${MAKE_TARGET})
|
||||
endif()
|
||||
|
||||
set(MAKE_BUILD_ARGS --build ${MAKE_BUILD_PATH} --config ${MAKE_BUILD_TYPE})
|
||||
|
||||
set(MAKE_EFFECTIVE_LIBRARIES)
|
||||
set(MAKE_ARTIFACTS)
|
||||
foreach(lib ${MAKE_LIBRARIES})
|
||||
if(lib MATCHES "^(WIN32|UNIX|APPLE)$")
|
||||
if(${lib})
|
||||
continue()
|
||||
else()
|
||||
list(POP_BACK MAKE_ARTIFACTS)
|
||||
endif()
|
||||
else()
|
||||
list(APPEND MAKE_EFFECTIVE_LIBRARIES ${lib})
|
||||
if(lib MATCHES "\\.")
|
||||
list(APPEND MAKE_ARTIFACTS ${MAKE_LIB_PATH}/${lib})
|
||||
else()
|
||||
list(APPEND MAKE_ARTIFACTS ${MAKE_LIB_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}${lib}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT MAKE_TARGETS)
|
||||
set(MAKE_TARGETS ${MAKE_EFFECTIVE_LIBRARIES})
|
||||
endif()
|
||||
|
||||
foreach(target ${MAKE_TARGETS})
|
||||
list(APPEND MAKE_BUILD_ARGS --target ${target})
|
||||
endforeach()
|
||||
|
||||
set(MAKE_EFFECTIVE_INCLUDES)
|
||||
foreach(include ${MAKE_INCLUDES})
|
||||
if(include STREQUAL ".")
|
||||
list(APPEND MAKE_EFFECTIVE_INCLUDES ${MAKE_CWD})
|
||||
else()
|
||||
list(APPEND MAKE_EFFECTIVE_INCLUDES ${MAKE_CWD}/${include})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
register_command(
|
||||
COMMENT "Building ${MAKE_TARGET}"
|
||||
TARGET ${MAKE_TARGET}
|
||||
TARGETS configure-${MAKE_TARGET}
|
||||
COMMAND ${CMAKE_COMMAND} ${MAKE_BUILD_ARGS}
|
||||
CWD ${MAKE_CWD}
|
||||
ARTIFACTS ${MAKE_ARTIFACTS}
|
||||
)
|
||||
|
||||
if(MAKE_EFFECTIVE_INCLUDES)
|
||||
target_include_directories(${bun} PRIVATE ${MAKE_EFFECTIVE_INCLUDES})
|
||||
if(TARGET clone-${MAKE_TARGET} AND NOT BUN_LINK_ONLY)
|
||||
add_dependencies(${bun} clone-${MAKE_TARGET})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# HACK: Workaround for duplicate symbols when linking mimalloc.o
|
||||
# >| duplicate symbol '_mi_page_queue_append(mi_heap_s*, mi_page_queue_s*, mi_page_queue_s*)' in:
|
||||
# >| mimalloc/CMakeFiles/mimalloc-obj.dir/src/static.c.o
|
||||
# >| ld: 287 duplicate symbols for architecture arm64
|
||||
if(NOT BUN_LINK_ONLY OR NOT MAKE_ARTIFACTS MATCHES "static.c.o")
|
||||
target_link_libraries(${bun} PRIVATE ${MAKE_ARTIFACTS})
|
||||
endif()
|
||||
|
||||
if(BUN_LINK_ONLY)
|
||||
target_sources(${bun} PRIVATE ${MAKE_ARTIFACTS})
|
||||
endif()
|
||||
set(${target} ${target} PARENT_SCOPE)
|
||||
set(${target}_CWD ${CWD} PARENT_SCOPE)
|
||||
set(${target}_BUILD_PATH ${BUILD_PATH} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# register_compiler_flag()
|
||||
# register_vendor_target()
|
||||
# Description:
|
||||
# Registers a target that does nothing.
|
||||
# Arguments:
|
||||
# target string - The name of the target
|
||||
function(register_vendor_target target)
|
||||
add_custom_target(${target})
|
||||
|
||||
set(${target} ${target} PARENT_SCOPE)
|
||||
set(${target}_CWD ${VENDOR_PATH}/${target} PARENT_SCOPE)
|
||||
set(${target}_BUILD_PATH ${BUILD_PATH}/vendor/${target} PARENT_SCOPE)
|
||||
|
||||
if(NOT TARGET vendor)
|
||||
add_custom_target(vendor)
|
||||
endif()
|
||||
add_dependencies(vendor ${target})
|
||||
endfunction()
|
||||
|
||||
# register_outputs()
|
||||
# Description:
|
||||
# Registers outputs that are built from a target.
|
||||
# Arguments:
|
||||
# TARGET string - The target that builds the outputs
|
||||
# outputs string[] - The list of outputs
|
||||
function(register_outputs)
|
||||
set(args TARGET PATH)
|
||||
cmake_parse_arguments(OUTPUT "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(OUTPUT_TARGET)
|
||||
parse_list(OUTPUT_UNPARSED_ARGUMENTS OUTPUT_PATHS)
|
||||
parse_path(OUTPUT_PATHS)
|
||||
|
||||
foreach(path ${OUTPUT_PATHS})
|
||||
set_property(GLOBAL PROPERTY ${path} ${OUTPUT_TARGET} APPEND)
|
||||
set_property(TARGET ${OUTPUT_TARGET} PROPERTY OUTPUT ${path} APPEND)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# register_inputs()
|
||||
# Description:
|
||||
# Registers inputs that are required to build a target.
|
||||
# Arguments:
|
||||
# TARGET string - The target that builds the inputs
|
||||
# inputs string[] - The list of inputs
|
||||
function(register_inputs)
|
||||
set(args TARGET)
|
||||
cmake_parse_arguments(INPUT "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(INPUT_TARGET)
|
||||
parse_list(INPUT_UNPARSED_ARGUMENTS INPUT_PATHS)
|
||||
|
||||
foreach(path ${INPUT_PATHS})
|
||||
set(search ${path})
|
||||
set(found OFF)
|
||||
while(search)
|
||||
if(EXISTS ${search})
|
||||
set(found ON)
|
||||
break()
|
||||
endif()
|
||||
get_property(target GLOBAL PROPERTY ${search})
|
||||
if(TARGET ${target})
|
||||
set(found ON)
|
||||
set_property(TARGET ${target} PROPERTY OUTPUT ${path} APPEND)
|
||||
break()
|
||||
endif()
|
||||
get_filename_component(next_search ${search} DIRECTORY)
|
||||
if(next_search STREQUAL search OR next_search STREQUAL ${CWD} OR next_search STREQUAL ${VENDOR_PATH})
|
||||
break()
|
||||
endif()
|
||||
set(search ${next_search})
|
||||
endwhile()
|
||||
if(NOT found)
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: ${path} does not have a target")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# upload_artifacts()
|
||||
# Description:
|
||||
# Uploads artifacts after a target has been built.
|
||||
# Arguments:
|
||||
# TARGET string - The target to upload artifacts for
|
||||
# artifacts string[] - The artifacts to upload
|
||||
function(upload_artifacts)
|
||||
set(args TARGET)
|
||||
cmake_parse_arguments(ARTIFACT "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(ARTIFACT_TARGET)
|
||||
get_target_property(imported ${ARTIFACT_TARGET} IMPORTED)
|
||||
if(imported)
|
||||
return()
|
||||
endif()
|
||||
|
||||
parse_list(ARTIFACT_UNPARSED_ARGUMENTS ARTIFACT_PATHS)
|
||||
|
||||
foreach(artifact ${ARTIFACT_PATHS})
|
||||
file(RELATIVE_PATH filename ${BUILD_PATH} ${artifact})
|
||||
add_custom_command(
|
||||
TARGET ${ARTIFACT_TARGET} POST_BUILD
|
||||
COMMENT "Uploading ${filename}"
|
||||
COMMAND ${CMAKE_COMMAND} -E chdir ${BUILD_PATH} buildkite-agent artifact upload ${filename}
|
||||
)
|
||||
set_property(TARGET ${ARTIFACT_TARGET} PROPERTY OUTPUT ${artifact} APPEND)
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
# register_compiler_flags()
|
||||
# Description:
|
||||
# Registers a compiler flag, similar to `add_compile_options()`, but has more validation and features.
|
||||
# Arguments:
|
||||
# flags string[] - The flags to register
|
||||
# TARGET string - The target to register the flag (default: all)
|
||||
# LANGUAGE string - The language to register the flag (default: C, CXX)
|
||||
# DESCRIPTION string - The description of the flag
|
||||
# LANGUAGES string[] - The languages to register the flag (default: C, CXX)
|
||||
# TARGETS string[] - The targets to register the flag (default: all)
|
||||
# flags string[] - The flags to register
|
||||
function(register_compiler_flags)
|
||||
set(args DESCRIPTION)
|
||||
set(multiArgs LANGUAGES TARGETS)
|
||||
cmake_parse_arguments(COMPILER "" "${args}" "${multiArgs}" ${ARGN})
|
||||
set(args TARGET LANGUAGE DESCRIPTION)
|
||||
cmake_parse_arguments(COMPILER "" "${args}" "" ${ARGN})
|
||||
|
||||
if(NOT COMPILER_LANGUAGES)
|
||||
set(COMPILER_LANGUAGES C CXX)
|
||||
endif()
|
||||
parse_target(COMPILER_TARGET)
|
||||
parse_language(COMPILER_LANGUAGE)
|
||||
parse_list(COMPILER_UNPARSED_ARGUMENTS COMPILER_FLAGS)
|
||||
|
||||
set(COMPILER_FLAGS)
|
||||
foreach(flag ${COMPILER_UNPARSED_ARGUMENTS})
|
||||
if(flag STREQUAL "ON")
|
||||
continue()
|
||||
elseif(flag STREQUAL "OFF")
|
||||
list(POP_BACK COMPILER_FLAGS)
|
||||
elseif(flag MATCHES "^(-|/)")
|
||||
list(APPEND COMPILER_FLAGS ${flag})
|
||||
else()
|
||||
message(FATAL_ERROR "register_compiler_flags: Invalid flag: \"${flag}\"")
|
||||
foreach(flag ${COMPILER_FLAGS})
|
||||
if(NOT flag MATCHES "^(-|/)")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid flag: \"${flag}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(target ${COMPILER_TARGETS})
|
||||
if(NOT TARGET ${target})
|
||||
message(FATAL_ERROR "register_compiler_flags: \"${target}\" is not a target")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
foreach(lang ${COMPILER_LANGUAGES})
|
||||
foreach(language ${COMPILER_LANGUAGE})
|
||||
list(JOIN COMPILER_FLAGS " " COMPILER_FLAGS_STRING)
|
||||
|
||||
if(NOT COMPILER_TARGETS)
|
||||
set(CMAKE_${lang}_FLAGS "${CMAKE_${lang}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
if(NOT COMPILER_TARGET)
|
||||
set(CMAKE_${language}_FLAGS "${CMAKE_${language}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endif()
|
||||
|
||||
foreach(target ${COMPILER_TARGETS})
|
||||
set(${target}_CMAKE_${lang}_FLAGS "${${target}_CMAKE_${lang}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
foreach(target ${COMPILER_TARGET})
|
||||
set(${target}_CMAKE_${language}_FLAGS "${${target}_CMAKE_${language}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
foreach(lang ${COMPILER_LANGUAGES})
|
||||
foreach(language ${COMPILER_LANGUAGE})
|
||||
foreach(flag ${COMPILER_FLAGS})
|
||||
if(NOT COMPILER_TARGETS)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:${lang}>:${flag}>)
|
||||
if(NOT COMPILER_TARGET)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:${language}>:${flag}>)
|
||||
endif()
|
||||
|
||||
foreach(target ${COMPILER_TARGETS})
|
||||
foreach(target ${COMPILER_TARGET})
|
||||
get_target_property(type ${target} TYPE)
|
||||
if(type MATCHES "EXECUTABLE|LIBRARY")
|
||||
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:${lang}>:${flag}>)
|
||||
get_target_property(imported ${target} IMPORTED)
|
||||
if(type MATCHES "EXECUTABLE|LIBRARY" AND NOT imported)
|
||||
target_compile_options(${target} PRIVATE $<$<COMPILE_LANGUAGE:${language}>:${flag}>)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# register_compiler_definitions()
|
||||
# Description:
|
||||
# Registers a compiler definition, similar to `add_compile_definitions()`.
|
||||
# Arguments:
|
||||
# TARGET string - The target to register the definitions (default: all)
|
||||
# LANGUAGE string - The language to register the definitions (default: C, CXX)
|
||||
# DESCRIPTION string - The description of the definitions
|
||||
# definitions string[] - The definitions to register
|
||||
function(register_compiler_definitions)
|
||||
|
||||
set(args TARGET LANGUAGE DESCRIPTION)
|
||||
cmake_parse_arguments(COMPILER "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_language(COMPILER_LANGUAGE)
|
||||
parse_target(COMPILER_TARGET)
|
||||
parse_list(COMPILER_UNPARSED_ARGUMENTS COMPILER_DEFINITIONS)
|
||||
|
||||
foreach(definition ${COMPILER_DEFINITIONS})
|
||||
if(NOT definition MATCHES "^([A-Z_][A-Z0-9_]*)")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid definition: \"${definition}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(WIN32)
|
||||
list(TRANSFORM COMPILER_DEFINITIONS PREPEND "/D" OUTPUT_VARIABLE COMPILER_FLAGS)
|
||||
else()
|
||||
list(TRANSFORM COMPILER_DEFINITIONS PREPEND "-D" OUTPUT_VARIABLE COMPILER_FLAGS)
|
||||
endif()
|
||||
|
||||
foreach(language ${COMPILER_LANGUAGE})
|
||||
list(JOIN COMPILER_FLAGS " " COMPILER_FLAGS_STRING)
|
||||
if(NOT COMPILER_TARGET)
|
||||
set(CMAKE_${language}_FLAGS "${CMAKE_${language}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endif()
|
||||
foreach(target ${COMPILER_TARGET})
|
||||
set(${target}_CMAKE_${language}_FLAGS "${${target}_CMAKE_${language}_FLAGS} ${COMPILER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
foreach(definition ${COMPILER_DEFINITIONS})
|
||||
foreach(language ${COMPILER_LANGUAGE})
|
||||
if(NOT COMPILER_TARGET)
|
||||
add_compile_definitions($<$<COMPILE_LANGUAGE:${language}>:${definition}>)
|
||||
endif()
|
||||
foreach(target ${COMPILER_TARGET})
|
||||
get_target_property(type ${target} TYPE)
|
||||
get_target_property(imported ${target} IMPORTED)
|
||||
if(type MATCHES "EXECUTABLE|LIBRARY" AND NOT imported)
|
||||
target_compile_definitions(${target} PRIVATE $<$<COMPILE_LANGUAGE:${language}>:${definition}>)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# register_linker_flags()
|
||||
# Description:
|
||||
# Registers a linker flag, similar to `add_link_options()`.
|
||||
# Arguments:
|
||||
# flags string[] - The flags to register
|
||||
# TARGET string - The target to register the flag (default: all)
|
||||
# DESCRIPTION string - The description of the flag
|
||||
# flags string[] - The flags to register
|
||||
function(register_linker_flags)
|
||||
set(args DESCRIPTION)
|
||||
set(args TARGET DESCRIPTION)
|
||||
cmake_parse_arguments(LINKER "" "${args}" "" ${ARGN})
|
||||
|
||||
foreach(flag ${LINKER_UNPARSED_ARGUMENTS})
|
||||
if(flag STREQUAL "ON")
|
||||
continue()
|
||||
elseif(flag STREQUAL "OFF")
|
||||
list(POP_FRONT LINKER_FLAGS)
|
||||
elseif(flag MATCHES "^(-|/)")
|
||||
list(APPEND LINKER_FLAGS ${flag})
|
||||
else()
|
||||
message(FATAL_ERROR "register_linker_flags: Invalid flag: \"${flag}\"")
|
||||
parse_target(LINKER_TARGET)
|
||||
parse_list(LINKER_UNPARSED_ARGUMENTS LINKER_FLAGS)
|
||||
|
||||
foreach(flag ${LINKER_FLAGS})
|
||||
if(NOT flag MATCHES "^(-|/)")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid flag: \"${flag}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
add_link_options(${LINKER_FLAGS})
|
||||
list(JOIN LINKER_FLAGS " " LINKER_FLAGS_STRING)
|
||||
if(NOT LINKER_TARGET)
|
||||
set(CMAKE_LINKER_FLAGS "${CMAKE_LINKER_FLAGS} ${LINKER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endif()
|
||||
foreach(target ${LINKER_TARGET})
|
||||
set(${target}_CMAKE_LINKER_FLAGS "${${target}_CMAKE_LINKER_FLAGS} ${LINKER_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
|
||||
if(NOT LINKER_TARGET)
|
||||
add_link_options(${LINKER_FLAGS})
|
||||
endif()
|
||||
foreach(target ${LINKER_TARGET})
|
||||
get_target_property(type ${target} TYPE)
|
||||
if(type MATCHES "EXECUTABLE|LIBRARY")
|
||||
target_link_options(${target} PUBLIC ${LINKER_FLAGS})
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(print_compiler_flags)
|
||||
get_property(targets DIRECTORY PROPERTY BUILDSYSTEM_TARGETS)
|
||||
set(languages C CXX)
|
||||
foreach(target ${targets})
|
||||
get_target_property(type ${target} TYPE)
|
||||
message(STATUS "Target: ${target}")
|
||||
foreach(lang ${languages})
|
||||
if(${target}_CMAKE_${lang}_FLAGS)
|
||||
message(STATUS " ${lang} Flags: ${${target}_CMAKE_${lang}_FLAGS}")
|
||||
# register_includes()
|
||||
# Description:
|
||||
# Registers a include directory, similar to `target_include_directories()`.
|
||||
# Arguments:
|
||||
# TARGET string - The target to register the include (default: all)
|
||||
# LANGUAGE string - The language to register the include (default: C, CXX)
|
||||
# DESCRIPTION string - The description of the include
|
||||
# paths string[] - The include paths to register
|
||||
function(register_includes)
|
||||
set(args TARGET LANGUAGE DESCRIPTION)
|
||||
cmake_parse_arguments(INCLUDE "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(INCLUDE_TARGET)
|
||||
parse_language(INCLUDE_LANGUAGE)
|
||||
parse_list(INCLUDE_UNPARSED_ARGUMENTS INCLUDE_PATHS)
|
||||
parse_path(INCLUDE_PATHS)
|
||||
|
||||
register_inputs(TARGET ${INCLUDE_TARGET} ${INCLUDE_PATHS})
|
||||
|
||||
list(TRANSFORM INCLUDE_PATHS PREPEND "-I" OUTPUT_VARIABLE INCLUDE_FLAGS)
|
||||
list(JOIN INCLUDE_FLAGS " " INCLUDE_FLAGS_STRING)
|
||||
|
||||
foreach(language ${INCLUDE_LANGUAGE})
|
||||
if(NOT INCLUDE_TARGET)
|
||||
set(CMAKE_${language}_FLAGS "${CMAKE_${language}_FLAGS} ${INCLUDE_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endif()
|
||||
foreach(target ${INCLUDE_TARGET})
|
||||
set(${target}_CMAKE_${language}_FLAGS "${${target}_CMAKE_${language}_FLAGS} ${INCLUDE_FLAGS_STRING}" PARENT_SCOPE)
|
||||
endforeach()
|
||||
|
||||
if(NOT INCLUDE_TARGET)
|
||||
add_include_directories(${INCLUDE_PATHS})
|
||||
endif()
|
||||
foreach(target ${INCLUDE_TARGET})
|
||||
get_target_property(type ${target} TYPE)
|
||||
get_target_property(imported ${target} IMPORTED)
|
||||
if(type MATCHES "EXECUTABLE|LIBRARY" AND NOT imported)
|
||||
target_include_directories(${target} PUBLIC ${INCLUDE_PATHS})
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
foreach(lang ${languages})
|
||||
message(STATUS "Language: ${lang}")
|
||||
if(CMAKE_${lang}_FLAGS)
|
||||
message(STATUS " Flags: ${CMAKE_${lang}_FLAGS}")
|
||||
endfunction()
|
||||
|
||||
# register_libraries()
|
||||
# Description:
|
||||
# Registers libraries that are built from a target.
|
||||
# Arguments:
|
||||
# TARGET string - The target that builds the libraries
|
||||
# PATH string - The relative path to the libraries
|
||||
# VARIABLE string - The variable to set to the libraries
|
||||
# libraries string[] - The libraries to register
|
||||
function(register_libraries)
|
||||
set(args TARGET PATH VARIABLE)
|
||||
cmake_parse_arguments(LIBRARY "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(LIBRARY_TARGET)
|
||||
parse_list(LIBRARY_UNPARSED_ARGUMENTS LIBRARY_NAMES)
|
||||
|
||||
if(LIBRARY_PATH)
|
||||
if(NOT IS_ABSOLUTE ${LIBRARY_PATH})
|
||||
set(LIBRARY_PATH ${${LIBRARY_TARGET}_BUILD_PATH}/${LIBRARY_PATH})
|
||||
endif()
|
||||
else()
|
||||
set(LIBRARY_PATH ${${LIBRARY_TARGET}_BUILD_PATH})
|
||||
endif()
|
||||
parse_path(LIBRARY_PATH)
|
||||
|
||||
set(LIBRARY_PATHS)
|
||||
foreach(name ${LIBRARY_NAMES})
|
||||
if(name MATCHES "\\.")
|
||||
list(APPEND LIBRARY_PATHS ${LIBRARY_PATH}/${name})
|
||||
else()
|
||||
list(APPEND LIBRARY_PATHS ${LIBRARY_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}${name}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set_property(TARGET ${LIBRARY_TARGET} PROPERTY OUTPUT ${LIBRARY_PATHS} APPEND)
|
||||
|
||||
if(LIBRARY_VARIABLE)
|
||||
set(${LIBRARY_VARIABLE} ${LIBRARY_PATHS} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(get_libraries target variable)
|
||||
get_target_property(libraries ${target} OUTPUT)
|
||||
if(libraries MATCHES "NOTFOUND")
|
||||
set(libraries)
|
||||
endif()
|
||||
set(${variable} ${libraries} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# register_cmake_project()
|
||||
# Description:
|
||||
# Registers an external CMake project.
|
||||
# Arguments:
|
||||
# TARGET string - The target to associate the project
|
||||
# CWD string - The working directory of the project
|
||||
# CMAKE_TARGET string[] - The CMake targets to build
|
||||
# CMAKE_PATH string - The path to the CMake project (default: CWD)
|
||||
function(register_cmake_project)
|
||||
set(args TARGET CWD CMAKE_PATH LIBRARY_PATH)
|
||||
set(multiArgs CMAKE_TARGET)
|
||||
cmake_parse_arguments(PROJECT "" "${args}" "${multiArgs}" ${ARGN})
|
||||
|
||||
parse_target(PROJECT_TARGET)
|
||||
|
||||
if(NOT PROJECT_CWD)
|
||||
set(PROJECT_CWD ${VENDOR_PATH}/${PROJECT_TARGET})
|
||||
endif()
|
||||
parse_path(PROJECT_CWD)
|
||||
|
||||
if(PROJECT_CMAKE_PATH)
|
||||
set(PROJECT_CMAKE_PATH ${PROJECT_CWD}/${PROJECT_CMAKE_PATH})
|
||||
else()
|
||||
set(PROJECT_CMAKE_PATH ${PROJECT_CWD})
|
||||
endif()
|
||||
parse_path(PROJECT_CMAKE_PATH)
|
||||
|
||||
set(PROJECT_BUILD_PATH ${BUILD_PATH}/vendor/${PROJECT_TARGET})
|
||||
set(PROJECT_TOOLCHAIN_PATH ${PROJECT_BUILD_PATH}/CMakeLists-toolchain.txt)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
configure-${PROJECT_TARGET}
|
||||
COMMENT
|
||||
"Configuring ${PROJECT_TARGET}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-G ${CMAKE_GENERATOR}
|
||||
-B ${PROJECT_BUILD_PATH}
|
||||
-S ${PROJECT_CMAKE_PATH}
|
||||
--toolchain ${PROJECT_TOOLCHAIN_PATH}
|
||||
--fresh
|
||||
-DCMAKE_POLICY_DEFAULT_CMP0077=NEW
|
||||
CWD
|
||||
${PROJECT_CWD}
|
||||
SOURCES
|
||||
${PROJECT_TOOLCHAIN_PATH}
|
||||
OUTPUTS
|
||||
${PROJECT_BUILD_PATH}/CMakeCache.txt
|
||||
)
|
||||
|
||||
if(TARGET clone-${PROJECT_TARGET})
|
||||
add_dependencies(configure-${PROJECT_TARGET} clone-${PROJECT_TARGET})
|
||||
endif()
|
||||
|
||||
set(PROJECT_BUILD_ARGS --build ${PROJECT_BUILD_PATH})
|
||||
|
||||
parse_list(PROJECT_CMAKE_TARGET PROJECT_CMAKE_TARGET)
|
||||
foreach(target ${PROJECT_CMAKE_TARGET})
|
||||
list(APPEND PROJECT_BUILD_ARGS --target ${target})
|
||||
endforeach()
|
||||
|
||||
if(NOT BUN_LINK_ONLY)
|
||||
get_libraries(${PROJECT_TARGET} PROJECT_OUTPUTS)
|
||||
endif()
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
build-${PROJECT_TARGET}
|
||||
COMMENT
|
||||
"Building ${PROJECT_TARGET}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
${PROJECT_BUILD_ARGS}
|
||||
CWD
|
||||
${PROJECT_CWD}
|
||||
TARGETS
|
||||
configure-${PROJECT_TARGET}
|
||||
ARTIFACTS
|
||||
${PROJECT_OUTPUTS}
|
||||
)
|
||||
|
||||
add_dependencies(${PROJECT_TARGET} build-${PROJECT_TARGET})
|
||||
|
||||
cmake_language(EVAL CODE "cmake_language(DEFER CALL create_toolchain_file ${PROJECT_TOOLCHAIN_PATH} ${PROJECT_TARGET})")
|
||||
endfunction()
|
||||
|
||||
# register_cmake_definitions()
|
||||
# Description:
|
||||
# Registers definitions, when compiling an external CMake project.
|
||||
# Arguments:
|
||||
# TARGET string - The target to register the definitions (if not defined, sets for all targets)
|
||||
# DESCRIPTION string - The description of the definitions
|
||||
# definitions string[] - The definitions to register
|
||||
function(register_cmake_definitions)
|
||||
set(args TARGET DESCRIPTION)
|
||||
cmake_parse_arguments(CMAKE "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(CMAKE_TARGET)
|
||||
parse_list(CMAKE_UNPARSED_ARGUMENTS CMAKE_EXTRA_DEFINITIONS)
|
||||
|
||||
foreach(definition ${CMAKE_EXTRA_DEFINITIONS})
|
||||
string(REGEX MATCH "^([^=]+)=(.*)$" match ${definition})
|
||||
if(NOT match)
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Invalid definition: \"${definition}\"")
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(CMAKE_TARGET)
|
||||
set(${CMAKE_TARGET}_CMAKE_DEFINITIONS ${${CMAKE_TARGET}_CMAKE_DEFINITIONS} ${CMAKE_EXTRA_DEFINITIONS} PARENT_SCOPE)
|
||||
else()
|
||||
set(CMAKE_DEFINITIONS ${CMAKE_DEFINITIONS} ${CMAKE_EXTRA_DEFINITIONS} PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
# register_link_targets()
|
||||
# Description:
|
||||
# Links the libraries of one target to another.
|
||||
# Arguments:
|
||||
# TARGET string - The main target
|
||||
# targets string[] - The targets to link to the main target
|
||||
function(register_link_targets)
|
||||
set(args TARGET)
|
||||
cmake_parse_arguments(LINK "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(LINK_TARGET)
|
||||
get_target_property(type ${LINK_TARGET} TYPE)
|
||||
if(NOT type MATCHES "EXECUTABLE|LIBRARY")
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Target is not an executable or library: ${LINK_TARGET}")
|
||||
endif()
|
||||
|
||||
parse_list(LINK_UNPARSED_ARGUMENTS LINK_TARGETS)
|
||||
parse_target(LINK_TARGETS)
|
||||
|
||||
foreach(target ${LINK_TARGETS})
|
||||
get_target_property(libraries ${target} OUTPUT)
|
||||
if(NOT libraries)
|
||||
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION}: Target does not have libraries: ${target}")
|
||||
endif()
|
||||
register_link_libraries(TARGET ${LINK_TARGET} ${libraries})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
function(register_link_libraries)
|
||||
set(args TARGET)
|
||||
cmake_parse_arguments(LINK "" "${args}" "" ${ARGN})
|
||||
|
||||
parse_target(LINK_TARGET)
|
||||
parse_list(LINK_UNPARSED_ARGUMENTS LINK_TARGETS)
|
||||
|
||||
foreach(target ${LINK_TARGETS})
|
||||
target_link_libraries(${LINK_TARGET} PUBLIC ${target})
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
# create_toolchain_file()
|
||||
# Description:
|
||||
# Creates a CMake toolchain file.
|
||||
# Arguments:
|
||||
# filename string - The path to create the toolchain file
|
||||
# target string - The target to create the toolchain file
|
||||
function(create_toolchain_file filename target)
|
||||
parse_path(filename)
|
||||
parse_target(target)
|
||||
|
||||
set(lines)
|
||||
|
||||
if(CMAKE_TOOLCHAIN_FILE)
|
||||
file(STRINGS ${CMAKE_TOOLCHAIN_FILE} lines)
|
||||
list(PREPEND lines "# Copied from ${CMAKE_TOOLCHAIN_FILE}")
|
||||
endif()
|
||||
|
||||
list(APPEND lines "# Generated from ${CMAKE_CURRENT_FUNCTION} in ${CMAKE_CURRENT_LIST_FILE}")
|
||||
|
||||
set(variables
|
||||
CMAKE_BUILD_TYPE
|
||||
CMAKE_EXPORT_COMPILE_COMMANDS
|
||||
CMAKE_COLOR_DIAGNOSTICS
|
||||
CMAKE_C_COMPILER
|
||||
CMAKE_C_COMPILER_LAUNCHER
|
||||
CMAKE_CXX_COMPILER
|
||||
CMAKE_CXX_COMPILER_LAUNCHER
|
||||
CMAKE_LINKER
|
||||
CMAKE_AR
|
||||
CMAKE_RANLIB
|
||||
CMAKE_STRIP
|
||||
CMAKE_OSX_SYSROOT
|
||||
CMAKE_OSX_DEPLOYMENT_TARGET
|
||||
)
|
||||
|
||||
macro(append variable value)
|
||||
if(value MATCHES " ")
|
||||
list(APPEND lines "set(${variable} \"${value}\")")
|
||||
else()
|
||||
list(APPEND lines "set(${variable} ${value})")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
foreach(variable ${variables})
|
||||
if(DEFINED ${variable})
|
||||
append(${variable} ${${variable}})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(flags
|
||||
CMAKE_C_FLAGS
|
||||
CMAKE_CXX_FLAGS
|
||||
CMAKE_LINKER_FLAGS
|
||||
)
|
||||
|
||||
foreach(flag ${flags})
|
||||
set(value)
|
||||
if(DEFINED ${flag})
|
||||
set(value "${${flag}}")
|
||||
endif()
|
||||
if(DEFINED ${target}_${flag})
|
||||
set(value "${value} ${${target}_${flag}}")
|
||||
endif()
|
||||
if(value)
|
||||
append(${flag} ${value})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
set(definitions
|
||||
CMAKE_DEFINITIONS
|
||||
${target}_CMAKE_DEFINITIONS
|
||||
)
|
||||
|
||||
foreach(definition ${definitions})
|
||||
foreach(entry ${${definition}})
|
||||
string(REGEX MATCH "^([^=]+)=(.*)$" match ${entry})
|
||||
if(NOT match)
|
||||
message(FATAL_ERROR "Invalid definition: ${entry}")
|
||||
endif()
|
||||
append(${CMAKE_MATCH_1} ${CMAKE_MATCH_2})
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
list(JOIN lines "\n" lines)
|
||||
file(GENERATE OUTPUT ${filename} CONTENT "${lines}\n")
|
||||
endfunction()
|
||||
|
||||
@@ -2,8 +2,8 @@ if(NOT CMAKE_SYSTEM_NAME OR NOT CMAKE_SYSTEM_PROCESSOR)
|
||||
message(FATAL_ERROR "CMake included this file before project() was called")
|
||||
endif()
|
||||
|
||||
optionx(BUN_LINK_ONLY BOOL "If only the linking step should be built" DEFAULT OFF)
|
||||
optionx(BUN_CPP_ONLY BOOL "If only the C++ part of Bun should be built" DEFAULT OFF)
|
||||
optionx(BUN_CPP_ONLY BOOL "If only the C++ library should be built" DEFAULT OFF)
|
||||
optionx(BUN_LINK_ONLY BOOL "If only the executable should be linked" DEFAULT OFF)
|
||||
|
||||
optionx(BUILDKITE BOOL "If Buildkite is enabled" DEFAULT OFF)
|
||||
optionx(GITHUB_ACTIONS BOOL "If GitHub Actions is enabled" DEFAULT OFF)
|
||||
@@ -143,15 +143,4 @@ endif()
|
||||
|
||||
optionx(USE_STATIC_LIBATOMIC BOOL "If libatomic should be statically linked" DEFAULT ${DEFAULT_STATIC_LIBATOMIC})
|
||||
|
||||
if(APPLE)
|
||||
set(DEFAULT_WEBKIT_ICU OFF)
|
||||
else()
|
||||
set(DEFAULT_WEBKIT_ICU ON)
|
||||
endif()
|
||||
|
||||
optionx(USE_WEBKIT_ICU BOOL "Use the ICU libraries from WebKit" DEFAULT ${DEFAULT_WEBKIT_ICU})
|
||||
|
||||
optionx(ERROR_LIMIT STRING "Maximum number of errors to show when compiling C++ code" DEFAULT "100")
|
||||
|
||||
list(APPEND CMAKE_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)
|
||||
|
||||
|
||||
35
cmake/analysis/RunClangFormat.cmake
Normal file
35
cmake/analysis/RunClangFormat.cmake
Normal file
@@ -0,0 +1,35 @@
|
||||
find_command(
|
||||
VARIABLE
|
||||
CLANG_FORMAT_PROGRAM
|
||||
COMMAND
|
||||
clang-format
|
||||
REQUIRED
|
||||
OFF
|
||||
)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
clang-format-check
|
||||
COMMENT
|
||||
"Running clang-format"
|
||||
COMMAND
|
||||
${CLANG_FORMAT_PROGRAM}
|
||||
-Werror
|
||||
--dry-run
|
||||
--verbose
|
||||
${BUN_C_SOURCES}
|
||||
${BUN_CXX_SOURCES}
|
||||
)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
clang-format
|
||||
COMMENT
|
||||
"Fixing clang-format"
|
||||
COMMAND
|
||||
${CLANG_FORMAT_PROGRAM}
|
||||
-i # edits files in-place
|
||||
--verbose
|
||||
${BUN_C_SOURCES}
|
||||
${BUN_CXX_SOURCES}
|
||||
)
|
||||
@@ -11,23 +11,61 @@ find_command(
|
||||
OFF
|
||||
)
|
||||
|
||||
set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM} ${BUN_CPP_SOURCES}
|
||||
-p ${BUILD_PATH}
|
||||
--config-file=${CWD}/.clang-tidy
|
||||
--fix
|
||||
--fix-errors
|
||||
--fix-notes
|
||||
set(CLANG_TIDY_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})
|
||||
|
||||
find_command(
|
||||
VARIABLE
|
||||
GIT_PROGRAM
|
||||
COMMAND
|
||||
git
|
||||
REQUIRED
|
||||
OFF
|
||||
)
|
||||
|
||||
if(CMAKE_COLOR_DIAGNOSTICS)
|
||||
list(APPEND CLANG_TIDY_COMMAND --use-color)
|
||||
if(GIT_PROGRAM)
|
||||
execute_process(
|
||||
COMMAND
|
||||
${GIT_PROGRAM}
|
||||
diff
|
||||
--name-only
|
||||
--diff-filter=AM
|
||||
main
|
||||
WORKING_DIRECTORY
|
||||
${CWD}
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
OUTPUT_VARIABLE
|
||||
GIT_CHANGED_FILES
|
||||
ERROR_QUIET
|
||||
)
|
||||
string(REPLACE "\n" ";" GIT_CHANGED_FILES ${GIT_CHANGED_FILES})
|
||||
list(TRANSFORM GIT_CHANGED_FILES PREPEND ${CWD}/)
|
||||
|
||||
set(CLANG_TIDY_CHANGED_SOURCES)
|
||||
foreach(source ${CLANG_TIDY_SOURCES})
|
||||
list(FIND GIT_CHANGED_FILES ${source} index)
|
||||
if(NOT ${index} EQUAL -1)
|
||||
list(APPEND CLANG_TIDY_CHANGED_SOURCES ${source})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(CLANG_TIDY_CHANGED_SOURCES)
|
||||
set(CLANG_TIDY_SOURCES ${CLANG_TIDY_CHANGED_SOURCES})
|
||||
else()
|
||||
set(CLANG_TIDY_COMMAND ${CMAKE_COMMAND} -E echo "No files changed for clang-tidy")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Extra clang-tidy checks that are normally disabled due to noise.
|
||||
# e.g. JavaScriptCore/Lookup.h
|
||||
set(CLANG_TIDY_EXTRA_COMMAND ${CLANG_TIDY_PROGRAM}
|
||||
--checks=performance-*
|
||||
)
|
||||
if(NOT CLANG_TIDY_COMMAND)
|
||||
set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM}
|
||||
-p ${BUILD_PATH}
|
||||
--config-file=${CWD}/.clang-tidy
|
||||
--fix
|
||||
--fix-errors
|
||||
--fix-notes
|
||||
--use-color
|
||||
${CLANG_TIDY_SOURCES}
|
||||
)
|
||||
endif()
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
@@ -38,19 +76,4 @@ register_command(
|
||||
${CLANG_TIDY_COMMAND}
|
||||
CWD
|
||||
${BUILD_PATH}
|
||||
TARGETS
|
||||
${bun}
|
||||
)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
clang-tidy-extra
|
||||
COMMENT
|
||||
"Running clang-tidy with extra checks"
|
||||
COMMAND
|
||||
${CLANG_TIDY_EXTRA_COMMAND}
|
||||
CWD
|
||||
${BUILD_PATH}
|
||||
TARGETS
|
||||
${bun}
|
||||
)
|
||||
|
||||
22
cmake/analysis/RunZigFormat.cmake
Normal file
22
cmake/analysis/RunZigFormat.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
register_command(
|
||||
TARGET
|
||||
zig-format-check
|
||||
COMMENT
|
||||
"Checking zig fmt"
|
||||
COMMAND
|
||||
${ZIG_EXECUTABLE}
|
||||
fmt
|
||||
--check
|
||||
${BUN_ZIG_SOURCES}
|
||||
)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
zig-format
|
||||
COMMENT
|
||||
"Running zig fmt"
|
||||
COMMAND
|
||||
${ZIG_EXECUTABLE}
|
||||
fmt
|
||||
${BUN_ZIG_SOURCES}
|
||||
)
|
||||
131
cmake/scripts/DownloadUrl.cmake
Normal file
131
cmake/scripts/DownloadUrl.cmake
Normal file
@@ -0,0 +1,131 @@
|
||||
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
|
||||
message(STATUS "Running script: ${SCRIPT_NAME}")
|
||||
|
||||
if(NOT DOWNLOAD_URL OR NOT DOWNLOAD_PATH)
|
||||
message(FATAL_ERROR "DOWNLOAD_URL and DOWNLOAD_PATH are required")
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
set(TMP_PATH $ENV{TEMP})
|
||||
else()
|
||||
set(TMP_PATH $ENV{TMPDIR})
|
||||
endif()
|
||||
|
||||
if(NOT TMP_PATH)
|
||||
set(TMP_PATH ${CMAKE_BINARY_DIR}/tmp)
|
||||
endif()
|
||||
|
||||
string(REGEX REPLACE "/+$" "" TMP_PATH ${TMP_PATH})
|
||||
string(REGEX REPLACE "[^a-zA-Z0-9]" "-" DOWNLOAD_ID ${DOWNLOAD_URL})
|
||||
string(RANDOM LENGTH 8 RANDOM_ID)
|
||||
|
||||
set(DOWNLOAD_TMP_PATH ${TMP_PATH}/${DOWNLOAD_ID}-${RANDOM_ID})
|
||||
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_PATH}/tmp)
|
||||
|
||||
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
|
||||
|
||||
if(DOWNLOAD_ACCEPT_HEADER)
|
||||
set(DOWNLOAD_ACCEPT_HEADER "Accept: ${DOWNLOAD_ACCEPT_HEADER}")
|
||||
else()
|
||||
set(DOWNLOAD_ACCEPT_HEADER "Accept: */*")
|
||||
endif()
|
||||
|
||||
foreach(i RANGE 10)
|
||||
set(DOWNLOAD_TMP_FILE_${i} ${DOWNLOAD_TMP_FILE}.${i})
|
||||
|
||||
if(i EQUAL 0)
|
||||
message(STATUS "Downloading ${DOWNLOAD_URL}...")
|
||||
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
|
||||
)
|
||||
|
||||
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}}")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
file(RENAME ${DOWNLOAD_TMP_FILE_${i}} ${DOWNLOAD_TMP_FILE})
|
||||
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()
|
||||
|
||||
if(NOT EXISTS ${DOWNLOAD_TMP_FILE})
|
||||
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
|
||||
message(FATAL_ERROR "Download failed after too many attempts: ${DOWNLOAD_URL}")
|
||||
endif()
|
||||
|
||||
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_URL} NAME)
|
||||
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(REMOVE ${DOWNLOAD_TMP_FILE})
|
||||
|
||||
if(DOWNLOAD_FILTERS)
|
||||
list(TRANSFORM DOWNLOAD_FILTERS PREPEND ${DOWNLOAD_TMP_EXTRACT}/ OUTPUT_VARIABLE DOWNLOAD_GLOBS)
|
||||
else()
|
||||
set(DOWNLOAD_GLOBS ${DOWNLOAD_TMP_EXTRACT}/*)
|
||||
endif()
|
||||
|
||||
file(GLOB DOWNLOAD_TMP_EXTRACT_PATHS LIST_DIRECTORIES ON ${DOWNLOAD_GLOBS})
|
||||
list(LENGTH DOWNLOAD_TMP_EXTRACT_PATHS DOWNLOAD_COUNT)
|
||||
|
||||
if(DOWNLOAD_COUNT EQUAL 0)
|
||||
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
|
||||
|
||||
if(DOWNLOAD_FILTERS)
|
||||
message(FATAL_ERROR "Extract failed: No files found matching ${DOWNLOAD_FILTERS}")
|
||||
else()
|
||||
message(FATAL_ERROR "Extract failed: No files found")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DOWNLOAD_FILTERS)
|
||||
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_EXTRACT_PATHS})
|
||||
elseif(DOWNLOAD_COUNT EQUAL 1)
|
||||
list(GET DOWNLOAD_TMP_EXTRACT_PATHS 0 DOWNLOAD_TMP_FILE)
|
||||
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_TMP_FILE} NAME)
|
||||
message(STATUS "Hoisting ${DOWNLOAD_FILENAME}...")
|
||||
else()
|
||||
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_EXTRACT})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(DOWNLOAD_FILTERS)
|
||||
foreach(file ${DOWNLOAD_TMP_FILE})
|
||||
file(RENAME ${file} ${DOWNLOAD_PATH})
|
||||
endforeach()
|
||||
else()
|
||||
file(REMOVE_RECURSE ${DOWNLOAD_PATH})
|
||||
get_filename_component(DOWNLOAD_PARENT_PATH ${DOWNLOAD_PATH} DIRECTORY)
|
||||
file(MAKE_DIRECTORY ${DOWNLOAD_PARENT_PATH})
|
||||
file(RENAME ${DOWNLOAD_TMP_FILE} ${DOWNLOAD_PATH})
|
||||
endif()
|
||||
|
||||
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_PATH} NAME)
|
||||
message(STATUS "Saved ${DOWNLOAD_FILENAME}")
|
||||
|
||||
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
|
||||
111
cmake/scripts/DownloadZig.cmake
Normal file
111
cmake/scripts/DownloadZig.cmake
Normal file
@@ -0,0 +1,111 @@
|
||||
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
|
||||
message(STATUS "Running script: ${SCRIPT_NAME}")
|
||||
|
||||
if(NOT ZIG_PATH)
|
||||
message(FATAL_ERROR "ZIG_PATH is required")
|
||||
endif()
|
||||
|
||||
if(ZIG_REPOSITORY)
|
||||
if(NOT ZIG_COMMIT)
|
||||
message(FATAL_ERROR "ZIG_COMMIT is required when ZIG_REPOSITORY is set")
|
||||
endif()
|
||||
elseif(NOT ZIG_COMMIT)
|
||||
set(ZIG_REPOSITORY "oven-sh/zig")
|
||||
set(ZIG_COMMIT "131a009ba2eb127a3447d05b9e12f710429aa5ee")
|
||||
endif()
|
||||
|
||||
if(NOT ZIG_VERSION)
|
||||
set(ZIG_VERSION "0.13.0")
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_APPLE)
|
||||
set(ZIG_OS "macos")
|
||||
elseif(CMAKE_HOST_WIN32)
|
||||
set(ZIG_OS "windows")
|
||||
elseif(CMAKE_HOST_UNIX)
|
||||
set(ZIG_OS "linux")
|
||||
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 zig-${ZIG_OS}-${ZIG_ARCH}-${ZIG_VERSION})
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(ZIG_EXE "zig.exe")
|
||||
set(ZIG_FILENAME ${ZIG_NAME}.zip)
|
||||
else()
|
||||
set(ZIG_EXE "zig")
|
||||
set(ZIG_FILENAME ${ZIG_NAME}.tar.xz)
|
||||
endif()
|
||||
|
||||
message(STATUS "Downloading ${ZIG_EXE} ${ZIG_VERSION} on ${ZIG_OS} ${ZIG_ARCH}...")
|
||||
set(ZIG_DOWNLOAD_URL https://ziglang.org/download/${ZIG_VERSION}/${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 "Download failed: 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 `bun.exe` symlink on Unix.
|
||||
if(NOT WIN32)
|
||||
file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC)
|
||||
endif()
|
||||
|
||||
if(ZIG_REPOSITORY AND ZIG_COMMIT)
|
||||
message(STATUS "Downloading zig library from ${ZIG_REPOSITORY} at ${ZIG_COMMIT}...")
|
||||
|
||||
execute_process(
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DGIT_PATH=${ZIG_PATH}/tmp
|
||||
-DGIT_REPOSITORY=${ZIG_REPOSITORY}
|
||||
-DGIT_COMMIT=${ZIG_COMMIT}
|
||||
-P ${CMAKE_CURRENT_LIST_DIR}/GitClone.cmake
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_VARIABLE
|
||||
ZIG_REPOSITORY_ERROR
|
||||
RESULT_VARIABLE
|
||||
ZIG_REPOSITORY_RESULT
|
||||
)
|
||||
|
||||
if(NOT ZIG_REPOSITORY_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "Download failed: ${ZIG_REPOSITORY_ERROR}")
|
||||
endif()
|
||||
|
||||
file(REMOVE_RECURSE ${ZIG_PATH}/lib)
|
||||
file(RENAME ${ZIG_PATH}/tmp/lib ${ZIG_PATH}/lib)
|
||||
file(REMOVE_RECURSE ${ZIG_PATH}/tmp)
|
||||
message(STATUS "Saved ${ZIG_PATH}/lib")
|
||||
endif()
|
||||
|
||||
message(STATUS "Saved ${ZIG_EXE}")
|
||||
@@ -1,74 +1,85 @@
|
||||
include(cmake/Globals.cmake)
|
||||
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
|
||||
message(STATUS "Running script: ${SCRIPT_NAME}")
|
||||
|
||||
if(NOT GIT_PATH OR NOT GIT_REPOSITORY OR NOT GIT_REF)
|
||||
message(FATAL_ERROR "git_clone: GIT_PATH, GIT_REPOSITORY, and GIT_REF are required")
|
||||
if(NOT GIT_PATH OR NOT GIT_REPOSITORY)
|
||||
message(FATAL_ERROR "GIT_PATH and GIT_REPOSITORY are required")
|
||||
endif()
|
||||
|
||||
setx(GIT_PATH ${GIT_PATH})
|
||||
setx(GIT_REPOSITORY ${GIT_REPOSITORY})
|
||||
setx(GIT_REF ${GIT_REF})
|
||||
if(GIT_COMMIT)
|
||||
set(GIT_REF ${GIT_COMMIT})
|
||||
elseif(GIT_TAG)
|
||||
set(GIT_REF refs/tags/${GIT_TAG})
|
||||
elseif(GIT_BRANCH)
|
||||
set(GIT_REF refs/heads/${GIT_BRANCH})
|
||||
else()
|
||||
message(FATAL_ERROR "GIT_COMMIT, GIT_TAG, or GIT_BRANCH are required")
|
||||
endif()
|
||||
|
||||
string(REGEX MATCH "([^/]+)$" GIT_ORIGINAL_NAME ${GIT_REPOSITORY})
|
||||
|
||||
if(NOT GIT_NAME)
|
||||
setx(GIT_NAME ${GIT_ORIGINAL_NAME})
|
||||
set(GIT_NAME ${GIT_ORIGINAL_NAME})
|
||||
endif()
|
||||
|
||||
set(GIT_REF_PATH ${GIT_PATH}/.ref)
|
||||
set(GIT_DOWNLOAD_URL https://github.com/${GIT_REPOSITORY}/archive/${GIT_REF}.tar.gz)
|
||||
|
||||
if(EXISTS ${GIT_REF_PATH})
|
||||
file(READ ${GIT_REF_PATH} GIT_CACHED_REF)
|
||||
if(GIT_CACHED_REF STREQUAL GIT_REF)
|
||||
return()
|
||||
endif()
|
||||
message(STATUS "Cloning ${GIT_REPOSITORY} at ${GIT_REF}...")
|
||||
execute_process(
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DDOWNLOAD_URL=${GIT_DOWNLOAD_URL}
|
||||
-DDOWNLOAD_PATH=${GIT_PATH}
|
||||
-DDOWNLOAD_FILTERS=${GIT_FILTERS}
|
||||
-P ${CMAKE_CURRENT_LIST_DIR}/DownloadUrl.cmake
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_VARIABLE
|
||||
GIT_ERROR
|
||||
RESULT_VARIABLE
|
||||
GIT_RESULT
|
||||
)
|
||||
|
||||
if(NOT GIT_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "Clone failed: ${GIT_ERROR}")
|
||||
endif()
|
||||
|
||||
setx(GIT_DOWNLOAD_PATH ${GIT_PATH}.tar.gz)
|
||||
setx(GIT_DOWNLOAD_URL https://github.com/${GIT_REPOSITORY}/archive/${GIT_REF}.tar.gz)
|
||||
|
||||
foreach(i RANGE 10)
|
||||
set(GIT_DOWNLOAD_TMP_PATH ${GIT_PATH}.tmp.${i})
|
||||
file(DOWNLOAD
|
||||
${GIT_DOWNLOAD_URL}
|
||||
${GIT_DOWNLOAD_TMP_PATH}
|
||||
TIMEOUT 120
|
||||
STATUS GIT_DOWNLOAD_STATUS
|
||||
SHOW_PROGRESS
|
||||
)
|
||||
if(GIT_DOWNLOAD_STATUS MATCHES "^0" AND EXISTS ${GIT_DOWNLOAD_TMP_PATH})
|
||||
file(RENAME ${GIT_DOWNLOAD_TMP_PATH} ${GIT_DOWNLOAD_PATH})
|
||||
break()
|
||||
endif()
|
||||
message(WARNING "git_clone: ${GIT_DOWNLOAD_STATUS}: ${GIT_DOWNLOAD_URL}")
|
||||
file(REMOVE ${GIT_DOWNLOAD_TMP_PATH})
|
||||
endforeach()
|
||||
|
||||
if(NOT EXISTS ${GIT_DOWNLOAD_PATH})
|
||||
message(FATAL_ERROR "git_clone: failed to download ${GIT_DOWNLOAD_URL}")
|
||||
endif()
|
||||
|
||||
file(REMOVE_RECURSE ${GIT_PATH})
|
||||
get_filename_component(GIT_PARENT_PATH ${GIT_PATH} DIRECTORY)
|
||||
file(ARCHIVE_EXTRACT INPUT ${GIT_DOWNLOAD_PATH} DESTINATION ${GIT_PARENT_PATH}/tmp-${GIT_ORIGINAL_NAME} TOUCH)
|
||||
file(GLOB GIT_TMP_PATH LIST_DIRECTORIES ON ${GIT_PARENT_PATH}/tmp-${GIT_ORIGINAL_NAME}/${GIT_ORIGINAL_NAME}-*)
|
||||
file(RENAME ${GIT_TMP_PATH} ${GIT_PATH})
|
||||
file(REMOVE_RECURSE ${GIT_PARENT_PATH}/tmp-${GIT_ORIGINAL_NAME})
|
||||
file(REMOVE ${GIT_DOWNLOAD_PATH})
|
||||
|
||||
file(GLOB_RECURSE GIT_PATCH_PATHS ${CMAKE_SOURCE_DIR}/patches/${GIT_NAME}/*)
|
||||
foreach(GIT_PATCH_PATH ${GIT_PATCH_PATHS})
|
||||
if(GIT_PATCH_PATH MATCHES "\\.patch$")
|
||||
execute_process(
|
||||
COMMAND git apply --ignore-whitespace --ignore-space-change --no-index --verbose ${GIT_PATCH_PATH}
|
||||
WORKING_DIRECTORY ${GIT_PATH}
|
||||
RESULT_VARIABLE GIT_PATCH_RESULT
|
||||
)
|
||||
if(NOT GIT_PATCH_RESULT EQUAL 0)
|
||||
message(FATAL_ERROR "git_clone: failed to apply patch: ${GIT_PATCH_PATH}")
|
||||
endif()
|
||||
else()
|
||||
file(COPY ${GIT_PATCH_PATH} DESTINATION ${GIT_PATH})
|
||||
endif()
|
||||
endforeach()
|
||||
list(LENGTH GIT_PATCH_PATHS GIT_PATCH_COUNT)
|
||||
|
||||
file(WRITE ${GIT_REF_PATH} ${GIT_REF})
|
||||
if(GIT_PATCH_COUNT GREATER 0)
|
||||
find_program(GIT_PROGRAM git REQUIRED)
|
||||
|
||||
foreach(GIT_PATCH ${GIT_PATCH_PATHS})
|
||||
get_filename_component(GIT_PATCH_NAME ${GIT_PATCH} NAME)
|
||||
|
||||
if(GIT_PATCH_NAME MATCHES "\\.patch$")
|
||||
message(STATUS "Applying patch ${GIT_PATCH_NAME}...")
|
||||
execute_process(
|
||||
COMMAND
|
||||
${GIT_PROGRAM}
|
||||
apply
|
||||
--ignore-whitespace
|
||||
--ignore-space-change
|
||||
--no-index
|
||||
--verbose
|
||||
${GIT_PATCH}
|
||||
WORKING_DIRECTORY
|
||||
${GIT_PATH}
|
||||
ERROR_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_VARIABLE
|
||||
GIT_PATCH_ERROR
|
||||
RESULT_VARIABLE
|
||||
GIT_PATCH_RESULT
|
||||
)
|
||||
|
||||
if(NOT GIT_PATCH_RESULT EQUAL 0 AND NOT GIT_PATCH_ERROR MATCHES "cleanly")
|
||||
file(REMOVE_RECURSE ${GIT_PATH})
|
||||
message(FATAL_ERROR "Failed to apply patch: ${GIT_PATCH_ERROR}")
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Copying file ${GIT_PATCH_NAME}...")
|
||||
file(COPY ${GIT_PATCH} DESTINATION ${GIT_PATH})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
file(WRITE ${GIT_PATH}/.ref ${GIT_REF})
|
||||
message(STATUS "Cloned ${GIT_REPOSITORY}")
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
register_vendor_target(boringssl)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
boringssl
|
||||
${boringssl}
|
||||
REPOSITORY
|
||||
oven-sh/boringssl
|
||||
COMMIT
|
||||
29a2cd359458c9384694b75456026e4b57e3e567
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
register_libraries(
|
||||
TARGET ${boringssl}
|
||||
crypto
|
||||
ssl
|
||||
decrepit
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
boringssl
|
||||
LIBRARIES
|
||||
${boringssl}
|
||||
CMAKE_TARGET
|
||||
crypto
|
||||
ssl
|
||||
decrepit
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
INCLUDES
|
||||
include
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${boringssl}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
)
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
register_vendor_target(brotli)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
brotli
|
||||
${brotli}
|
||||
REPOSITORY
|
||||
google/brotli
|
||||
TAG
|
||||
v1.1.0
|
||||
COMMIT
|
||||
ed738e842d2fbdf2d6459e39267a633c4a9b2f5d
|
||||
)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${brotli}
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${brotli}
|
||||
CMAKE_TARGET
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${brotli}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
BROTLI_BUILD_TOOLS=OFF
|
||||
BROTLI_EMSCRIPTEN=OFF
|
||||
BROTLI_DISABLE_TESTS=ON
|
||||
)
|
||||
|
||||
# Tests fail with "BrotliDecompressionError" when LTO is enabled
|
||||
# only on Linux x64 (non-baseline). It's a mystery.
|
||||
if(LINUX AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64" AND NOT ENABLE_BASELINE)
|
||||
set(BROTLI_CMAKE_ARGS "-DCMAKE_C_FLAGS=-fno-lto")
|
||||
if(LINUX AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64" AND NOT ENABLE_BASELINE)
|
||||
register_compiler_flags(
|
||||
TARGET ${brotli}
|
||||
-fno-lto
|
||||
)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
brotli
|
||||
LIBRARIES
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DBROTLI_BUILD_TOOLS=OFF
|
||||
-DBROTLI_EMSCRIPTEN=OFF
|
||||
-DBROTLI_DISABLE_TESTS=ON
|
||||
${BROTLI_CMAKE_ARGS}
|
||||
INCLUDES
|
||||
c/include
|
||||
)
|
||||
|
||||
@@ -12,15 +12,6 @@ else()
|
||||
set(bunStrip bun)
|
||||
endif()
|
||||
|
||||
set(bunExe ${bun}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
|
||||
if(bunStrip)
|
||||
set(bunStripExe ${bunStrip}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(buns ${bun} ${bunStrip})
|
||||
else()
|
||||
set(buns ${bun})
|
||||
endif()
|
||||
|
||||
# Some commands use this path, and some do not.
|
||||
# In the future, change those commands so that generated files are written to this path.
|
||||
optionx(CODEGEN_PATH FILEPATH "Path to the codegen directory" DEFAULT ${BUILD_PATH}/codegen)
|
||||
@@ -54,7 +45,7 @@ register_command(
|
||||
COMMENT
|
||||
"Generating src/js_lexer/*.blob"
|
||||
COMMAND
|
||||
${CMAKE_ZIG_COMPILER}
|
||||
${ZIG_EXECUTABLE}
|
||||
run
|
||||
${CMAKE_ZIG_FLAGS}
|
||||
${BUN_ZIG_IDENTIFIER_SCRIPT}
|
||||
@@ -62,8 +53,6 @@ register_command(
|
||||
${BUN_ZIG_IDENTIFIER_SOURCES}
|
||||
OUTPUTS
|
||||
${BUN_ZIG_IDENTIFIER_OUTPUTS}
|
||||
TARGETS
|
||||
clone-zig
|
||||
)
|
||||
|
||||
set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error)
|
||||
@@ -474,6 +463,19 @@ WEBKIT_ADD_SOURCE_DEPENDENCIES(
|
||||
${CODEGEN_PATH}/InternalModuleRegistryConstants.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
if(ENABLE_CANARY)
|
||||
set(Bun_VERSION_WITH_TAG ${VERSION}-canary.${CANARY_REVISION})
|
||||
else()
|
||||
set(Bun_VERSION_WITH_TAG ${VERSION})
|
||||
endif()
|
||||
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
|
||||
configure_file(
|
||||
${CWD}/src/windows-app-info.rc
|
||||
${CODEGEN_PATH}/windows-app-info.rc
|
||||
)
|
||||
endif()
|
||||
|
||||
# --- Zig ---
|
||||
|
||||
file(GLOB_RECURSE BUN_ZIG_SOURCES ${CONFIGURE_DEPENDS}
|
||||
@@ -484,6 +486,9 @@ list(APPEND BUN_ZIG_SOURCES
|
||||
${CWD}/build.zig
|
||||
${CWD}/root.zig
|
||||
${CWD}/root_wasm.zig
|
||||
)
|
||||
|
||||
set(BUN_ZIG_GENERATED_SOURCES
|
||||
${BUN_ZIG_IDENTIFIER_OUTPUTS}
|
||||
${BUN_ERROR_OUTPUTS}
|
||||
${BUN_FALLBACK_DECODER_OUTPUT}
|
||||
@@ -496,9 +501,9 @@ list(APPEND BUN_ZIG_SOURCES
|
||||
|
||||
# In debug builds, these are not embedded, but rather referenced at runtime.
|
||||
if (DEBUG)
|
||||
list(APPEND BUN_ZIG_SOURCES ${CODEGEN_PATH}/kit_empty_file)
|
||||
list(APPEND BUN_ZIG_GENERATED_SOURCES ${CODEGEN_PATH}/kit_empty_file)
|
||||
else()
|
||||
list(APPEND BUN_ZIG_SOURCES ${BUN_KIT_RUNTIME_OUTPUTS})
|
||||
list(APPEND BUN_ZIG_GENERATED_SOURCES ${BUN_KIT_RUNTIME_OUTPUTS})
|
||||
endif()
|
||||
|
||||
set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o)
|
||||
@@ -527,7 +532,7 @@ register_command(
|
||||
COMMENT
|
||||
"Building src/*.zig for ${ZIG_TARGET}"
|
||||
COMMAND
|
||||
${CMAKE_ZIG_COMPILER}
|
||||
${ZIG_EXECUTABLE}
|
||||
build obj
|
||||
${CMAKE_ZIG_FLAGS}
|
||||
--prefix ${BUILD_PATH}
|
||||
@@ -545,14 +550,13 @@ register_command(
|
||||
${BUN_ZIG_OUTPUT}
|
||||
SOURCES
|
||||
${BUN_ZIG_SOURCES}
|
||||
TARGETS
|
||||
clone-zig
|
||||
${BUN_ZIG_GENERATED_SOURCES}
|
||||
)
|
||||
|
||||
set_property(TARGET bun-zig PROPERTY JOB_POOL compile_pool)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "build.zig")
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CWD}/build.zig)
|
||||
|
||||
# --- C/C++ Sources ---
|
||||
# --- C/C++ Object ---
|
||||
|
||||
set(BUN_USOCKETS_SOURCE ${CWD}/packages/bun-usockets)
|
||||
|
||||
@@ -577,17 +581,6 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}
|
||||
${BUN_USOCKETS_SOURCE}/src/crypto/*.c
|
||||
)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
picohttpparser
|
||||
REPOSITORY
|
||||
h2o/picohttpparser
|
||||
COMMIT
|
||||
066d2b1e9ab820703db0837a7255d92d30f0c9f5
|
||||
OUTPUTS
|
||||
picohttpparser.c
|
||||
)
|
||||
|
||||
list(APPEND BUN_C_SOURCES ${VENDOR_PATH}/picohttpparser/picohttpparser.c)
|
||||
|
||||
if(WIN32)
|
||||
@@ -604,22 +597,12 @@ list(APPEND BUN_CPP_SOURCES
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
if(ENABLE_CANARY)
|
||||
set(Bun_VERSION_WITH_TAG ${VERSION}-canary.${CANARY_REVISION})
|
||||
else()
|
||||
set(Bun_VERSION_WITH_TAG ${VERSION})
|
||||
endif()
|
||||
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
|
||||
configure_file(
|
||||
${CWD}/src/windows-app-info.rc
|
||||
${CODEGEN_PATH}/windows-app-info.rc
|
||||
)
|
||||
list(APPEND BUN_CPP_SOURCES ${CODEGEN_PATH}/windows-app-info.rc)
|
||||
endif()
|
||||
|
||||
# --- Executable ---
|
||||
|
||||
set(BUN_CPP_OUTPUT ${BUILD_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}${bun}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
set(BUN_EXE_OUTPUT ${BUILD_PATH}/${CMAKE_EXECUTABLE_PREFIX}${bun}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(BUN_EXE_STRIP_OUTPUT ${BUILD_PATH}/${CMAKE_EXECUTABLE_PREFIX}bun${CMAKE_EXECUTABLE_SUFFIX})
|
||||
|
||||
if(BUN_LINK_ONLY)
|
||||
add_executable(${bun} ${BUN_CPP_OUTPUT} ${BUN_ZIG_OUTPUT})
|
||||
@@ -627,30 +610,21 @@ if(BUN_LINK_ONLY)
|
||||
target_link_libraries(${bun} PRIVATE ${BUN_CPP_OUTPUT})
|
||||
elseif(BUN_CPP_ONLY)
|
||||
add_library(${bun} STATIC ${BUN_CPP_SOURCES})
|
||||
register_command(
|
||||
TARGET
|
||||
${bun}
|
||||
TARGET_PHASE
|
||||
POST_BUILD
|
||||
COMMENT
|
||||
"Uploading ${bun}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E true
|
||||
ARTIFACTS
|
||||
${BUN_CPP_OUTPUT}
|
||||
upload_artifacts(
|
||||
TARGET ${bun}
|
||||
${BUN_CPP_OUTPUT}
|
||||
)
|
||||
else()
|
||||
add_executable(${bun} ${BUN_CPP_SOURCES})
|
||||
target_link_libraries(${bun} PRIVATE ${BUN_ZIG_OUTPUT})
|
||||
upload_artifacts(
|
||||
TARGET ${bun}
|
||||
${BUN_EXE_OUTPUT}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT bun STREQUAL "bun")
|
||||
add_custom_target(bun DEPENDS ${bun})
|
||||
endif()
|
||||
|
||||
# --- C/C++ Properties ---
|
||||
|
||||
set_target_properties(${bun} PROPERTIES
|
||||
OUTPUT_NAME ${bun}
|
||||
CXX_STANDARD 20
|
||||
CXX_STANDARD_REQUIRED YES
|
||||
CXX_EXTENSIONS YES
|
||||
@@ -660,6 +634,17 @@ set_target_properties(${bun} PROPERTIES
|
||||
VISIBILITY_INLINES_HIDDEN YES
|
||||
)
|
||||
|
||||
if(BUN_LINK_ONLY)
|
||||
set_target_properties(${bun} PROPERTIES
|
||||
OUTPUT_NAME ${bun}
|
||||
LINKER_LANGUAGE CXX
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT bun STREQUAL "bun")
|
||||
add_custom_target(bun DEPENDS ${bun})
|
||||
endif()
|
||||
|
||||
# --- C/C++ Includes ---
|
||||
|
||||
if(WIN32)
|
||||
@@ -714,7 +699,6 @@ target_compile_definitions(${bun} PRIVATE
|
||||
WITH_BORINGSSL=1
|
||||
STATICALLY_LINKED_WITH_JavaScriptCore=1
|
||||
STATICALLY_LINKED_WITH_BMALLOC=1
|
||||
BUILDING_WITH_CMAKE=1
|
||||
JSC_OBJC_API_ENABLED=0
|
||||
BUN_SINGLE_THREADED_PER_VM_ENTRY_SCOPE=1
|
||||
NAPI_EXPERIMENTAL=ON
|
||||
@@ -731,7 +715,6 @@ if(DEBUG AND NOT CI)
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
# --- Compiler options ---
|
||||
|
||||
if(NOT WIN32)
|
||||
@@ -820,8 +803,34 @@ elseif(APPLE)
|
||||
-fno-keep-static-consts
|
||||
)
|
||||
else()
|
||||
# Try to use lld-16 if available, otherwise fallback to lld
|
||||
# Cache it so we don't have to re-run CMake to pick it up
|
||||
if((NOT DEFINED LLD_NAME) AND (NOT CI OR BUN_LINK_ONLY))
|
||||
find_program(LLD_EXECUTABLE_NAME lld-${LLVM_VERSION_MAJOR})
|
||||
|
||||
if(NOT LLD_EXECUTABLE_NAME)
|
||||
if(CI)
|
||||
# Ensure we don't use a differing version of lld in CI vs clang
|
||||
message(FATAL_ERROR "lld-${LLVM_VERSION_MAJOR} not found. Please make sure you have LLVM ${LLVM_VERSION_MAJOR}.x installed and set to lld-${LLVM_VERSION_MAJOR}")
|
||||
endif()
|
||||
|
||||
# To make it easier for contributors, allow differing versions of lld vs clang/cmake
|
||||
find_program(LLD_EXECUTABLE_NAME lld)
|
||||
endif()
|
||||
|
||||
if(NOT LLD_EXECUTABLE_NAME)
|
||||
message(FATAL_ERROR "LLD not found. Please make sure you have LLVM ${LLVM_VERSION_MAJOR}.x installed and lld is available in your PATH as lld-${LLVM_VERSION_MAJOR}")
|
||||
endif()
|
||||
|
||||
# normalize to basename so it can be used with -fuse-ld
|
||||
get_filename_component(LLD_NAME ${LLD_EXECUTABLE_NAME} NAME CACHE)
|
||||
message(STATUS "Using linker: ${LLD_NAME} (${LLD_EXECUTABLE_NAME})")
|
||||
elseif(NOT DEFINED LLD_NAME)
|
||||
set(LLD_NAME lld-${LLVM_VERSION_MAJOR})
|
||||
endif()
|
||||
|
||||
target_link_options(${bun} PUBLIC
|
||||
-fuse-ld=lld-${LLVM_VERSION_MAJOR}
|
||||
-fuse-ld=${LLD_NAME}
|
||||
-fno-pic
|
||||
-static-libstdc++
|
||||
-static-libgcc
|
||||
@@ -880,8 +889,6 @@ set_target_properties(${bun} PROPERTIES LINK_DEPENDS ${BUN_SYMBOLS_PATH})
|
||||
|
||||
# --- WebKit ---
|
||||
|
||||
include(SetupWebKit)
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
target_link_libraries(${bun} PRIVATE
|
||||
@@ -918,34 +925,38 @@ endif()
|
||||
|
||||
# --- Dependencies ---
|
||||
|
||||
set(BUN_DEPENDENCIES
|
||||
BoringSSL
|
||||
Brotli
|
||||
Cares
|
||||
LibDeflate
|
||||
LolHtml
|
||||
Lshpack
|
||||
Mimalloc
|
||||
TinyCC
|
||||
Zlib
|
||||
LibArchive # must be loaded after zlib
|
||||
Zstd
|
||||
register_link_targets(
|
||||
TARGET ${bun}
|
||||
${boringssl}
|
||||
${brotli}
|
||||
${cares}
|
||||
${libarchive}
|
||||
${libdeflate}
|
||||
${libuv} ${WIN32}
|
||||
${lolhtml}
|
||||
${lshpack}
|
||||
${mimalloc}
|
||||
${tinycc}
|
||||
${sqlite} ${USE_STATIC_SQLITE}
|
||||
${webkit}
|
||||
${zlib}
|
||||
${zstd}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND BUN_DEPENDENCIES Libuv)
|
||||
endif()
|
||||
|
||||
if(USE_STATIC_SQLITE)
|
||||
list(APPEND BUN_DEPENDENCIES SQLite)
|
||||
endif()
|
||||
|
||||
foreach(dependency ${BUN_DEPENDENCIES})
|
||||
include(Build${dependency})
|
||||
endforeach()
|
||||
|
||||
list(TRANSFORM BUN_DEPENDENCIES TOLOWER OUTPUT_VARIABLE BUN_TARGETS)
|
||||
add_custom_target(dependencies DEPENDS ${BUN_TARGETS})
|
||||
register_includes(
|
||||
TARGET ${bun}
|
||||
${${picohttpparser}_CWD}
|
||||
${${boringssl}_CWD}/include
|
||||
${${brotli}_CWD}/c/include
|
||||
${${cares}_CWD}/include
|
||||
${${libarchive}_CWD}/include
|
||||
${${libdeflate}_CWD}
|
||||
${${libuv}_CWD}/include ${WIN32}
|
||||
${${lshpack}_CWD}
|
||||
${${lshpack}_CWD}/compat/queue ${WIN32}
|
||||
${${mimalloc}_CWD}/include
|
||||
${${zlib}_CWD}
|
||||
)
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(${bun} PRIVATE icucore resolv)
|
||||
@@ -991,6 +1002,12 @@ endif()
|
||||
|
||||
# --- Packaging ---
|
||||
|
||||
if(bunStrip)
|
||||
set(buns ${bun} ${bunStrip})
|
||||
else()
|
||||
set(buns ${bun})
|
||||
endif()
|
||||
|
||||
if(NOT BUN_CPP_ONLY)
|
||||
if(bunStrip)
|
||||
register_command(
|
||||
@@ -1002,15 +1019,15 @@ if(NOT BUN_CPP_ONLY)
|
||||
"Stripping ${bun}"
|
||||
COMMAND
|
||||
${CMAKE_STRIP}
|
||||
${bunExe}
|
||||
${BUN_EXE_OUTPUT}
|
||||
--strip-all
|
||||
--strip-debug
|
||||
--discard-all
|
||||
-o ${bunStripExe}
|
||||
-o ${BUN_EXE_STRIP_OUTPUT}
|
||||
CWD
|
||||
${BUILD_PATH}
|
||||
OUTPUTS
|
||||
${BUILD_PATH}/${bunStripExe}
|
||||
${BUN_EXE_STRIP_OUTPUT}
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1023,9 +1040,9 @@ if(NOT BUN_CPP_ONLY)
|
||||
"Testing ${bun}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-E env BUN_DEBUG_QUIET_LOGS=1
|
||||
${BUILD_PATH}/${bunExe}
|
||||
--revision
|
||||
-E env BUN_DEBUG_QUIET_LOGS=1
|
||||
${BUN_EXE_OUTPUT}
|
||||
--revision
|
||||
CWD
|
||||
${BUILD_PATH}
|
||||
)
|
||||
@@ -1045,7 +1062,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
BUN_GARBAGE_COLLECTOR_LEVEL=1
|
||||
BUN_DEBUG_QUIET_LOGS=1
|
||||
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1
|
||||
${BUILD_PATH}/${bunExe}
|
||||
${BUN_EXE_OUTPUT}
|
||||
${BUN_FEATURES_SCRIPT}
|
||||
CWD
|
||||
${BUILD_PATH}
|
||||
@@ -1054,7 +1071,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_APPLE AND bunStrip)
|
||||
if(bunStrip AND APPLE)
|
||||
register_command(
|
||||
TARGET
|
||||
${bun}
|
||||
@@ -1084,7 +1101,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
set(bunTriplet bun-${OS}-${ARCH})
|
||||
endif()
|
||||
string(REPLACE bun ${bunTriplet} bunPath ${bun})
|
||||
set(bunFiles ${bunExe} features.json)
|
||||
set(bunFiles ${BUN_EXE_OUTPUT} features.json)
|
||||
if(WIN32)
|
||||
list(APPEND bunFiles ${bun}.pdb)
|
||||
elseif(APPLE)
|
||||
@@ -1121,7 +1138,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E rm -rf ${bunStripPath} ${bunStripPath}.zip
|
||||
&& ${CMAKE_COMMAND} -E make_directory ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E copy ${bunStripExe} ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E copy ${${BUN_EXE_STRIP_OUTPUT}} ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E tar cfv ${bunStripPath}.zip --format=zip ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E rm -rf ${bunStripPath}
|
||||
CWD
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
register_vendor_target(cares)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
cares
|
||||
${cares}
|
||||
REPOSITORY
|
||||
c-ares/c-ares
|
||||
COMMIT
|
||||
d1722e6e8acaf10eb73fa995798a9cd421d9f85e
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
cares
|
||||
TARGETS
|
||||
c-ares
|
||||
ARGS
|
||||
-DCARES_STATIC=ON
|
||||
-DCARES_STATIC_PIC=ON # FORCE_PIC was set to 1, but CARES_STATIC_PIC was set to OFF??
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DCARES_SHARED=OFF
|
||||
-DCARES_BUILD_TOOLS=OFF # this was set to ON?
|
||||
LIB_PATH
|
||||
lib
|
||||
LIBRARIES
|
||||
cares
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${cares}
|
||||
PATH lib
|
||||
cares
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${cares}
|
||||
CMAKE_TARGET
|
||||
c-ares
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${cares}
|
||||
CARES_STATIC=ON
|
||||
CARES_STATIC_PIC=ON
|
||||
CARES_SHARED=OFF
|
||||
CARES_BUILD_TOOLS=OFF
|
||||
CMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
)
|
||||
|
||||
@@ -1,53 +1,61 @@
|
||||
register_vendor_target(libarchive)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libarchive
|
||||
${libarchive}
|
||||
REPOSITORY
|
||||
libarchive/libarchive
|
||||
COMMIT
|
||||
898dc8319355b7e985f68a9819f182aaed61b53a
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libarchive
|
||||
TARGETS
|
||||
archive_static
|
||||
ARGS
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DENABLE_INSTALL=OFF
|
||||
-DENABLE_TEST=OFF
|
||||
-DENABLE_WERROR=OFF
|
||||
-DENABLE_BZIP2=OFF
|
||||
-DENABLE_CAT=OFF
|
||||
-DENABLE_EXPAT=OFF
|
||||
-DENABLE_ICONV=OFF
|
||||
-DENABLE_LIBB2=OFF
|
||||
-DENABLE_LibGCC=OFF
|
||||
-DENABLE_LIBXML2=OFF
|
||||
-DENABLE_LZ4=OFF
|
||||
-DENABLE_LZMA=OFF
|
||||
-DENABLE_LZO=OFF
|
||||
-DENABLE_MBEDTLS=OFF
|
||||
-DENABLE_NETTLE=OFF
|
||||
-DENABLE_OPENSSL=OFF
|
||||
-DENABLE_PCRE2POSIX=OFF
|
||||
-DENABLE_PCREPOSIX=OFF
|
||||
-DENABLE_ZSTD=OFF
|
||||
# libarchive depends on zlib headers, otherwise it will
|
||||
# spawn a processes to compress instead of using the library.
|
||||
-DENABLE_ZLIB=OFF
|
||||
-DHAVE_ZLIB_H=ON
|
||||
-DCMAKE_C_FLAGS="-I${VENDOR_PATH}/zlib"
|
||||
LIB_PATH
|
||||
libarchive
|
||||
LIBRARIES
|
||||
archive
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${libarchive}
|
||||
PATH libarchive
|
||||
archive
|
||||
)
|
||||
|
||||
# Must be loaded after zlib is defined
|
||||
if(TARGET clone-zlib)
|
||||
add_dependencies(libarchive clone-zlib)
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libarchive}
|
||||
CMAKE_TARGET
|
||||
archive_static
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libarchive}
|
||||
CMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
ENABLE_INSTALL=OFF
|
||||
ENABLE_TEST=OFF
|
||||
ENABLE_WERROR=OFF
|
||||
ENABLE_BZIP2=OFF
|
||||
ENABLE_CAT=OFF
|
||||
ENABLE_EXPAT=OFF
|
||||
ENABLE_ICONV=OFF
|
||||
ENABLE_LIBB2=OFF
|
||||
ENABLE_LibGCC=OFF
|
||||
ENABLE_LIBXML2=OFF
|
||||
ENABLE_LZ4=OFF
|
||||
ENABLE_LZMA=OFF
|
||||
ENABLE_LZO=OFF
|
||||
ENABLE_MBEDTLS=OFF
|
||||
ENABLE_NETTLE=OFF
|
||||
ENABLE_OPENSSL=OFF
|
||||
ENABLE_PCRE2POSIX=OFF
|
||||
ENABLE_PCREPOSIX=OFF
|
||||
ENABLE_ZSTD=OFF
|
||||
ENABLE_ZLIB=OFF
|
||||
HAVE_ZLIB_H=ON
|
||||
)
|
||||
|
||||
# libarchive depends on zlib headers, otherwise it will
|
||||
# spawn a processes to compress instead of using the library.
|
||||
register_includes(
|
||||
TARGET ${libarchive}
|
||||
${VENDOR_PATH}/${zlib}
|
||||
)
|
||||
|
||||
if(TARGET clone-${zlib})
|
||||
add_dependencies(${libarchive} clone-${zlib})
|
||||
endif()
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
register_vendor_target(libdeflate)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libdeflate
|
||||
${libdeflate}
|
||||
REPOSITORY
|
||||
ebiggers/libdeflate
|
||||
COMMIT
|
||||
dc76454a39e7e83b68c3704b6e3784654f8d5ac5
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libdeflate
|
||||
TARGETS
|
||||
libdeflate_static
|
||||
ARGS
|
||||
-DLIBDEFLATE_BUILD_STATIC_LIB=ON
|
||||
-DLIBDEFLATE_BUILD_SHARED_LIB=OFF
|
||||
-DLIBDEFLATE_BUILD_GZIP=OFF
|
||||
LIBRARIES
|
||||
deflatestatic WIN32
|
||||
deflate UNIX
|
||||
INCLUDES
|
||||
.
|
||||
register_libraries(
|
||||
TARGET ${libdeflate}
|
||||
deflatestatic ${WIN32}
|
||||
deflate ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libdeflate}
|
||||
CMAKE_TARGET
|
||||
libdeflate_static
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libdeflate}
|
||||
LIBDEFLATE_BUILD_STATIC_LIB=ON
|
||||
LIBDEFLATE_BUILD_SHARED_LIB=OFF
|
||||
LIBDEFLATE_BUILD_GZIP=OFF
|
||||
)
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
register_vendor_target(libuv)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libuv
|
||||
${libuv}
|
||||
REPOSITORY
|
||||
libuv/libuv
|
||||
COMMIT
|
||||
da527d8d2a908b824def74382761566371439003
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LIBUV_CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS -Wno-int-conversion")
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libuv
|
||||
TARGETS
|
||||
uv_a
|
||||
ARGS
|
||||
-DLIBUV_BUILD_SHARED=OFF
|
||||
-DLIBUV_BUILD_TESTS=OFF
|
||||
-DLIBUV_BUILD_BENCH=OFF
|
||||
-DCMAKE_C_FLAGS=${LIBUV_CMAKE_C_FLAGS}
|
||||
LIBRARIES
|
||||
libuv WIN32
|
||||
uv UNIX
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${libuv}
|
||||
uv_a ${WIN32}
|
||||
uv ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libuv}
|
||||
CMAKE_TARGET
|
||||
uv_a
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libuv}
|
||||
LIBUV_BUILD_SHARED=OFF
|
||||
LIBUV_BUILD_TESTS=OFF
|
||||
LIBUV_BUILD_BENCH=OFF
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
register_compiler_flags(
|
||||
TARGET ${libuv}
|
||||
/DWIN32
|
||||
/D_WINDOWS
|
||||
-Wno-int-conversion
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,45 +1,50 @@
|
||||
register_vendor_target(lolhtml)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
lolhtml
|
||||
${lolhtml}
|
||||
REPOSITORY
|
||||
cloudflare/lol-html
|
||||
COMMIT
|
||||
8d4c273ded322193d017042d1f48df2766b0f88b
|
||||
)
|
||||
|
||||
set(LOLHTML_CWD ${VENDOR_PATH}/lolhtml/c-api)
|
||||
set(LOLHTML_BUILD_PATH ${BUILD_PATH}/lolhtml)
|
||||
|
||||
if(DEBUG)
|
||||
set(LOLHTML_BUILD_TYPE debug)
|
||||
set(${lolhtml}_BUILD_TYPE debug)
|
||||
else()
|
||||
set(LOLHTML_BUILD_TYPE release)
|
||||
set(${lolhtml}_BUILD_TYPE release)
|
||||
endif()
|
||||
|
||||
set(LOLHTML_LIBRARY ${LOLHTML_BUILD_PATH}/${LOLHTML_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}lolhtml${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
register_libraries(
|
||||
TARGET ${lolhtml}
|
||||
PATH ${${lolhtml}_BUILD_TYPE}
|
||||
VARIABLE ${lolhtml}_LIBRARY
|
||||
lolhtml
|
||||
)
|
||||
|
||||
set(LOLHTML_BUILD_ARGS
|
||||
--target-dir ${BUILD_PATH}/lolhtml
|
||||
set(${lolhtml}_BUILD_COMMAND
|
||||
${CARGO_EXECUTABLE}
|
||||
build
|
||||
--target-dir ${${lolhtml}_BUILD_PATH}
|
||||
)
|
||||
|
||||
if(RELEASE)
|
||||
list(APPEND LOLHTML_BUILD_ARGS --release)
|
||||
list(APPEND ${lolhtml}_BUILD_COMMAND --release)
|
||||
endif()
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
lolhtml
|
||||
build-${lolhtml}
|
||||
CWD
|
||||
${LOLHTML_CWD}
|
||||
${${lolhtml}_CWD}/c-api
|
||||
COMMAND
|
||||
${CARGO_EXECUTABLE}
|
||||
build
|
||||
${LOLHTML_BUILD_ARGS}
|
||||
${${lolhtml}_BUILD_COMMAND}
|
||||
ARTIFACTS
|
||||
${LOLHTML_LIBRARY}
|
||||
${${lolhtml}_LIBRARY}
|
||||
)
|
||||
|
||||
target_link_libraries(${bun} PRIVATE ${LOLHTML_LIBRARY})
|
||||
if(BUN_LINK_ONLY)
|
||||
target_sources(${bun} PRIVATE ${LOLHTML_LIBRARY})
|
||||
if(TARGET clone-${lolhtml})
|
||||
add_dependencies(build-${lolhtml} clone-${lolhtml})
|
||||
endif()
|
||||
|
||||
add_dependencies(${lolhtml} build-${lolhtml})
|
||||
|
||||
@@ -1,33 +1,42 @@
|
||||
register_vendor_target(lshpack)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
lshpack
|
||||
${lshpack}
|
||||
REPOSITORY
|
||||
litespeedtech/ls-hpack
|
||||
COMMIT
|
||||
3d0f1fc1d6e66a642e7a98c55deb38aa986eb4b0
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LSHPACK_INCLUDES . compat/queue)
|
||||
else()
|
||||
set(LSHPACK_INCLUDES .)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
lshpack
|
||||
LIBRARIES
|
||||
ls-hpack
|
||||
ARGS
|
||||
-DSHARED=OFF
|
||||
-DLSHPACK_XXH=ON
|
||||
# There are linking errors when built with non-Release
|
||||
# Undefined symbols for architecture arm64:
|
||||
# "___asan_handle_no_return", referenced from:
|
||||
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
|
||||
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
|
||||
# _update_hash in libls-hpack.a(lshpack.c.o)
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
INCLUDES
|
||||
${LSHPACK_INCLUDES}
|
||||
register_libraries(
|
||||
TARGET ${lshpack}
|
||||
ls-hpack
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${lshpack}
|
||||
CMAKE_TARGET
|
||||
ls-hpack
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${lshpack}
|
||||
SHARED=OFF
|
||||
LSHPACK_XXH=ON
|
||||
BUILD_TESTING=OFF
|
||||
)
|
||||
|
||||
# FIXME: There are linking errors when built with non-Release
|
||||
# Undefined symbols for architecture arm64:
|
||||
# "___asan_handle_no_return", referenced from:
|
||||
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
|
||||
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
|
||||
# _update_hash in libls-hpack.a(lshpack.c.o)
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
register_cmake_definitions(
|
||||
TARGET ${lshpack}
|
||||
CMAKE_BUILD_TYPE=Release
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,60 +1,63 @@
|
||||
register_vendor_target(mimalloc)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
mimalloc
|
||||
${mimalloc}
|
||||
REPOSITORY
|
||||
oven-sh/mimalloc
|
||||
COMMIT
|
||||
4c283af60cdae205df5a872530c77e2a6a307d43
|
||||
)
|
||||
|
||||
set(MIMALLOC_CMAKE_ARGS
|
||||
-DMI_BUILD_STATIC=ON
|
||||
-DMI_BUILD_OBJECT=ON
|
||||
-DMI_BUILD_SHARED=OFF
|
||||
-DMI_BUILD_TESTS=OFF
|
||||
-DMI_USE_CXX=ON
|
||||
-DMI_OVERRIDE=OFF
|
||||
-DMI_OSX_ZONE=OFF
|
||||
-DMI_OSX_INTERPOSE=OFF
|
||||
-DMI_SKIP_COLLECT_ON_EXIT=ON
|
||||
)
|
||||
|
||||
if(DEBUG)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_FULL=ON)
|
||||
endif()
|
||||
|
||||
if(ENABLE_VALGRIND)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_VALGRIND=ON)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
set(MIMALLOC_LIBRARY mimalloc-static-debug)
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY mimalloc-static)
|
||||
endif()
|
||||
elseif(DEBUG)
|
||||
set(MIMALLOC_LIBRARY mimalloc-debug)
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY mimalloc)
|
||||
endif()
|
||||
|
||||
# Workaround for linker issue on macOS and Linux x64
|
||||
# https://github.com/microsoft/mimalloc/issues/512
|
||||
if(APPLE OR (LINUX AND NOT DEBUG))
|
||||
set(MIMALLOC_LIBRARY CMakeFiles/mimalloc-obj.dir/src/static.c.o)
|
||||
register_libraries(
|
||||
TARGET ${mimalloc}
|
||||
PATH CMakeFiles/mimalloc-obj.dir/src
|
||||
static.c.o
|
||||
)
|
||||
else()
|
||||
register_libraries(
|
||||
TARGET ${mimalloc}
|
||||
mimalloc-static-debug ${WIN32} AND ${DEBUG}
|
||||
mimalloc-static ${WIN32} AND ${RELEASE}
|
||||
mimalloc-debug ${UNIX} AND ${DEBUG}
|
||||
mimalloc ${UNIX} AND ${RELEASE}
|
||||
)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
mimalloc
|
||||
TARGETS
|
||||
${mimalloc}
|
||||
CMAKE_TARGETS
|
||||
mimalloc-static
|
||||
mimalloc-obj
|
||||
ARGS
|
||||
${MIMALLOC_CMAKE_ARGS}
|
||||
LIBRARIES
|
||||
${MIMALLOC_LIBRARY}
|
||||
INCLUDES
|
||||
include
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_BUILD_STATIC=ON
|
||||
MI_BUILD_OBJECT=ON
|
||||
MI_BUILD_SHARED=OFF
|
||||
MI_BUILD_TESTS=OFF
|
||||
MI_USE_CXX=ON
|
||||
MI_OVERRIDE=OFF
|
||||
MI_OSX_ZONE=OFF
|
||||
MI_OSX_INTERPOSE=OFF
|
||||
MI_SKIP_COLLECT_ON_EXIT=ON
|
||||
)
|
||||
|
||||
if(ENABLE_ASSERTIONS)
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_DEBUG_FULL=ON
|
||||
MI_SHOW_ERRORS=ON
|
||||
)
|
||||
if(ENABLE_VALGRIND)
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_VALGRIND=ON
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
12
cmake/targets/BuildPicoHTTPParser.cmake
Normal file
12
cmake/targets/BuildPicoHTTPParser.cmake
Normal file
@@ -0,0 +1,12 @@
|
||||
register_vendor_target(picohttpparser)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
${picohttpparser}
|
||||
REPOSITORY
|
||||
h2o/picohttpparser
|
||||
COMMIT
|
||||
066d2b1e9ab820703db0837a7255d92d30f0c9f5
|
||||
OUTPUTS
|
||||
picohttpparser.c
|
||||
)
|
||||
@@ -1,10 +1,13 @@
|
||||
register_cmake_command(
|
||||
register_vendor_target(sqlite)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${sqlite}
|
||||
sqlite3
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
sqlite
|
||||
${sqlite}
|
||||
CWD
|
||||
${CWD}/src/bun.js/bindings/sqlite
|
||||
LIBRARIES
|
||||
sqlite3
|
||||
INCLUDES
|
||||
.
|
||||
)
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
register_vendor_target(tinycc)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
tinycc
|
||||
${tinycc}
|
||||
REPOSITORY
|
||||
oven-sh/tinycc
|
||||
COMMIT
|
||||
29985a3b59898861442fa3b43f663fc1af2591d7
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
tinycc
|
||||
LIBRARIES
|
||||
tcc
|
||||
register_libraries(
|
||||
TARGET ${tinycc}
|
||||
tcc
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${tinycc}
|
||||
)
|
||||
|
||||
88
cmake/targets/BuildWebKit.cmake
Normal file
88
cmake/targets/BuildWebKit.cmake
Normal file
@@ -0,0 +1,88 @@
|
||||
optionx(WEBKIT_LOCAL BOOL "If a local version of WebKit should be used instead of downloading" DEFAULT OFF)
|
||||
optionx(WEBKIT_VERSION STRING "The version of WebKit to use" DEFAULT "4a2db3254a9535949a5d5380eb58cf0f77c8e15a")
|
||||
|
||||
if(WEBKIT_LOCAL)
|
||||
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/webkit)
|
||||
endif()
|
||||
|
||||
optionx(WEBKIT_PATH FILEPATH "The path to the WebKit directory" DEFAULT ${DEFAULT_WEBKIT_PATH})
|
||||
|
||||
set(WEBKIT_INCLUDE_PATH ${WEBKIT_PATH}/include)
|
||||
set(WEBKIT_LIB_PATH ${WEBKIT_PATH}/lib)
|
||||
|
||||
register_vendor_target(webkit)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${webkit}
|
||||
PATH ${WEBKIT_PATH}/lib
|
||||
JavaScriptCore
|
||||
WTF
|
||||
bmalloc ${LINUX}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
register_libraries(
|
||||
TARGET ${webkit}
|
||||
PATH ${WEBKIT_PATH}/lib
|
||||
sicudt ${RELEASE}
|
||||
sicudtd ${DEBUG}
|
||||
sicuin ${RELEASE}
|
||||
sicuind ${DEBUG}
|
||||
sicuuc ${RELEASE}
|
||||
sicuucd ${DEBUG}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WEBKIT_LOCAL)
|
||||
# Must be built seperately, in the future this can be integrated into the build process
|
||||
register_target(build-webkit)
|
||||
else()
|
||||
if(WIN32)
|
||||
set(WEBKIT_OS "windows")
|
||||
elseif(APPLE)
|
||||
set(WEBKIT_OS "macos")
|
||||
elseif(LINUX)
|
||||
set(WEBKIT_OS "linux")
|
||||
else()
|
||||
unsupported(CMAKE_SYSTEM_NAME)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
|
||||
set(WEBKIT_ARCH "arm64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
|
||||
set(WEBKIT_ARCH "amd64")
|
||||
else()
|
||||
unsupported(CMAKE_SYSTEM_PROCESSOR)
|
||||
endif()
|
||||
|
||||
if(DEBUG)
|
||||
set(WEBKIT_SUFFIX "-debug")
|
||||
elseif(ENABLE_LTO AND NOT WIN32)
|
||||
set(WEBKIT_SUFFIX "-lto")
|
||||
else()
|
||||
set(WEBKIT_SUFFIX "")
|
||||
endif()
|
||||
|
||||
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
||||
set(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_NAME}.tar.gz)
|
||||
|
||||
get_libraries(${webkit} WEBKIT_LIBRARIES)
|
||||
register_command(
|
||||
TARGET
|
||||
clone-${webkit}
|
||||
COMMENT
|
||||
"Downloading ${WEBKIT_NAME}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DDOWNLOAD_PATH=${WEBKIT_PATH}
|
||||
-DDOWNLOAD_URL=${WEBKIT_DOWNLOAD_URL}
|
||||
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
|
||||
OUTPUTS
|
||||
${WEBKIT_PATH}/package.json
|
||||
${WEBKIT_LIBRARIES}
|
||||
)
|
||||
|
||||
register_outputs(TARGET clone-${webkit} ${WEBKIT_PATH})
|
||||
endif()
|
||||
@@ -1,40 +1,38 @@
|
||||
register_vendor_target(zlib)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
zlib
|
||||
${zlib}
|
||||
REPOSITORY
|
||||
cloudflare/zlib
|
||||
COMMIT
|
||||
886098f3f339617b4243b286f5ed364b9989e245
|
||||
)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${zlib}
|
||||
z ${UNIX}
|
||||
zlib ${WIN32} AND ${RELEASE}
|
||||
zlibd ${WIN32} AND ${DEBUG}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${zlib}
|
||||
CMAKE_TARGET
|
||||
zlib
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${zlib}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
BUILD_EXAMPLES=OFF
|
||||
)
|
||||
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/25755
|
||||
if(APPLE)
|
||||
set(ZLIB_CMAKE_C_FLAGS "-fno-define-target-os-macros")
|
||||
set(ZLIB_CMAKE_CXX_FLAGS "-fno-define-target-os-macros")
|
||||
register_compiler_flags(
|
||||
TARGET ${zlib}
|
||||
-fno-define-target-os-macros
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
set(ZLIB_LIBRARY "zlibd")
|
||||
else()
|
||||
set(ZLIB_LIBRARY "zlib")
|
||||
endif()
|
||||
else()
|
||||
set(ZLIB_LIBRARY "z")
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
zlib
|
||||
TARGETS
|
||||
zlib
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DBUILD_EXAMPLES=OFF
|
||||
"-DCMAKE_C_FLAGS=${ZLIB_CMAKE_C_FLAGS}"
|
||||
"-DCMAKE_CXX_FLAGS=${ZLIB_CMAKE_CXX_FLAGS}"
|
||||
LIBRARIES
|
||||
${ZLIB_LIBRARY}
|
||||
INCLUDES
|
||||
.
|
||||
)
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
register_vendor_target(zstd)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
zstd
|
||||
${zstd}
|
||||
REPOSITORY
|
||||
facebook/zstd
|
||||
COMMIT
|
||||
794ea1b0afca0f020f4e57b6732332231fb23c70
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
zstd
|
||||
TARGETS
|
||||
libzstd_static
|
||||
ARGS
|
||||
-Sbuild/cmake
|
||||
-DZSTD_BUILD_STATIC=ON
|
||||
-DZSTD_BUILD_PROGRAMS=OFF
|
||||
-DZSTD_BUILD_TESTS=OFF
|
||||
-DZSTD_BUILD_CONTRIB=OFF
|
||||
LIB_PATH
|
||||
lib
|
||||
LIBRARIES
|
||||
zstd_static WIN32
|
||||
zstd UNIX
|
||||
register_libraries(
|
||||
TARGET ${zstd}
|
||||
PATH lib
|
||||
zstd_static ${WIN32}
|
||||
zstd ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${zstd}
|
||||
CMAKE_TARGET
|
||||
libzstd_static
|
||||
CMAKE_PATH
|
||||
build/cmake
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${zstd}
|
||||
ZSTD_BUILD_STATIC=ON
|
||||
ZSTD_BUILD_PROGRAMS=OFF
|
||||
ZSTD_BUILD_TESTS=OFF
|
||||
ZSTD_BUILD_CONTRIB=OFF
|
||||
)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
optionx(BUILDKITE_CACHE BOOL "If the build can use Buildkite caches, even if not running in Buildkite" DEFAULT ${BUILDKITE})
|
||||
|
||||
if(NOT BUILDKITE_CACHE OR NOT BUN_LINK_ONLY)
|
||||
if(NOT BUN_LINK_ONLY)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -33,7 +31,7 @@ if(NOT BUILDKITE_BUILD_ID)
|
||||
endif()
|
||||
|
||||
setx(BUILDKITE_BUILD_URL https://buildkite.com/${BUILDKITE_ORGANIZATION_SLUG}/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_ID})
|
||||
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/builds/${BUILDKITE_BUILD_ID})
|
||||
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/${BUILDKITE_BUILD_ID})
|
||||
|
||||
file(
|
||||
DOWNLOAD ${BUILDKITE_BUILD_URL}
|
||||
@@ -125,15 +123,14 @@ foreach(i RANGE ${BUILDKITE_JOBS_MAX_INDEX})
|
||||
set(BUILDKITE_DOWNLOAD_COMMAND curl -L -o ${BUILDKITE_ARTIFACT_PATH} ${BUILDKITE_ARTIFACTS_URL}/${BUILDKITE_ARTIFACT_ID})
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
COMMENT
|
||||
"Downloading ${BUILDKITE_ARTIFACT_PATH}"
|
||||
VERBATIM COMMAND
|
||||
${BUILDKITE_DOWNLOAD_COMMAND}
|
||||
WORKING_DIRECTORY
|
||||
${BUILD_PATH}
|
||||
OUTPUT
|
||||
${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}
|
||||
message(STATUS "Downloading ${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}")
|
||||
get_filename_component(BUILDKITE_ARTIFACT_NAME ${BUILDKITE_ARTIFACT_PATH} NAME_WE)
|
||||
register_command(
|
||||
TARGET download-${BUILDKITE_ARTIFACT_NAME}
|
||||
COMMENT "Downloading ${BUILDKITE_ARTIFACT_PATH}"
|
||||
COMMAND ${BUILDKITE_DOWNLOAD_COMMAND}
|
||||
CWD ${BUILD_PATH}
|
||||
OUTPUTS ${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
|
||||
@@ -14,11 +14,8 @@ find_command(
|
||||
ON
|
||||
)
|
||||
|
||||
set(CCACHE_ARGS CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
|
||||
foreach(arg ${CCACHE_ARGS})
|
||||
setx(${arg} ${CCACHE_PROGRAM})
|
||||
list(APPEND CMAKE_ARGS -D${arg}=${${arg}})
|
||||
endforeach()
|
||||
setx(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
|
||||
setx(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
|
||||
|
||||
setenv(CCACHE_DIR ${CACHE_PATH}/ccache)
|
||||
setenv(CCACHE_BASEDIR ${CWD})
|
||||
|
||||
@@ -33,7 +33,6 @@ macro(find_llvm_command VARIABLE COMMAND)
|
||||
PATHS ${LLVM_PATH}
|
||||
VERSION ${LLVM_VERSION}
|
||||
)
|
||||
list(APPEND CMAKE_ARGS -D${VARIABLE}=${${VARIABLE}})
|
||||
endmacro()
|
||||
|
||||
macro(find_llvm_command_no_version VARIABLE COMMAND)
|
||||
@@ -43,7 +42,6 @@ macro(find_llvm_command_no_version VARIABLE COMMAND)
|
||||
PATHS ${LLVM_PATH}
|
||||
REQUIRED ON
|
||||
)
|
||||
list(APPEND CMAKE_ARGS -D${VARIABLE}=${${VARIABLE}})
|
||||
endmacro()
|
||||
|
||||
if(WIN32)
|
||||
|
||||
@@ -52,8 +52,3 @@ if(CMAKE_OSX_SYSROOT_ERROR)
|
||||
endif()
|
||||
|
||||
optionx(CMAKE_OSX_SYSROOT STRING "The macOS SDK path to target" DEFAULT ${DEFAULT_CMAKE_OSX_SYSROOT})
|
||||
|
||||
list(APPEND CMAKE_ARGS
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
|
||||
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
|
||||
)
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
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 4a2db3254a9535949a5d5380eb58cf0f77c8e15a)
|
||||
endif()
|
||||
|
||||
if(WEBKIT_LOCAL)
|
||||
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(DEFAULT_WEBKIT_PATH ${CACHE_PATH}/webkit-${WEBKIT_VERSION})
|
||||
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
|
||||
)
|
||||
endif()
|
||||
|
||||
# After this point, only prebuilt WebKit is supported
|
||||
return()
|
||||
endif()
|
||||
|
||||
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()
|
||||
|
||||
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(DEBUG)
|
||||
set(WEBKIT_SUFFIX "-debug")
|
||||
elseif(ENABLE_LTO AND NOT WIN32)
|
||||
set(WEBKIT_SUFFIX "-lto")
|
||||
else()
|
||||
set(WEBKIT_SUFFIX "")
|
||||
endif()
|
||||
|
||||
set(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})
|
||||
|
||||
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})
|
||||
|
||||
if(APPLE)
|
||||
file(REMOVE_RECURSE ${WEBKIT_INCLUDE_PATH}/unicode)
|
||||
endif()
|
||||
@@ -43,101 +43,33 @@ optionx(ZIG_OPTIMIZE "ReleaseFast|ReleaseSafe|ReleaseSmall|Debug" "The Zig optim
|
||||
# Change to "bc" to experiment, "Invalid record" means it is not valid output.
|
||||
optionx(ZIG_OBJECT_FORMAT "obj|bc" "Output file format for Zig object files" DEFAULT obj)
|
||||
|
||||
optionx(ZIG_VERSION STRING "The version of zig to use" DEFAULT "0.13.0")
|
||||
optionx(ZIG_LOCAL_CACHE_DIR FILEPATH "The path to local the zig cache directory" DEFAULT ${CACHE_PATH}/zig/local)
|
||||
optionx(ZIG_GLOBAL_CACHE_DIR FILEPATH "The path to the global zig cache directory" DEFAULT ${CACHE_PATH}/zig/global)
|
||||
|
||||
setx(ZIG_REPOSITORY_PATH ${VENDOR_PATH}/zig)
|
||||
setx(ZIG_PATH ${CACHE_PATH}/zig/bin)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
zig
|
||||
REPOSITORY
|
||||
oven-sh/zig
|
||||
COMMIT
|
||||
131a009ba2eb127a3447d05b9e12f710429aa5ee
|
||||
PATH
|
||||
${ZIG_REPOSITORY_PATH}
|
||||
)
|
||||
|
||||
setenv(ZIG_LOCAL_CACHE_DIR ${ZIG_LOCAL_CACHE_DIR})
|
||||
setenv(ZIG_GLOBAL_CACHE_DIR ${ZIG_GLOBAL_CACHE_DIR})
|
||||
|
||||
setx(ZIG_PATH ${VENDOR_PATH}/zig)
|
||||
|
||||
if(WIN32)
|
||||
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig.exe)
|
||||
else()
|
||||
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig)
|
||||
endif()
|
||||
|
||||
set(CMAKE_ZIG_FLAGS
|
||||
--cache-dir ${ZIG_LOCAL_CACHE_DIR}
|
||||
--global-cache-dir ${ZIG_GLOBAL_CACHE_DIR}
|
||||
--zig-lib-dir ${ZIG_REPOSITORY_PATH}/lib
|
||||
--zig-lib-dir ${ZIG_PATH}/lib
|
||||
)
|
||||
|
||||
find_command(
|
||||
VARIABLE
|
||||
CMAKE_ZIG_COMPILER
|
||||
COMMAND
|
||||
zig
|
||||
zig.exe
|
||||
PATHS
|
||||
${ZIG_PATH}
|
||||
VERSION
|
||||
${ZIG_VERSION}
|
||||
REQUIRED
|
||||
OFF
|
||||
)
|
||||
|
||||
if(CMAKE_ZIG_COMPILER)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
|
||||
set(ZIG_HOST_ARCH "aarch64")
|
||||
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|x64|AMD64")
|
||||
set(ZIG_HOST_ARCH "x86_64")
|
||||
else()
|
||||
unsupported(CMAKE_HOST_SYSTEM_PROCESSOR)
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_APPLE)
|
||||
set(ZIG_HOST_OS "macos")
|
||||
elseif(CMAKE_HOST_WIN32)
|
||||
set(ZIG_HOST_OS "windows")
|
||||
elseif(CMAKE_HOST_UNIX)
|
||||
set(ZIG_HOST_OS "linux")
|
||||
else()
|
||||
unsupported(CMAKE_HOST_SYSTEM_NAME)
|
||||
endif()
|
||||
|
||||
set(ZIG_NAME zig-${ZIG_HOST_OS}-${ZIG_HOST_ARCH}-${ZIG_VERSION})
|
||||
|
||||
if(CMAKE_HOST_WIN32)
|
||||
set(ZIG_EXE "zig.exe")
|
||||
set(ZIG_FILENAME ${ZIG_NAME}.zip)
|
||||
else()
|
||||
set(ZIG_EXE "zig")
|
||||
set(ZIG_FILENAME ${ZIG_NAME}.tar.xz)
|
||||
endif()
|
||||
|
||||
setx(ZIG_DOWNLOAD_URL https://ziglang.org/download/${ZIG_VERSION}/${ZIG_FILENAME})
|
||||
file(DOWNLOAD ${ZIG_DOWNLOAD_URL} ${TMP_PATH}/${ZIG_FILENAME} SHOW_PROGRESS)
|
||||
file(ARCHIVE_EXTRACT INPUT ${TMP_PATH}/${ZIG_FILENAME} DESTINATION ${TMP_PATH} TOUCH)
|
||||
file(REMOVE ${TMP_PATH}/${ZIG_FILENAME})
|
||||
file(COPY ${TMP_PATH}/${ZIG_NAME}/${ZIG_EXE} DESTINATION ${ZIG_PATH})
|
||||
file(CHMOD ${ZIG_PATH}/${ZIG_EXE} PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE)
|
||||
setx(CMAKE_ZIG_COMPILER ${ZIG_PATH}/${ZIG_EXE})
|
||||
|
||||
if(NOT WIN32)
|
||||
file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC)
|
||||
endif()
|
||||
|
||||
# Some zig commands need the executable to be in the same directory as the zig repository
|
||||
register_command(
|
||||
COMMENT
|
||||
"Creating symlink for zig"
|
||||
"Downloading zig"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy ${ZIG_PATH}/${ZIG_EXE} ${ZIG_REPOSITORY_PATH}/${ZIG_EXE}
|
||||
&& ${CMAKE_COMMAND} -E create_symlink ${ZIG_REPOSITORY_PATH}/${ZIG_EXE} ${ZIG_REPOSITORY_PATH}/zig.exe
|
||||
${CMAKE_COMMAND}
|
||||
-DZIG_PATH=${ZIG_PATH}
|
||||
-P ${CWD}/cmake/scripts/DownloadZig.cmake
|
||||
OUTPUTS
|
||||
${ZIG_REPOSITORY_PATH}/${ZIG_EXE}
|
||||
${ZIG_REPOSITORY_PATH}/zig.exe
|
||||
TARGETS
|
||||
clone-zig
|
||||
${ZIG_EXECUTABLE}
|
||||
)
|
||||
|
||||
15
package.json
15
package.json
@@ -40,20 +40,25 @@
|
||||
"build:release:local": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -DWEBKIT_LOCAL=ON -B build/release",
|
||||
"build:release:with_logs": "cmake . -DCMAKE_BUILD_TYPE=Release -DENABLE_LOGS=true -GNinja -Bbuild-release && ninja -Cbuild-release",
|
||||
"build:debug-zig-release": "cmake . -DCMAKE_BUILD_TYPE=Release -DZIG_OPTIMIZE=Debug -GNinja -Bbuild-debug-zig-release && ninja -Cbuild-debug-zig-release",
|
||||
"bump": "bun ./scripts/bump.ts",
|
||||
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
|
||||
"fmt": "prettier --config=.prettierrc-ci --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
|
||||
"fmt:cpp": "clang-format -i src/bun.js/bindings/**/*.{cpp,h} --verbose",
|
||||
"fmt:zig": "bun run zig:fmt",
|
||||
"fmt:cpp": "bun run build --target clang-format",
|
||||
"fmt:zig": "bun run build --target zig-format",
|
||||
"lint": "eslint './**/*.d.ts' --cache",
|
||||
"lint:fix": "eslint './**/*.d.ts' --cache --fix",
|
||||
"test": "node scripts/runner.node.mjs ./build/bun-debug",
|
||||
"test:release": "node scripts/runner.node.mjs ./build-release/bun",
|
||||
"banned": "bun packages/bun-internal-test/src/linter.ts",
|
||||
"zig": "vendor/zig/zig.exe",
|
||||
"zig:fmt": "bun run zig fmt src/*.zig src/*/*.zig src/*/*/*.zig src/*/*/*/*.zig",
|
||||
"zig:fmt": "bun run fmt:zig",
|
||||
"zig:check": "bun run zig build check --summary new",
|
||||
"zig:check-all": "bun run zig build check-all --summary new",
|
||||
"zig:check-windows": "bun run zig build check-windows --summary new"
|
||||
"zig:check-windows": "bun run zig build check-windows --summary new",
|
||||
"clang-format": "bun run build --target clang-format --fresh",
|
||||
"clang-format:check": "bun run build --target clang-format-check --fresh",
|
||||
"clang-tidy": "bun run build --target clang-tidy --fresh",
|
||||
"clang-tidy:check": "bun run build --target clang-tidy --fresh",
|
||||
"zig-format": "bun run build --target zig-format --fresh",
|
||||
"zig-format:check": "bun run build --target zig-format-check --fresh"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,20 +15,21 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/* This Server Name Indication hostname tree is written in C++ but could be ported to C.
|
||||
* Overall it looks like crap, but has no memory allocations in fast path and is O(log n). */
|
||||
/* This Server Name Indication hostname tree is written in C++ but could be
|
||||
* ported to C. Overall it looks like crap, but has no memory allocations in
|
||||
* fast path and is O(log n). */
|
||||
|
||||
#ifndef SNI_TREE_H
|
||||
#define SNI_TREE_H
|
||||
|
||||
#ifndef LIBUS_NO_SSL
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
|
||||
/* We only handle a maximum of 10 labels per hostname */
|
||||
#define MAX_LABELS 10
|
||||
@@ -37,180 +38,186 @@
|
||||
thread_local void (*sni_free_cb)(void *);
|
||||
|
||||
struct sni_node {
|
||||
/* Empty nodes must always hold null */
|
||||
void *user = nullptr;
|
||||
std::map<std::string_view, std::unique_ptr<sni_node>> children;
|
||||
/* Empty nodes must always hold null */
|
||||
void *user = nullptr;
|
||||
std::map<std::string_view, std::unique_ptr<sni_node>> children;
|
||||
|
||||
~sni_node() {
|
||||
for (auto &p : children) {
|
||||
/* The data of our string_views are managed by malloc */
|
||||
free((void *) p.first.data());
|
||||
~sni_node() {
|
||||
for (auto &p : children) {
|
||||
/* The data of our string_views are managed by malloc */
|
||||
free((void *)p.first.data());
|
||||
|
||||
/* Call destructor passed to sni_free only if we hold data.
|
||||
* This is important since sni_remove does not have sni_free_cb set */
|
||||
if (p.second.get()->user) {
|
||||
sni_free_cb(p.second.get()->user);
|
||||
}
|
||||
}
|
||||
/* Call destructor passed to sni_free only if we hold data.
|
||||
* This is important since sni_remove does not have sni_free_cb set */
|
||||
if (p.second.get()->user) {
|
||||
sni_free_cb(p.second.get()->user);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// this can only delete ONE single node, but may cull "empty nodes with null as data"
|
||||
void *removeUser(struct sni_node *root, unsigned int label, std::string_view *labels, unsigned int numLabels) {
|
||||
// this can only delete ONE single node, but may cull "empty nodes with null as
|
||||
// data"
|
||||
void *removeUser(struct sni_node *root, unsigned int label,
|
||||
std::string_view *labels, unsigned int numLabels) {
|
||||
|
||||
/* If we are in the bottom (past bottom by one), there is nothing to remove */
|
||||
if (label == numLabels) {
|
||||
void *user = root->user;
|
||||
/* Mark us for culling on the way up */
|
||||
root->user = nullptr;
|
||||
return user;
|
||||
}
|
||||
/* If we are in the bottom (past bottom by one), there is nothing to remove */
|
||||
if (label == numLabels) {
|
||||
void *user = root->user;
|
||||
/* Mark us for culling on the way up */
|
||||
root->user = nullptr;
|
||||
return user;
|
||||
}
|
||||
|
||||
/* Is this label a child of root? */
|
||||
auto it = root->children.find(labels[label]);
|
||||
if (it == root->children.end()) {
|
||||
/* We cannot continue */
|
||||
return nullptr;
|
||||
}
|
||||
/* Is this label a child of root? */
|
||||
auto it = root->children.find(labels[label]);
|
||||
if (it == root->children.end()) {
|
||||
/* We cannot continue */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *removedUser = removeUser(it->second.get(), label + 1, labels, numLabels);
|
||||
void *removedUser =
|
||||
removeUser(it->second.get(), label + 1, labels, numLabels);
|
||||
|
||||
/* On the way back up, we may cull empty nodes with no children.
|
||||
* This ends up being where we remove all nodes */
|
||||
if (it->second.get()->children.empty() && it->second.get()->user == nullptr) {
|
||||
/* On the way back up, we may cull empty nodes with no children.
|
||||
* This ends up being where we remove all nodes */
|
||||
if (it->second.get()->children.empty() && it->second.get()->user == nullptr) {
|
||||
|
||||
/* The data of our string_views are managed by malloc */
|
||||
free((void *) it->first.data());
|
||||
/* The data of our string_views are managed by malloc */
|
||||
free((void *)it->first.data());
|
||||
|
||||
/* This can only happen with user set to null, otherwise we use sni_free_cb which is unset by sni_remove */
|
||||
root->children.erase(it);
|
||||
}
|
||||
/* This can only happen with user set to null, otherwise we use sni_free_cb
|
||||
* which is unset by sni_remove */
|
||||
root->children.erase(it);
|
||||
}
|
||||
|
||||
return removedUser;
|
||||
return removedUser;
|
||||
}
|
||||
|
||||
void *getUser(struct sni_node *root, unsigned int label, std::string_view *labels, unsigned int numLabels) {
|
||||
void *getUser(struct sni_node *root, unsigned int label,
|
||||
std::string_view *labels, unsigned int numLabels) {
|
||||
|
||||
/* Do we have labels to match? Otherwise, return where we stand */
|
||||
if (label == numLabels) {
|
||||
return root->user;
|
||||
/* Do we have labels to match? Otherwise, return where we stand */
|
||||
if (label == numLabels) {
|
||||
return root->user;
|
||||
}
|
||||
|
||||
/* Try and match by our label */
|
||||
auto it = root->children.find(labels[label]);
|
||||
if (it != root->children.end()) {
|
||||
void *user = getUser(it->second.get(), label + 1, labels, numLabels);
|
||||
if (user) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
/* Try and match by our label */
|
||||
auto it = root->children.find(labels[label]);
|
||||
if (it != root->children.end()) {
|
||||
void *user = getUser(it->second.get(), label + 1, labels, numLabels);
|
||||
if (user) {
|
||||
return user;
|
||||
}
|
||||
}
|
||||
/* Try and match by wildcard */
|
||||
it = root->children.find("*");
|
||||
if (it == root->children.end()) {
|
||||
/* Matching has failed for both label and wildcard */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Try and match by wildcard */
|
||||
it = root->children.find("*");
|
||||
if (it == root->children.end()) {
|
||||
/* Matching has failed for both label and wildcard */
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* We matched by wildcard */
|
||||
return getUser(it->second.get(), label + 1, labels, numLabels);
|
||||
/* We matched by wildcard */
|
||||
return getUser(it->second.get(), label + 1, labels, numLabels);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
void *sni_new() {
|
||||
return new sni_node;
|
||||
void *sni_new() { return new sni_node; }
|
||||
|
||||
void sni_free(void *sni, void (*cb)(void *)) {
|
||||
/* We want to run this callback for every remaining name */
|
||||
sni_free_cb = cb;
|
||||
|
||||
delete (sni_node *)sni;
|
||||
}
|
||||
|
||||
/* Returns non-null if this name already exists */
|
||||
int sni_add(void *sni, const char *hostname, void *user) {
|
||||
struct sni_node *root = (struct sni_node *)sni;
|
||||
|
||||
/* Traverse all labels in hostname */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label; view.length();
|
||||
view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
|
||||
auto it = root->children.find(label);
|
||||
if (it == root->children.end()) {
|
||||
/* Duplicate this label for our kept string_view of it */
|
||||
void *labelString = malloc(label.length());
|
||||
memcpy(labelString, label.data(), label.length());
|
||||
|
||||
it = root->children
|
||||
.emplace(std::string_view((char *)labelString, label.length()),
|
||||
std::make_unique<sni_node>())
|
||||
.first; // NOLINT(clang-analyzer-unix.Malloc)
|
||||
}
|
||||
|
||||
void sni_free(void *sni, void (*cb)(void *)) {
|
||||
/* We want to run this callback for every remaining name */
|
||||
sni_free_cb = cb;
|
||||
root = it->second.get();
|
||||
}
|
||||
|
||||
delete (sni_node *) sni;
|
||||
/* We must never add multiple contexts for the same name, as that would
|
||||
* overwrite and leak */
|
||||
if (root->user) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
root->user = user;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Removes the exact match. Wildcards are treated as the verbatim asterisk char,
|
||||
* not as an actual wildcard */
|
||||
void *sni_remove(void *sni, const char *hostname) {
|
||||
struct sni_node *root = (struct sni_node *)sni;
|
||||
|
||||
/* I guess 10 labels is an okay limit */
|
||||
std::string_view labels[10];
|
||||
unsigned int numLabels = 0;
|
||||
|
||||
/* We traverse all labels first of all */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label; view.length();
|
||||
view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
|
||||
/* Anything longer than 10 labels is forbidden */
|
||||
if (numLabels == 10) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Returns non-null if this name already exists */
|
||||
int sni_add(void *sni, const char *hostname, void *user) {
|
||||
struct sni_node *root = (struct sni_node *) sni;
|
||||
labels[numLabels++] = label;
|
||||
}
|
||||
|
||||
/* Traverse all labels in hostname */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label;
|
||||
view.length(); view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
return removeUser(root, 0, labels, numLabels);
|
||||
}
|
||||
|
||||
auto it = root->children.find(label);
|
||||
if (it == root->children.end()) {
|
||||
/* Duplicate this label for our kept string_view of it */
|
||||
void *labelString = malloc(label.length());
|
||||
memcpy(labelString, label.data(), label.length());
|
||||
void *sni_find(void *sni, const char *hostname) {
|
||||
struct sni_node *root = (struct sni_node *)sni;
|
||||
|
||||
it = root->children.emplace(std::string_view((char *) labelString, label.length()),
|
||||
std::make_unique<sni_node>()).first; // NOLINT(clang-analyzer-unix.Malloc)
|
||||
}
|
||||
/* I guess 10 labels is an okay limit */
|
||||
std::string_view labels[10];
|
||||
unsigned int numLabels = 0;
|
||||
|
||||
root = it->second.get();
|
||||
}
|
||||
/* We traverse all labels first of all */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label; view.length();
|
||||
view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
|
||||
/* We must never add multiple contexts for the same name, as that would overwrite and leak */
|
||||
if (root->user) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
root->user = user;
|
||||
|
||||
return 0;
|
||||
/* Anything longer than 10 labels is forbidden */
|
||||
if (numLabels == 10) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/* Removes the exact match. Wildcards are treated as the verbatim asterisk char, not as an actual wildcard */
|
||||
void *sni_remove(void *sni, const char *hostname) {
|
||||
struct sni_node *root = (struct sni_node *) sni;
|
||||
|
||||
/* I guess 10 labels is an okay limit */
|
||||
std::string_view labels[10];
|
||||
unsigned int numLabels = 0;
|
||||
|
||||
/* We traverse all labels first of all */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label;
|
||||
view.length(); view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
|
||||
/* Anything longer than 10 labels is forbidden */
|
||||
if (numLabels == 10) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
labels[numLabels++] = label;
|
||||
}
|
||||
|
||||
return removeUser(root, 0, labels, numLabels);
|
||||
}
|
||||
|
||||
void *sni_find(void *sni, const char *hostname) {
|
||||
struct sni_node *root = (struct sni_node *) sni;
|
||||
|
||||
/* I guess 10 labels is an okay limit */
|
||||
std::string_view labels[10];
|
||||
unsigned int numLabels = 0;
|
||||
|
||||
/* We traverse all labels first of all */
|
||||
for (std::string_view view(hostname, strlen(hostname)), label;
|
||||
view.length(); view.remove_prefix(std::min(view.length(), label.length() + 1))) {
|
||||
/* Label is the token separated by dot */
|
||||
label = view.substr(0, view.find('.', 0));
|
||||
|
||||
/* Anything longer than 10 labels is forbidden */
|
||||
if (numLabels == 10) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
labels[numLabels++] = label;
|
||||
}
|
||||
|
||||
return getUser(root, 0, labels, numLabels);
|
||||
}
|
||||
labels[numLabels++] = label;
|
||||
}
|
||||
|
||||
return getUser(root, 0, labels, numLabels);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -127,7 +127,9 @@ int us_poll_events(struct us_poll_t *p) {
|
||||
|
||||
size_t us_internal_accept_poll_event(struct us_poll_t *p) { return 0; }
|
||||
|
||||
int us_internal_poll_type(struct us_poll_t *p) { return p->poll_type & POLL_TYPE_KIND_MASK; }
|
||||
int us_internal_poll_type(struct us_poll_t *p) {
|
||||
return p->poll_type & POLL_TYPE_KIND_MASK;
|
||||
}
|
||||
|
||||
void us_internal_poll_set_type(struct us_poll_t *p, int poll_type) {
|
||||
p->poll_type = poll_type | (p->poll_type & POLL_TYPE_POLLING_MASK);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "libusockets.h"
|
||||
#include "internal/internal.h"
|
||||
#include "libusockets.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -24,56 +24,65 @@
|
||||
// return bsd_udp_packet_buffer_ecn((struct udp_recvbuf *)buf, index);
|
||||
// }
|
||||
|
||||
int us_udp_packet_buffer_local_ip(struct us_udp_packet_buffer_t *buf, int index, char *ip) {
|
||||
return bsd_udp_packet_buffer_local_ip((struct udp_recvbuf *)buf, index, ip);
|
||||
int us_udp_packet_buffer_local_ip(struct us_udp_packet_buffer_t *buf, int index,
|
||||
char *ip) {
|
||||
return bsd_udp_packet_buffer_local_ip((struct udp_recvbuf *)buf, index, ip);
|
||||
}
|
||||
|
||||
char *us_udp_packet_buffer_peer(struct us_udp_packet_buffer_t *buf, int index) {
|
||||
return bsd_udp_packet_buffer_peer((struct udp_recvbuf *)buf, index);
|
||||
return bsd_udp_packet_buffer_peer((struct udp_recvbuf *)buf, index);
|
||||
}
|
||||
|
||||
char *us_udp_packet_buffer_payload(struct us_udp_packet_buffer_t *buf, int index) {
|
||||
return bsd_udp_packet_buffer_payload((struct udp_recvbuf *)buf, index);
|
||||
char *us_udp_packet_buffer_payload(struct us_udp_packet_buffer_t *buf,
|
||||
int index) {
|
||||
return bsd_udp_packet_buffer_payload((struct udp_recvbuf *)buf, index);
|
||||
}
|
||||
|
||||
int us_udp_packet_buffer_payload_length(struct us_udp_packet_buffer_t *buf, int index) {
|
||||
return bsd_udp_packet_buffer_payload_length((struct udp_recvbuf *)buf, index);
|
||||
int us_udp_packet_buffer_payload_length(struct us_udp_packet_buffer_t *buf,
|
||||
int index) {
|
||||
return bsd_udp_packet_buffer_payload_length((struct udp_recvbuf *)buf, index);
|
||||
}
|
||||
|
||||
int us_udp_socket_send(struct us_udp_socket_t *s, void** payloads, size_t* lengths, void** addresses, int num) {
|
||||
if (num == 0) return 0;
|
||||
int fd = us_poll_fd((struct us_poll_t *) s);
|
||||
int us_udp_socket_send(struct us_udp_socket_t *s, void **payloads,
|
||||
size_t *lengths, void **addresses, int num) {
|
||||
if (num == 0)
|
||||
return 0;
|
||||
int fd = us_poll_fd((struct us_poll_t *)s);
|
||||
|
||||
struct udp_sendbuf *buf = (struct udp_sendbuf *)s->loop->data.send_buf;
|
||||
struct udp_sendbuf *buf = (struct udp_sendbuf *)s->loop->data.send_buf;
|
||||
|
||||
int total_sent = 0;
|
||||
while (total_sent < num) {
|
||||
int count = bsd_udp_setup_sendbuf(buf, LIBUS_SEND_BUFFER_LENGTH, payloads, lengths, addresses, num);
|
||||
payloads += count;
|
||||
lengths += count;
|
||||
addresses += count;
|
||||
num -= count;
|
||||
// TODO nohang flag?
|
||||
int sent = bsd_sendmmsg(fd, buf, MSG_DONTWAIT);
|
||||
if (sent < 0) {
|
||||
return sent;
|
||||
}
|
||||
total_sent += sent;
|
||||
if (0 <= sent && sent < num) {
|
||||
// if we couldn't send all packets, register a writable event so we can call the drain callback
|
||||
us_poll_change((struct us_poll_t *) s, s->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
|
||||
}
|
||||
int total_sent = 0;
|
||||
while (total_sent < num) {
|
||||
int count = bsd_udp_setup_sendbuf(buf, LIBUS_SEND_BUFFER_LENGTH, payloads,
|
||||
lengths, addresses, num);
|
||||
payloads += count;
|
||||
lengths += count;
|
||||
addresses += count;
|
||||
num -= count;
|
||||
// TODO nohang flag?
|
||||
int sent = bsd_sendmmsg(fd, buf, MSG_DONTWAIT);
|
||||
if (sent < 0) {
|
||||
return sent;
|
||||
}
|
||||
return total_sent;
|
||||
total_sent += sent;
|
||||
if (0 <= sent && sent < num) {
|
||||
// if we couldn't send all packets, register a writable event so we can
|
||||
// call the drain callback
|
||||
us_poll_change((struct us_poll_t *)s, s->loop,
|
||||
LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
|
||||
}
|
||||
}
|
||||
return total_sent;
|
||||
}
|
||||
|
||||
int us_udp_socket_bound_port(struct us_udp_socket_t *s) {
|
||||
return ((struct us_udp_socket_t *) s)->port;
|
||||
return ((struct us_udp_socket_t *)s)->port;
|
||||
}
|
||||
|
||||
void us_udp_socket_bound_ip(struct us_udp_socket_t *s, char *buf, int *length) {
|
||||
struct bsd_addr_t addr;
|
||||
if (bsd_local_addr(us_poll_fd((struct us_poll_t *)s), &addr) || *length < bsd_addr_get_ip_length(&addr)) {
|
||||
if (bsd_local_addr(us_poll_fd((struct us_poll_t *)s), &addr) ||
|
||||
*length < bsd_addr_get_ip_length(&addr)) {
|
||||
*length = 0;
|
||||
} else {
|
||||
*length = bsd_addr_get_ip_length(&addr);
|
||||
@@ -81,9 +90,11 @@ void us_udp_socket_bound_ip(struct us_udp_socket_t *s, char *buf, int *length) {
|
||||
}
|
||||
}
|
||||
|
||||
void us_udp_socket_remote_ip(struct us_udp_socket_t *s, char *buf, int *length) {
|
||||
void us_udp_socket_remote_ip(struct us_udp_socket_t *s, char *buf,
|
||||
int *length) {
|
||||
struct bsd_addr_t addr;
|
||||
if (bsd_remote_addr(us_poll_fd((struct us_poll_t *)s), &addr) || *length < bsd_addr_get_ip_length(&addr)) {
|
||||
if (bsd_remote_addr(us_poll_fd((struct us_poll_t *)s), &addr) ||
|
||||
*length < bsd_addr_get_ip_length(&addr)) {
|
||||
*length = 0;
|
||||
} else {
|
||||
*length = bsd_addr_get_ip_length(&addr);
|
||||
@@ -92,71 +103,71 @@ void us_udp_socket_remote_ip(struct us_udp_socket_t *s, char *buf, int *length)
|
||||
}
|
||||
|
||||
void *us_udp_socket_user(struct us_udp_socket_t *s) {
|
||||
struct us_udp_socket_t *udp = (struct us_udp_socket_t *) s;
|
||||
struct us_udp_socket_t *udp = (struct us_udp_socket_t *)s;
|
||||
|
||||
return udp->user;
|
||||
return udp->user;
|
||||
}
|
||||
|
||||
void us_udp_socket_close(struct us_udp_socket_t *s) {
|
||||
struct us_loop_t *loop = s->loop;
|
||||
struct us_poll_t *p = (struct us_poll_t *) s;
|
||||
us_poll_stop(p, loop);
|
||||
bsd_close_socket(us_poll_fd(p));
|
||||
s->closed = 1;
|
||||
s->next = loop->data.closed_udp_head;
|
||||
loop->data.closed_udp_head = s;
|
||||
s->on_close(s);
|
||||
struct us_loop_t *loop = s->loop;
|
||||
struct us_poll_t *p = (struct us_poll_t *)s;
|
||||
us_poll_stop(p, loop);
|
||||
bsd_close_socket(us_poll_fd(p));
|
||||
s->closed = 1;
|
||||
s->next = loop->data.closed_udp_head;
|
||||
loop->data.closed_udp_head = s;
|
||||
s->on_close(s);
|
||||
}
|
||||
|
||||
int us_udp_socket_connect(struct us_udp_socket_t *s, const char* host, unsigned short port) {
|
||||
return bsd_connect_udp_socket(us_poll_fd((struct us_poll_t *)s), host, port);
|
||||
int us_udp_socket_connect(struct us_udp_socket_t *s, const char *host,
|
||||
unsigned short port) {
|
||||
return bsd_connect_udp_socket(us_poll_fd((struct us_poll_t *)s), host, port);
|
||||
}
|
||||
|
||||
int us_udp_socket_disconnect(struct us_udp_socket_t *s) {
|
||||
return bsd_disconnect_udp_socket(us_poll_fd((struct us_poll_t *)s));
|
||||
return bsd_disconnect_udp_socket(us_poll_fd((struct us_poll_t *)s));
|
||||
}
|
||||
|
||||
struct us_udp_socket_t *us_create_udp_socket(
|
||||
struct us_loop_t *loop,
|
||||
void (*data_cb)(struct us_udp_socket_t *, void *, int),
|
||||
void (*drain_cb)(struct us_udp_socket_t *),
|
||||
void (*close_cb)(struct us_udp_socket_t *),
|
||||
const char *host,
|
||||
unsigned short port,
|
||||
void *user
|
||||
) {
|
||||
struct us_udp_socket_t *
|
||||
us_create_udp_socket(struct us_loop_t *loop,
|
||||
void (*data_cb)(struct us_udp_socket_t *, void *, int),
|
||||
void (*drain_cb)(struct us_udp_socket_t *),
|
||||
void (*close_cb)(struct us_udp_socket_t *),
|
||||
const char *host, unsigned short port, void *user) {
|
||||
|
||||
LIBUS_SOCKET_DESCRIPTOR fd = bsd_create_udp_socket(host, port);
|
||||
if (fd == LIBUS_SOCKET_ERROR) {
|
||||
return 0;
|
||||
}
|
||||
LIBUS_SOCKET_DESCRIPTOR fd = bsd_create_udp_socket(host, port);
|
||||
if (fd == LIBUS_SOCKET_ERROR) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ext_size = 0;
|
||||
int fallthrough = 0;
|
||||
int ext_size = 0;
|
||||
int fallthrough = 0;
|
||||
|
||||
struct us_poll_t *p = us_create_poll(loop, fallthrough, sizeof(struct us_udp_socket_t) + ext_size);
|
||||
us_poll_init(p, fd, POLL_TYPE_UDP);
|
||||
struct us_poll_t *p = us_create_poll(
|
||||
loop, fallthrough, sizeof(struct us_udp_socket_t) + ext_size);
|
||||
us_poll_init(p, fd, POLL_TYPE_UDP);
|
||||
|
||||
struct us_udp_socket_t *udp = (struct us_udp_socket_t *)p;
|
||||
struct us_udp_socket_t *udp = (struct us_udp_socket_t *)p;
|
||||
|
||||
/* Get and store the port once */
|
||||
struct bsd_addr_t tmp = {0};
|
||||
bsd_local_addr(fd, &tmp);
|
||||
udp->port = bsd_addr_get_port(&tmp);
|
||||
udp->loop = loop;
|
||||
/* Get and store the port once */
|
||||
struct bsd_addr_t tmp = {0};
|
||||
bsd_local_addr(fd, &tmp);
|
||||
udp->port = bsd_addr_get_port(&tmp);
|
||||
udp->loop = loop;
|
||||
|
||||
/* There is no udp socket context, only user data */
|
||||
/* This should really be ext like everything else */
|
||||
udp->user = user;
|
||||
/* There is no udp socket context, only user data */
|
||||
/* This should really be ext like everything else */
|
||||
udp->user = user;
|
||||
|
||||
udp->closed = 0;
|
||||
udp->connected = 0;
|
||||
udp->on_data = data_cb;
|
||||
udp->on_drain = drain_cb;
|
||||
udp->on_close = close_cb;
|
||||
udp->next = NULL;
|
||||
udp->closed = 0;
|
||||
udp->connected = 0;
|
||||
udp->on_data = data_cb;
|
||||
udp->on_drain = drain_cb;
|
||||
udp->on_close = close_cb;
|
||||
udp->next = NULL;
|
||||
|
||||
us_poll_start((struct us_poll_t *) udp, udp->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
|
||||
|
||||
return (struct us_udp_socket_t *) udp;
|
||||
us_poll_start((struct us_poll_t *)udp, udp->loop,
|
||||
LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
|
||||
|
||||
return (struct us_udp_socket_t *)udp;
|
||||
}
|
||||
@@ -19,9 +19,9 @@ add_compile_options(-Wall)
|
||||
if(NOT CMAKE_C_COMPILER_ID MATCHES "tcc")
|
||||
add_compile_options(
|
||||
-fno-strict-aliasing
|
||||
-Wdeclaration-after-statement
|
||||
-Wno-declaration-after-statement
|
||||
-Wpointer-sign
|
||||
-Wsign-compare
|
||||
-Wno-sign-compare
|
||||
-Wunused-result
|
||||
-Wformat-truncation
|
||||
)
|
||||
|
||||
@@ -320,7 +320,8 @@ static JSValue constructBunShell(VM& vm, JSObject* bunObject)
|
||||
|
||||
// This value currently depends on a zig feature flag
|
||||
extern "C" JSC::EncodedJSValue Bun__getTemporaryDevServer(JSC::JSGlobalObject* bunObject);
|
||||
static JSValue constructBunKit(VM& vm, JSObject* bunObject) {
|
||||
static JSValue constructBunKit(VM& vm, JSObject* bunObject)
|
||||
{
|
||||
return JSC::JSValue::decode(Bun__getTemporaryDevServer(bunObject->globalObject()));
|
||||
}
|
||||
|
||||
|
||||
@@ -3030,10 +3030,10 @@ static EncodedJSValue doAsymmetricCipher(JSGlobalObject* globalObject, CallFrame
|
||||
|
||||
if (isTypedArrayTypeIncludingDataView(jsOaepLabelType)) {
|
||||
auto* jsBufferView = jsCast<JSArrayBufferView*>(jsOaepLabelCell);
|
||||
oaepLabel = std::optional<BufferSource::VariantType>{jsBufferView->unsharedImpl()};
|
||||
oaepLabel = std::optional<BufferSource::VariantType> { jsBufferView->unsharedImpl() };
|
||||
} else if (jsOaepLabelType == ArrayBufferType) {
|
||||
auto* jsBuffer = jsDynamicCast<JSArrayBuffer*>(jsOaepLabelCell);
|
||||
oaepLabel = std::optional<BufferSource::VariantType>{jsBuffer->impl()};
|
||||
oaepLabel = std::optional<BufferSource::VariantType> { jsBuffer->impl() };
|
||||
} else {
|
||||
return Bun::throwError(globalObject, scope, Bun::ErrorCode::ERR_INVALID_ARG_TYPE,
|
||||
"expected Buffer or array-like object for oaepLabel"_s);
|
||||
@@ -3066,7 +3066,7 @@ static EncodedJSValue doAsymmetricCipher(JSGlobalObject* globalObject, CallFrame
|
||||
}
|
||||
auto buffer = jsBuffer.releaseReturnValue();
|
||||
|
||||
auto params = CryptoAlgorithmRsaOaepParams{};
|
||||
auto params = CryptoAlgorithmRsaOaepParams {};
|
||||
params.label = oaepLabel;
|
||||
params.padding = padding;
|
||||
const auto& rsaKey = downcast<CryptoKeyRSA>(cryptoKey);
|
||||
@@ -3080,12 +3080,12 @@ static EncodedJSValue doAsymmetricCipher(JSGlobalObject* globalObject, CallFrame
|
||||
return JSValue::encode(WebCore::createBuffer(globalObject, outBuffer));
|
||||
}
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(KeyObject__publicEncrypt, (JSGlobalObject* globalObject, CallFrame* callFrame))
|
||||
JSC_DEFINE_HOST_FUNCTION(KeyObject__publicEncrypt, (JSGlobalObject * globalObject, CallFrame* callFrame))
|
||||
{
|
||||
return doAsymmetricCipher(globalObject, callFrame, true);
|
||||
}
|
||||
|
||||
JSC_DEFINE_HOST_FUNCTION(KeyObject__privateDecrypt, (JSGlobalObject* globalObject, CallFrame* callFrame))
|
||||
JSC_DEFINE_HOST_FUNCTION(KeyObject__privateDecrypt, (JSGlobalObject * globalObject, CallFrame* callFrame))
|
||||
{
|
||||
return doAsymmetricCipher(globalObject, callFrame, false);
|
||||
}
|
||||
|
||||
@@ -4883,7 +4883,7 @@ extern "C" void JSC__VM__getAPILock(JSC::VM* vm)
|
||||
vm->apiLock().lock();
|
||||
}
|
||||
|
||||
extern "C" void JSC__VM__releaseAPILock(JSC::VM* vm)
|
||||
extern "C" void JSC__VM__releaseAPILock(JSC::VM* vm)
|
||||
{
|
||||
// https://github.com/WebKit/WebKit/blob/6cb5017d237ef7cb898582a22f05acca22322845/Source/JavaScriptCore/runtime/JSLock.cpp#L72
|
||||
RefPtr<JSLock> apiLock(&vm->apiLock());
|
||||
|
||||
@@ -2574,7 +2574,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in)
|
||||
indexStack.last()++;
|
||||
goto objectStartVisitMember;
|
||||
}
|
||||
mapStartState : {
|
||||
mapStartState: {
|
||||
ASSERT(inValue.isObject());
|
||||
if (inputObjectStack.size() > maximumFilterRecursion)
|
||||
return SerializationReturnCode::StackOverflowError;
|
||||
@@ -2622,7 +2622,7 @@ SerializationReturnCode CloneSerializer::serialize(JSValue in)
|
||||
goto mapDataStartVisitEntry;
|
||||
}
|
||||
|
||||
setStartState : {
|
||||
setStartState: {
|
||||
ASSERT(inValue.isObject());
|
||||
if (inputObjectStack.size() > maximumFilterRecursion)
|
||||
return SerializationReturnCode::StackOverflowError;
|
||||
@@ -5084,7 +5084,7 @@ DeserializationResult CloneDeserializer::deserialize()
|
||||
propertyNameStack.removeLast();
|
||||
goto objectStartVisitMember;
|
||||
}
|
||||
mapObjectStartState : {
|
||||
mapObjectStartState: {
|
||||
if (outputObjectStack.size() > maximumFilterRecursion)
|
||||
return std::make_pair(JSValue(), SerializationReturnCode::StackOverflowError);
|
||||
JSMap* map = JSMap::create(m_lexicalGlobalObject->vm(), m_globalObject->mapStructure());
|
||||
@@ -5113,7 +5113,7 @@ DeserializationResult CloneDeserializer::deserialize()
|
||||
goto mapDataStartVisitEntry;
|
||||
}
|
||||
|
||||
setObjectStartState : {
|
||||
setObjectStartState: {
|
||||
if (outputObjectStack.size() > maximumFilterRecursion)
|
||||
return std::make_pair(JSValue(), SerializationReturnCode::StackOverflowError);
|
||||
JSSet* set = JSSet::create(m_lexicalGlobalObject->vm(), m_globalObject->setStructure());
|
||||
|
||||
@@ -11,7 +11,8 @@ void generateNativeModule_BunObject(JSC::JSGlobalObject *lexicalGlobalObject,
|
||||
JSC::MarkedArgumentBuffer &exportValues) {
|
||||
// FIXME: this does not add each property as a top level export
|
||||
JSC::VM &vm = lexicalGlobalObject->vm();
|
||||
Zig::GlobalObject *globalObject = jsCast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||
Zig::GlobalObject *globalObject =
|
||||
jsCast<Zig::GlobalObject *>(lexicalGlobalObject);
|
||||
|
||||
JSObject *object = globalObject->bunObject();
|
||||
|
||||
|
||||
@@ -18,24 +18,25 @@ extern "C" mach_port_t io_darwin_create_machport(uint64_t wakeup, int32_t fd,
|
||||
kern_return_t kr = mach_port_allocate(self, MACH_PORT_RIGHT_RECEIVE, &port);
|
||||
|
||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Insert a send right into the port since we also use this to send
|
||||
kr = mach_port_insert_right(self, port, port, MACH_MSG_TYPE_MAKE_SEND);
|
||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Modify the port queue size to be 1 because we are only
|
||||
// using it for notifications and not for any other purpose.
|
||||
mach_port_limits_t limits = { .mpl_qlimit = 1 };
|
||||
kr = mach_port_set_attributes(self, port, MACH_PORT_LIMITS_INFO, (mach_port_info_t)&limits, MACH_PORT_LIMITS_INFO_COUNT);
|
||||
|
||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||
return 0;
|
||||
}
|
||||
mach_port_limits_t limits = {.mpl_qlimit = 1};
|
||||
kr = mach_port_set_attributes(self, port, MACH_PORT_LIMITS_INFO,
|
||||
(mach_port_info_t)&limits,
|
||||
MACH_PORT_LIMITS_INFO_COUNT);
|
||||
|
||||
if (UNLIKELY(kr != KERN_SUCCESS)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Configure the event to directly receive the Mach message as part of the
|
||||
// kevent64() call.
|
||||
@@ -85,37 +86,32 @@ extern "C" bool io_darwin_schedule_wakeup(mach_port_t waker) {
|
||||
.msgh_id = 0,
|
||||
};
|
||||
|
||||
mach_msg_return_t kr = mach_msg(
|
||||
&msg,
|
||||
MACH_SEND_MSG | MACH_SEND_TIMEOUT,
|
||||
msg.msgh_size,
|
||||
0,
|
||||
MACH_PORT_NULL,
|
||||
0, // Fail instantly if the port is full
|
||||
MACH_PORT_NULL
|
||||
);
|
||||
|
||||
switch (kr) {
|
||||
case MACH_MSG_SUCCESS: {
|
||||
return true;
|
||||
}
|
||||
|
||||
// This means that the send would've blocked because the
|
||||
// queue is full. We assume success because the port is full.
|
||||
case MACH_SEND_TIMED_OUT: {
|
||||
return true;
|
||||
}
|
||||
mach_msg_return_t kr = mach_msg(&msg, MACH_SEND_MSG | MACH_SEND_TIMEOUT,
|
||||
msg.msgh_size, 0, MACH_PORT_NULL,
|
||||
0, // Fail instantly if the port is full
|
||||
MACH_PORT_NULL);
|
||||
|
||||
// No space means it will wake up.
|
||||
case MACH_SEND_NO_BUFFER: {
|
||||
return true;
|
||||
}
|
||||
switch (kr) {
|
||||
case MACH_MSG_SUCCESS: {
|
||||
return true;
|
||||
}
|
||||
|
||||
default: {
|
||||
ASSERT_NOT_REACHED_WITH_MESSAGE("mach_msg failed with %x", kr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// This means that the send would've blocked because the
|
||||
// queue is full. We assume success because the port is full.
|
||||
case MACH_SEND_TIMED_OUT: {
|
||||
return true;
|
||||
}
|
||||
|
||||
// No space means it will wake up.
|
||||
case MACH_SEND_NO_BUFFER: {
|
||||
return true;
|
||||
}
|
||||
|
||||
default: {
|
||||
ASSERT_NOT_REACHED_WITH_MESSAGE("mach_msg failed with %x", kr);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -1,82 +1,89 @@
|
||||
#include "KitDevGlobalObject.h"
|
||||
#include "JavaScriptCore/GlobalObjectMethodTable.h"
|
||||
#include "JSNextTickQueue.h"
|
||||
#include "JavaScriptCore/GlobalObjectMethodTable.h"
|
||||
#include "headers-handwritten.h"
|
||||
|
||||
namespace Kit {
|
||||
|
||||
#define INHERIT_HOOK_METHOD(name) Zig::GlobalObject::s_globalObjectMethodTable. name
|
||||
#define INHERIT_HOOK_METHOD(name) \
|
||||
Zig::GlobalObject::s_globalObjectMethodTable.name
|
||||
|
||||
const JSC::GlobalObjectMethodTable DevGlobalObject::s_globalObjectMethodTable = {
|
||||
INHERIT_HOOK_METHOD(supportsRichSourceInfo),
|
||||
INHERIT_HOOK_METHOD(shouldInterruptScript),
|
||||
INHERIT_HOOK_METHOD(javaScriptRuntimeFlags),
|
||||
INHERIT_HOOK_METHOD(queueMicrotaskToEventLoop),
|
||||
INHERIT_HOOK_METHOD(shouldInterruptScriptBeforeTimeout),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderImportModule),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderResolve),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderFetch),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderCreateImportMetaProperties),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderEvaluate),
|
||||
INHERIT_HOOK_METHOD(promiseRejectionTracker),
|
||||
INHERIT_HOOK_METHOD(reportUncaughtExceptionAtEventLoop),
|
||||
INHERIT_HOOK_METHOD(currentScriptExecutionOwner),
|
||||
INHERIT_HOOK_METHOD(scriptExecutionStatus),
|
||||
INHERIT_HOOK_METHOD(reportViolationForUnsafeEval),
|
||||
INHERIT_HOOK_METHOD(defaultLanguage),
|
||||
INHERIT_HOOK_METHOD(compileStreaming),
|
||||
INHERIT_HOOK_METHOD(instantiateStreaming),
|
||||
INHERIT_HOOK_METHOD(deriveShadowRealmGlobalObject),
|
||||
INHERIT_HOOK_METHOD(codeForEval),
|
||||
INHERIT_HOOK_METHOD(canCompileStrings),
|
||||
const JSC::GlobalObjectMethodTable DevGlobalObject::s_globalObjectMethodTable =
|
||||
{
|
||||
INHERIT_HOOK_METHOD(supportsRichSourceInfo),
|
||||
INHERIT_HOOK_METHOD(shouldInterruptScript),
|
||||
INHERIT_HOOK_METHOD(javaScriptRuntimeFlags),
|
||||
INHERIT_HOOK_METHOD(queueMicrotaskToEventLoop),
|
||||
INHERIT_HOOK_METHOD(shouldInterruptScriptBeforeTimeout),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderImportModule),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderResolve),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderFetch),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderCreateImportMetaProperties),
|
||||
INHERIT_HOOK_METHOD(moduleLoaderEvaluate),
|
||||
INHERIT_HOOK_METHOD(promiseRejectionTracker),
|
||||
INHERIT_HOOK_METHOD(reportUncaughtExceptionAtEventLoop),
|
||||
INHERIT_HOOK_METHOD(currentScriptExecutionOwner),
|
||||
INHERIT_HOOK_METHOD(scriptExecutionStatus),
|
||||
INHERIT_HOOK_METHOD(reportViolationForUnsafeEval),
|
||||
INHERIT_HOOK_METHOD(defaultLanguage),
|
||||
INHERIT_HOOK_METHOD(compileStreaming),
|
||||
INHERIT_HOOK_METHOD(instantiateStreaming),
|
||||
INHERIT_HOOK_METHOD(deriveShadowRealmGlobalObject),
|
||||
INHERIT_HOOK_METHOD(codeForEval),
|
||||
INHERIT_HOOK_METHOD(canCompileStrings),
|
||||
};
|
||||
|
||||
DevGlobalObject* DevGlobalObject::create(JSC::VM& vm, JSC::Structure* structure, const JSC::GlobalObjectMethodTable* methodTable)
|
||||
{
|
||||
DevGlobalObject* ptr = new (NotNull, JSC::allocateCell<DevGlobalObject>(vm)) DevGlobalObject(vm, structure, methodTable);
|
||||
ptr->finishCreation(vm);
|
||||
return ptr;
|
||||
DevGlobalObject *
|
||||
DevGlobalObject::create(JSC::VM &vm, JSC::Structure *structure,
|
||||
const JSC::GlobalObjectMethodTable *methodTable) {
|
||||
DevGlobalObject *ptr = new (NotNull, JSC::allocateCell<DevGlobalObject>(vm))
|
||||
DevGlobalObject(vm, structure, methodTable);
|
||||
ptr->finishCreation(vm);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void DevGlobalObject::finishCreation(JSC::VM &vm) {
|
||||
Base::finishCreation(vm);
|
||||
ASSERT(inherits(info()));
|
||||
Base::finishCreation(vm);
|
||||
ASSERT(inherits(info()));
|
||||
}
|
||||
|
||||
extern "C" BunVirtualMachine* Bun__getVM();
|
||||
extern "C" BunVirtualMachine *Bun__getVM();
|
||||
|
||||
// A lot of this function is taken from 'Zig__GlobalObject__create'
|
||||
extern "C" DevGlobalObject* KitCreateDevGlobal(DevServer* owner, void* console) {
|
||||
JSC::VM& vm = JSC::VM::create(JSC::HeapType::Large).leakRef();
|
||||
vm.heap.acquireAccess();
|
||||
JSC::JSLockHolder locker(vm);
|
||||
BunVirtualMachine* bunVM = Bun__getVM();
|
||||
WebCore::JSVMClientData::create(&vm, bunVM);
|
||||
extern "C" DevGlobalObject *KitCreateDevGlobal(DevServer *owner,
|
||||
void *console) {
|
||||
JSC::VM &vm = JSC::VM::create(JSC::HeapType::Large).leakRef();
|
||||
vm.heap.acquireAccess();
|
||||
JSC::JSLockHolder locker(vm);
|
||||
BunVirtualMachine *bunVM = Bun__getVM();
|
||||
WebCore::JSVMClientData::create(&vm, bunVM);
|
||||
|
||||
JSC::Structure* structure = DevGlobalObject::createStructure(vm);
|
||||
DevGlobalObject* global = DevGlobalObject::create(vm, structure, &DevGlobalObject::s_globalObjectMethodTable);
|
||||
if (!global)
|
||||
BUN_PANIC("Failed to create DevGlobalObject");
|
||||
JSC::Structure *structure = DevGlobalObject::createStructure(vm);
|
||||
DevGlobalObject *global = DevGlobalObject::create(
|
||||
vm, structure, &DevGlobalObject::s_globalObjectMethodTable);
|
||||
if (!global)
|
||||
BUN_PANIC("Failed to create DevGlobalObject");
|
||||
|
||||
global->m_devServer = owner;
|
||||
global->m_bunVM = bunVM;
|
||||
global->m_devServer = owner;
|
||||
global->m_bunVM = bunVM;
|
||||
|
||||
JSC::gcProtect(global);
|
||||
JSC::gcProtect(global);
|
||||
|
||||
global->setConsole(console);
|
||||
global->setStackTraceLimit(10); // Node.js defaults to 10
|
||||
global->setConsole(console);
|
||||
global->setStackTraceLimit(10); // Node.js defaults to 10
|
||||
|
||||
// vm.setOnComputeErrorInfo(computeErrorInfoWrapper);
|
||||
vm.setOnEachMicrotaskTick([global](JSC::VM& vm) -> void {
|
||||
if (auto nextTickQueue = global->m_nextTickQueue.get()) {
|
||||
global->resetOnEachMicrotaskTick();
|
||||
Bun::JSNextTickQueue* queue = jsCast<Bun::JSNextTickQueue*>(nextTickQueue);
|
||||
queue->drain(vm, global);
|
||||
return;
|
||||
}
|
||||
});
|
||||
// vm.setOnComputeErrorInfo(computeErrorInfoWrapper);
|
||||
vm.setOnEachMicrotaskTick([global](JSC::VM &vm) -> void {
|
||||
if (auto nextTickQueue = global->m_nextTickQueue.get()) {
|
||||
global->resetOnEachMicrotaskTick();
|
||||
Bun::JSNextTickQueue *queue =
|
||||
jsCast<Bun::JSNextTickQueue *>(nextTickQueue);
|
||||
queue->drain(vm, global);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
return global;
|
||||
return global;
|
||||
}
|
||||
|
||||
}; // namespace Kit
|
||||
|
||||
Reference in New Issue
Block a user