mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
asdfasfdafdsafda
This commit is contained in:
177
CMakeLists.txt
177
CMakeLists.txt
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.25)
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
cmake_policy(SET CMP0091 NEW)
|
||||
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
||||
|
||||
@@ -47,9 +47,9 @@ if(UNIX)
|
||||
message(FATAL_ERROR "Could not find LLVM ${LLVM_VERSION} installed on your system.")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_COMPILER "${LLVM_PREFIX}/bin/clang++")
|
||||
set(CMAKE_C_COMPILER "${LLVM_PREFIX}/bin/clang")
|
||||
set(CMAKE_CXX_COMPILER_ID "Clang")
|
||||
set(CMAKE_CXX_COMPILER "${LLVM_PREFIX}/bin/clang++" CACHE STRING "CMAKE_CXX_COMPILER" FORCE)
|
||||
set(CMAKE_C_COMPILER "${LLVM_PREFIX}/bin/clang" CACHE STRING "CMAKE_C_COMPILER" FORCE)
|
||||
set(CMAKE_CXX_COMPILER_ID "Clang" CACHE STRING "CMAKE_CXX_COMPILER_ID" FORCE)
|
||||
set(STRIP "${LLVM_PREFIX}/bin/llvm-strip")
|
||||
set(DSYMUTIL "${LLVM_PREFIX}/bin/dsymutil")
|
||||
|
||||
@@ -65,14 +65,19 @@ set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
project(Bun VERSION "1.0.7")
|
||||
|
||||
set(DEFAULT_ON_UNLESS_WINDOWS ON)
|
||||
if (WIN32)
|
||||
if(WIN32)
|
||||
set(DEFAULT_ON_UNLESS_WINDOWS OFF)
|
||||
endif()
|
||||
set(DEFAULT_ON_UNLESS_APPLE ON)
|
||||
if (APPLE)
|
||||
if(APPLE)
|
||||
set(DEFAULT_ON_UNLESS_APPLE OFF)
|
||||
endif()
|
||||
|
||||
set(CI OFF)
|
||||
if(DEFINED ENV{CI} OR DEFINED ENV{GITHUB_ACTIONS})
|
||||
set(CI ON)
|
||||
endif()
|
||||
|
||||
# -- Build Flags --
|
||||
option(USE_STATIC_SQLITE "Statically link SQLite?" ${DEFAULT_ON_UNLESS_APPLE})
|
||||
option(USE_CUSTOM_ZLIB "Use Bun's recommended version of zlib" ${DEFAULT_ON_UNLESS_WINDOWS})
|
||||
@@ -90,7 +95,7 @@ option(USE_BASELINE_BUILD "Build Bun for baseline (older) CPUs" OFF)
|
||||
set(ERROR_LIMIT 100 CACHE STRING "Maximum number of errors to show when compiling C++ code")
|
||||
|
||||
set(ARCH x86_64)
|
||||
if (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm")
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm")
|
||||
set(ARCH arm64)
|
||||
endif()
|
||||
|
||||
@@ -100,7 +105,7 @@ if(NOT CPU_TARGET)
|
||||
if (NOT MSVC)
|
||||
if (USE_BASELINE_BUILD)
|
||||
set(CPU_TARGET "nehalem")
|
||||
else ()
|
||||
else()
|
||||
set(CPU_TARGET "haswell")
|
||||
endif()
|
||||
endif()
|
||||
@@ -113,6 +118,7 @@ if(USE_CONFIGURE_DEPENDS)
|
||||
else()
|
||||
set(CONFIGURE_DEPENDS "")
|
||||
endif()
|
||||
|
||||
# --- CLI Paths ---
|
||||
|
||||
# Zig Compiler
|
||||
@@ -151,7 +157,7 @@ endif()
|
||||
# --- Dependencies ---
|
||||
|
||||
# WebKit
|
||||
if(NOT WEBKIT_DIR)
|
||||
if(NOT WEBKIT_DIR AND NOT WINDOWS)
|
||||
# TODO: allow this to point to the actual webkit cmake file to allow easier rebuilds
|
||||
find_path(
|
||||
WEBKIT_DIR
|
||||
@@ -218,7 +224,7 @@ file(GLOB BUN_CPP ${CONFIGURE_DEPENDS}
|
||||
"${BUN_SRC}/io/*.cpp"
|
||||
"${BUN_SRC}/bun.js/modules/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/WebCore/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/webcore/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/sqlite/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/webcrypto/*.cpp"
|
||||
"${BUN_SRC}/bun.js/bindings/webcrypto/*/*.cpp"
|
||||
@@ -447,11 +453,10 @@ set_target_properties(${bun} PROPERTIES
|
||||
)
|
||||
|
||||
# Set /subsystem:console on bun for windows
|
||||
if (WIN32)
|
||||
if(WIN32)
|
||||
set_target_properties(${bun} PROPERTIES LINK_FLAGS " /SUBSYSTEM:CONSOLE ")
|
||||
endif()
|
||||
|
||||
# --- Flags and Defines ---
|
||||
add_compile_definitions(
|
||||
# TODO: are all of these variables strictly necessary?
|
||||
"_HAS_EXCEPTIONS=0"
|
||||
@@ -473,6 +478,7 @@ add_compile_definitions(
|
||||
"ASSERT_ENABLED=$<IF:$<CONFIG:ASSERT_ENABLED>,1,0>"
|
||||
"BUN_DYNAMIC_JS_LOAD_PATH=\"${BUN_WORKDIR}/js\""
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/packages/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets
|
||||
@@ -498,7 +504,7 @@ include_directories(
|
||||
"${BUN_WORKDIR}/codegen"
|
||||
)
|
||||
|
||||
# Compile and Linker Flags
|
||||
# --- clang and linker flags ---
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_compile_definitions("BUN_DEBUG=1")
|
||||
if (NOT MSVC)
|
||||
@@ -515,6 +521,10 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
if(NOT CI)
|
||||
target_compile_options(${bun} PRIVATE -fdiagnostics-color=always)
|
||||
endif()
|
||||
|
||||
target_compile_options(${bun} PUBLIC
|
||||
-march=${CPU_TARGET}
|
||||
-mtune=${CPU_TARGET}
|
||||
@@ -526,6 +536,8 @@ if(NOT MSVC)
|
||||
-fno-rtti
|
||||
-ferror-limit=${ERROR_LIMIT}
|
||||
-fPIC
|
||||
-fno-omit-frame-pointer
|
||||
-fno-semantic-interposition
|
||||
)
|
||||
else() # MSVC
|
||||
string(APPEND SUPPRESS_WARNING_NUMBERS
|
||||
@@ -549,22 +561,71 @@ if(APPLE)
|
||||
target_link_options(${bun} PUBLIC "-dead_strip")
|
||||
target_link_options(${bun} PUBLIC "-dead_strip_dylibs")
|
||||
target_link_options(${bun} PUBLIC "-exported_symbols_list" "${BUN_SRC}/symbols.txt")
|
||||
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/symbols.txt")
|
||||
|
||||
target_link_options(${bun} PUBLIC "-fno-keep-static-consts")
|
||||
target_link_libraries(${bun} PRIVATE "resolv")
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
if(UNIX AND NOT APPLE)
|
||||
target_compile_options(${bun} PUBLIC
|
||||
-std=c++2a
|
||||
)
|
||||
target_link_options(${bun} PUBLIC
|
||||
"-static-libstdc++"
|
||||
"-static-libgcc"
|
||||
"-fuse-ld=lld"
|
||||
"-Wl,-z,now"
|
||||
"-Wl,--as-needed"
|
||||
"-Wl,--gc-sections"
|
||||
"-Wl,-z,stack-size=12800000"
|
||||
"-Wl,--wrap=fcntl"
|
||||
"-Wl,--wrap=fcntl64"
|
||||
"-Wl,--wrap=stat64"
|
||||
"-Wl,--wrap=pow"
|
||||
"-Wl,--wrap=exp"
|
||||
"-Wl,--wrap=log"
|
||||
"-Wl,--wrap=log2"
|
||||
"-Wl,--wrap=lstat"
|
||||
"-Wl,--wrap=stat"
|
||||
"-Wl,--wrap=fstat"
|
||||
"-Wl,--wrap=fstatat"
|
||||
"-Wl,--wrap=lstat64"
|
||||
"-Wl,--wrap=stat64"
|
||||
"-Wl,--wrap=fstat64"
|
||||
"-Wl,--wrap=fstatat64"
|
||||
"-Wl,--wrap=mknod"
|
||||
"-Wl,--wrap=mknodat"
|
||||
"-Wl,--wrap=statx "
|
||||
"-Wl,--compress-debug-sections=zlib"
|
||||
"-Bsymbolics-functions"
|
||||
"-rdynamic"
|
||||
"-Wl,--dynamic-list=${BUN_SRC}/symbols.dyn"
|
||||
"-Wl,--version-script=${BUN_SRC}/linker.lds"
|
||||
)
|
||||
target_link_libraries(${bun} PRIVATE "c")
|
||||
target_link_libraries(${bun} PRIVATE "libatomic.a")
|
||||
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libicudata.a")
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libicui18n.a")
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libicuuc.a")
|
||||
|
||||
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/linker.lds")
|
||||
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/symbols.dyn")
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_compile_definitions(
|
||||
"WIN32"
|
||||
"_WINDOWS"
|
||||
"_CRT_SECURE_NO_WARNINGS"
|
||||
"WIN32_LEAN_AND_MEAN=1"
|
||||
)
|
||||
|
||||
|
||||
set_property(TARGET ${bun} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
if(APPLE)
|
||||
# TODO: a much better check can be done to find this path
|
||||
find_path(
|
||||
ICU4C_DIR NAMES lib/libicudata.a
|
||||
@@ -581,38 +642,6 @@ if (APPLE)
|
||||
target_link_libraries(${bun} PRIVATE "${ICU4C_DIR}/lib/libicui18n.a")
|
||||
target_link_libraries(${bun} PRIVATE "${ICU4C_DIR}/lib/libicuuc.a")
|
||||
include_directories(${ICU4C_DIR}/include)
|
||||
elseif (LINUX)
|
||||
string(APPEND CMAKE_CXX_FLAGS " -static-libstdc++ -static-libgcc -fno-omit-frame-pointer")
|
||||
string(APPEND CMAKE_C_FLAGS " -static-libgcc -fno-omit-frame-pointer")
|
||||
target_link_libraries(${bun} PRIVATE "c")
|
||||
string(APPEND CMAKE_LINKER_FLAGS
|
||||
" -Wl,--compress-debug-sections=zlib "
|
||||
" -l:libatomic.a "
|
||||
" -Wl,-Bsymbolics-functions "
|
||||
" -fno-semantic-interposition "
|
||||
" -Wl,-z,now"
|
||||
" -Wl,--as-needed"
|
||||
" -Wl,--gc-sections"
|
||||
" -Wl,-z,-stack-size=12800000"
|
||||
" -Wl,--wrap=fcntl"
|
||||
" -Wl,--wrap=fcntl64"
|
||||
" -Wl,--wrap=stat64"
|
||||
" -Wl,--wrap=pow"
|
||||
" -Wl,--wrap=exp"
|
||||
" -Wl,--wrap=log"
|
||||
" -Wl,--wrap=log2"
|
||||
" -Wl,--wrap=lstat"
|
||||
" -Wl,--wrap=stat"
|
||||
" -Wl,--wrap=fstat"
|
||||
" -Wl,--wrap=fstatat"
|
||||
" -Wl,--wrap=lstat64"
|
||||
" -Wl,--wrap=stat64"
|
||||
" -Wl,--wrap=fstat64"
|
||||
" -Wl,--wrap=fstatat64"
|
||||
" -Wl,--wrap=mknod"
|
||||
" -Wl,--wrap=mknodat"
|
||||
" -Wl,--wrap=statx "
|
||||
)
|
||||
endif()
|
||||
|
||||
# --- Stripped Binary "bun"
|
||||
@@ -633,15 +662,15 @@ endif()
|
||||
|
||||
# --- Dependencies ---
|
||||
|
||||
if (USE_CUSTOM_ZLIB AND (NOT WIN32))
|
||||
if(USE_CUSTOM_ZLIB AND (NOT WIN32))
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libz.a")
|
||||
include_directories(${BUN_DEPS_DIR}/zlib/include)
|
||||
else ()
|
||||
else()
|
||||
find_package(ZLIB REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE ZLIB::ZLIB)
|
||||
endif ()
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_BORINGSSL)
|
||||
if(USE_CUSTOM_BORINGSSL)
|
||||
include_directories(src/deps/boringssl/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/crypto.lib")
|
||||
@@ -652,48 +681,52 @@ if (USE_CUSTOM_BORINGSSL)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libssl.a")
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libdecrepit.a")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
include(FindBoringSSL)
|
||||
FindBoringSSL(${bun})
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_LIBARCHIVE)
|
||||
if(USE_CUSTOM_LIBARCHIVE)
|
||||
include_directories(src/deps/libarchive/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/archive.lib")
|
||||
else()
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libarchive.a")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
find_package(LibArchive REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE LibArchive::LibArchive)
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_MIMALLOC)
|
||||
if(USE_CUSTOM_MIMALLOC)
|
||||
include_directories(src/deps/mimalloc/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/mimalloc-static.lib")
|
||||
else()
|
||||
elseif(APPLE)
|
||||
# https://github.com/microsoft/mimalloc/issues/512
|
||||
# Linking mimalloc via object file on macOS x64 can cause heap corruption
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libmimalloc.a")
|
||||
else()
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libmimalloc.o")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
find_package(mimalloc REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE mimalloc)
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_ZSTD)
|
||||
if(USE_CUSTOM_ZSTD)
|
||||
include_directories(src/deps/zstd/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/zstd.lib")
|
||||
else()
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libzstd.a")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
find_package(zstd CONFIG REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE zstd::libzstd)
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_CARES)
|
||||
if(USE_CUSTOM_CARES)
|
||||
include_directories(src/deps/c-ares/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/cares.lib")
|
||||
@@ -705,7 +738,7 @@ else()
|
||||
target_link_libraries(${bun} PRIVATE c-ares::cares)
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_BASE64)
|
||||
if(USE_CUSTOM_BASE64)
|
||||
include_directories(src/deps/base64/include)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/base64.lib")
|
||||
@@ -714,47 +747,47 @@ if (USE_CUSTOM_BASE64)
|
||||
endif()
|
||||
else()
|
||||
find_package(base64 REQUIRED)
|
||||
target_link_libraries(bun PRIVATE base64::base64)
|
||||
target_link_libraries(${bun} PRIVATE base64::base64)
|
||||
endif()
|
||||
|
||||
if (NOT WIN32)
|
||||
if(NOT WIN32)
|
||||
if (USE_CUSTOM_TINYCC)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/tcc.lib")
|
||||
else()
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libtcc.a")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
find_package(tinycc REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE tinycc::tinycc)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (USE_CUSTOM_LOLHTML)
|
||||
if(USE_CUSTOM_LOLHTML)
|
||||
if (WIN32)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/lolhtml.lib")
|
||||
else()
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/liblolhtml.a")
|
||||
endif()
|
||||
else ()
|
||||
else()
|
||||
find_package(lolhtml REQUIRED)
|
||||
target_link_libraries(${bun} PRIVATE lolhtml::lolhtml)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
if(WIN32)
|
||||
if (USE_CUSTOM_LIBUV)
|
||||
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/uv.lib")
|
||||
else ()
|
||||
else()
|
||||
find_package(libuv CONFIG REQUIRED )
|
||||
target_link_libraries(${bun} PRIVATE $<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>)
|
||||
endif()
|
||||
message(STATUS "Found libuv: ${libuv_LIBRARIES}")
|
||||
endif()
|
||||
|
||||
if (USE_STATIC_SQLITE)
|
||||
if(USE_STATIC_SQLITE)
|
||||
add_library(sqlite3 STATIC src/bun.js/bindings/sqlite/sqlite3.c)
|
||||
target_include_directories(sqlite3 PUBLIC src/bun.js/bindings/sqlite)
|
||||
target_link_libraries(bun PRIVATE sqlite3)
|
||||
target_link_libraries(${bun} PRIVATE sqlite3)
|
||||
message(STATUS "Using static sqlite3")
|
||||
target_compile_definitions(${bun} PRIVATE "LAZY_LOAD_SQLITE=0")
|
||||
else()
|
||||
@@ -762,7 +795,7 @@ else()
|
||||
target_compile_definitions(${bun} PRIVATE "LAZY_LOAD_SQLITE=1")
|
||||
endif()
|
||||
|
||||
if (NOT MSVC)
|
||||
if(NOT MSVC)
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libWTF.a")
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libJavaScriptCore.a")
|
||||
target_link_libraries(${bun} PRIVATE "${WEBKIT_DIR}/lib/libbmalloc.a")
|
||||
|
||||
6
Makefile
6
Makefile
@@ -375,9 +375,7 @@ ICU_FLAGS ?=
|
||||
# Ideally, we could just look up the linker search paths
|
||||
ifeq ($(OS_NAME),linux)
|
||||
LIB_ICU_PATH ?= $(JSC_LIB)
|
||||
ICU_FLAGS += $(LIB_ICU_PATH)/libicuuc.a $(LIB_ICU_PATH)/libicudata.a $(LIB_ICU_PATH)/libicui18n.a
|
||||
else
|
||||
LIB_ICU_PATH ?= $(BUN_DEPS_DIR)
|
||||
ICU_FLAGS += $(LIB_ICU_PATH)/libicuuc.a $(LIB_ICU_PATH)/libicudata.a $(LIB_ICU_PATH)/libicui18n.a
|
||||
endif
|
||||
|
||||
ifeq ($(OS_NAME),darwin)
|
||||
@@ -1954,4 +1952,4 @@ help: ## to print this help
|
||||
|
||||
|
||||
print_linker_flags:
|
||||
echo $(BUN_LLD_FLAGS) $(SYMBOLS) -W $(OPTIMIZATION_LEVEL) $(RELEASE_FLAGS)
|
||||
@echo $(CLANG_FLAGS)
|
||||
|
||||
7
goals
7
goals
@@ -1,7 +0,0 @@
|
||||
runtime_js fallback_decoder bun_error node-fallbacks
|
||||
|
||||
release-bindings
|
||||
build-obj
|
||||
bun-link-lld-release
|
||||
bun-link-lld-release-dsym
|
||||
release-bin-entitlements
|
||||
@@ -15,8 +15,8 @@
|
||||
},
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "cmake . -G Ninja -B build && time ninja -C build",
|
||||
"build:release": "cmake . -DCMAKE_BUILD_TYPE=Release -G Ninja -B build-release && time ninja -C build-release",
|
||||
"build": "cmake . -DCMAKE_BUILD_TYPE=Debug -GNinja -Bbuild && ninja -Cbuild",
|
||||
"build:release": "cmake . -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-release && ninja -Cbuild-release",
|
||||
"build-runtime": "esbuild --target=esnext --bundle src/runtime/index.ts --format=iife --platform=browser --global-name=BUN_RUNTIME > src/runtime.out.js; cat src/runtime.footer.js >> src/runtime.out.js",
|
||||
"build-fallback": "esbuild --target=esnext --bundle src/fallback.ts --format=iife --platform=browser --minify > src/fallback.out.js",
|
||||
"postinstall": "bash .scripts/postinstall.sh",
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "root.h"
|
||||
#include "ZigGlobalObject.h"
|
||||
#include "AsyncContextFrame.h"
|
||||
|
||||
@@ -3,6 +3,7 @@ import { unlinkSync } from "fs";
|
||||
import { readdirSync } from "fs";
|
||||
import { resolve } from "path";
|
||||
import type { Field, ClassDefinition } from "./class-definitions";
|
||||
import { writeIfNotChanged } from "./helpers";
|
||||
|
||||
const CommonIdentifiers = {
|
||||
"name": true,
|
||||
@@ -1709,13 +1710,6 @@ for (const file of files) {
|
||||
}
|
||||
classes.sort((a, b) => (a.name < b.name ? -1 : 1));
|
||||
|
||||
function writeAndUnlink(path, content) {
|
||||
try {
|
||||
unlinkSync(path);
|
||||
} catch (e) {}
|
||||
return Bun.write(path, content);
|
||||
}
|
||||
|
||||
const GENERATED_CLASSES_FOOTER = `
|
||||
|
||||
class StructuredCloneableSerialize {
|
||||
@@ -1791,7 +1785,7 @@ function writeCppSerializers() {
|
||||
return output;
|
||||
}
|
||||
|
||||
await writeAndUnlink(`${outBase}/ZigGeneratedClasses.zig`, [
|
||||
await writeIfNotChanged(`${outBase}/ZigGeneratedClasses.zig`, [
|
||||
ZIG_GENERATED_CLASSES_HEADER,
|
||||
|
||||
...classes.map(a => generateZig(a.name, a).trim()).join("\n"),
|
||||
@@ -1804,25 +1798,25 @@ comptime {
|
||||
`,
|
||||
]);
|
||||
const allHeaders = classes.map(a => generateHeader(a.name, a));
|
||||
await writeAndUnlink(`${outBase}/ZigGeneratedClasses.h`, [
|
||||
await writeIfNotChanged(`${outBase}/ZigGeneratedClasses.h`, [
|
||||
GENERATED_CLASSES_HEADER[0],
|
||||
...[...new Set(extraIncludes.map(a => `#include "${a}";` + "\n"))],
|
||||
GENERATED_CLASSES_HEADER[1],
|
||||
...allHeaders,
|
||||
GENERATED_CLASSES_FOOTER,
|
||||
]);
|
||||
await writeAndUnlink(`${outBase}/ZigGeneratedClasses.cpp`, [
|
||||
await writeIfNotChanged(`${outBase}/ZigGeneratedClasses.cpp`, [
|
||||
GENERATED_CLASSES_IMPL_HEADER,
|
||||
...classes.map(a => generateImpl(a.name, a)),
|
||||
writeCppSerializers(classes),
|
||||
GENERATED_CLASSES_IMPL_FOOTER,
|
||||
]);
|
||||
await writeAndUnlink(
|
||||
await writeIfNotChanged(
|
||||
`${outBase}/ZigGeneratedClasses+lazyStructureHeader.h`,
|
||||
classes.map(a => generateLazyClassStructureHeader(a.name, a)).join("\n"),
|
||||
);
|
||||
|
||||
await writeAndUnlink(
|
||||
await writeIfNotChanged(
|
||||
`${outBase}/ZigGeneratedClasses+DOMClientIsoSubspaces.h`,
|
||||
classes.map(a =>
|
||||
[
|
||||
@@ -1832,7 +1826,7 @@ await writeAndUnlink(
|
||||
),
|
||||
);
|
||||
|
||||
await writeAndUnlink(
|
||||
await writeIfNotChanged(
|
||||
`${outBase}/ZigGeneratedClasses+DOMIsoSubspaces.h`,
|
||||
classes.map(a =>
|
||||
[
|
||||
@@ -1842,9 +1836,7 @@ await writeAndUnlink(
|
||||
),
|
||||
);
|
||||
|
||||
await writeAndUnlink(
|
||||
await writeIfNotChanged(
|
||||
`${outBase}/ZigGeneratedClasses+lazyStructureImpl.h`,
|
||||
initLazyClasses(classes.map(a => generateLazyClassStructureImpl(a.name, a))) + "\n" + visitLazyClasses(classes),
|
||||
);
|
||||
|
||||
export {};
|
||||
|
||||
@@ -60,5 +60,10 @@ export function writeIfNotChanged(file: string, contents: string) {
|
||||
}
|
||||
}
|
||||
|
||||
fs.writeFileSync(file, contents);
|
||||
try {
|
||||
fs.writeFileSync(file, contents);
|
||||
} catch (error) {
|
||||
fs.mkdirSync(path.dirname(file));
|
||||
fs.writeFileSync(file, contents);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user