mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
try using LLVM 18 on macOS (#12727)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
This commit is contained in:
43
.github/workflows/build-darwin.yml
vendored
43
.github/workflows/build-darwin.yml
vendored
@@ -27,11 +27,12 @@ on:
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
LLVM_VERSION: 16
|
||||
LLVM_VERSION: 18
|
||||
BUN_VERSION: 1.1.8
|
||||
LC_CTYPE: "en_US.UTF-8"
|
||||
LC_ALL: "en_US.UTF-8"
|
||||
BUN_ENABLE_LTO: "1"
|
||||
# LTO is disabled because we cannot use lld on macOS currently
|
||||
BUN_ENABLE_LTO: "0"
|
||||
|
||||
jobs:
|
||||
build-submodules:
|
||||
@@ -54,16 +55,7 @@ jobs:
|
||||
cat $(echo scripts/build*.sh scripts/all-dependencies.sh | tr " " "\n" | sort)
|
||||
}
|
||||
echo "hash=$(print_versions | shasum)" >> $GITHUB_OUTPUT
|
||||
- if: ${{ !inputs.no-cache }}
|
||||
name: Restore Cache
|
||||
id: cache
|
||||
uses: actions/cache/restore@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/bun-deps
|
||||
key: bun-${{ inputs.tag }}-deps-${{ steps.hash.outputs.hash }}
|
||||
# TODO: Figure out how to cache homebrew dependencies
|
||||
- if: ${{ inputs.no-cache || !steps.cache.outputs.cache-hit }}
|
||||
name: Install Dependencies
|
||||
- name: Install Dependencies
|
||||
env:
|
||||
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
|
||||
HOMEBREW_NO_AUTO_UPDATE: 1
|
||||
@@ -87,24 +79,16 @@ jobs:
|
||||
echo "$(brew --prefix coreutils)/libexec/gnubin" >> $GITHUB_PATH
|
||||
echo "$(brew --prefix llvm@$LLVM_VERSION)/bin" >> $GITHUB_PATH
|
||||
brew link --overwrite llvm@$LLVM_VERSION
|
||||
- if: ${{ inputs.no-cache || !steps.cache.outputs.cache-hit }}
|
||||
name: Clone Submodules
|
||||
- name: Clone Submodules
|
||||
run: |
|
||||
./scripts/update-submodules.sh
|
||||
- name: Build Submodules
|
||||
if: ${{ inputs.no-cache || !steps.cache.outputs.cache-hit }}
|
||||
env:
|
||||
CPU_TARGET: ${{ inputs.cpu }}
|
||||
BUN_DEPS_OUT_DIR: ${{ runner.temp }}/bun-deps
|
||||
run: |
|
||||
mkdir -p $BUN_DEPS_OUT_DIR
|
||||
./scripts/all-dependencies.sh
|
||||
- name: Save Cache
|
||||
if: ${{ inputs.no-cache || !steps.cache.outputs.cache-hit }}
|
||||
uses: actions/cache/save@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/bun-deps
|
||||
key: ${{ steps.cache.outputs.cache-primary-key }}
|
||||
- name: Upload bun-${{ inputs.tag }}-deps
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
@@ -148,14 +132,6 @@ jobs:
|
||||
uses: ./.github/actions/setup-bun
|
||||
with:
|
||||
bun-version: ${{ env.BUN_VERSION }}
|
||||
- if: ${{ !inputs.no-cache }}
|
||||
name: Restore Cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/ccache
|
||||
key: bun-${{ inputs.tag }}-cpp-${{ hashFiles('Dockerfile', 'Makefile', 'CMakeLists.txt', 'build.zig', 'scripts/**', 'src/**', 'packages/bun-usockets/src/**', 'packages/bun-uws/src/**') }}
|
||||
restore-keys: |
|
||||
bun-${{ inputs.tag }}-cpp-
|
||||
- name: Compile
|
||||
env:
|
||||
CPU_TARGET: ${{ inputs.cpu }}
|
||||
@@ -245,18 +221,9 @@ jobs:
|
||||
with:
|
||||
name: bun-${{ inputs.tag }}-zig
|
||||
path: ${{ runner.temp }}/release
|
||||
- if: ${{ !inputs.no-cache }}
|
||||
name: Restore Cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: ${{ runner.temp }}/ccache
|
||||
key: bun-${{ inputs.tag }}-cpp-${{ hashFiles('Dockerfile', 'Makefile', 'CMakeLists.txt', 'build.zig', 'scripts/**', 'src/**', 'packages/bun-usockets/src/**', 'packages/bun-uws/src/**') }}
|
||||
restore-keys: |
|
||||
bun-${{ inputs.tag }}-cpp-
|
||||
- name: Link
|
||||
env:
|
||||
CPU_TARGET: ${{ inputs.cpu }}
|
||||
CCACHE_DIR: ${{ runner.temp }}/ccache
|
||||
run: |
|
||||
SRC_DIR=$PWD
|
||||
mkdir ${{ runner.temp }}/link-build
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -145,3 +145,4 @@ zig-cache
|
||||
zig-out
|
||||
test/node.js/upstream
|
||||
.zig-cache
|
||||
scripts/env.local
|
||||
|
||||
@@ -4,7 +4,7 @@ cmake_policy(SET CMP0067 NEW)
|
||||
|
||||
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
|
||||
set(Bun_VERSION "1.1.21")
|
||||
set(WEBKIT_TAG 2be773eeea48c03a4fa92c170934eb2220666809)
|
||||
set(WEBKIT_TAG 49907bff8781719bc2ded068b0c934f6d0074d1e)
|
||||
|
||||
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")
|
||||
@@ -116,7 +116,7 @@ endif()
|
||||
# we do some extra work afterwards to double-check, and we will rerun BUN_FIND_LLVM if the compiler did not match.
|
||||
#
|
||||
# If the user passes -DLLVM_PREFIX, most of this logic is skipped, but we still warn if invalid.
|
||||
if(WIN32)
|
||||
if(WIN32 OR APPLE)
|
||||
set(LLVM_VERSION 18)
|
||||
else()
|
||||
set(LLVM_VERSION 16)
|
||||
@@ -154,11 +154,12 @@ macro(BUN_FIND_LLVM)
|
||||
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
|
||||
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
|
||||
)
|
||||
|
||||
find_program(
|
||||
STRIP
|
||||
NAMES strip
|
||||
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
|
||||
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
|
||||
DOC "Path to strip binary"
|
||||
)
|
||||
find_program(
|
||||
DSYMUTIL
|
||||
@@ -330,6 +331,11 @@ option(USE_STATIC_LIBATOMIC "Statically link libatomic, requires the presence of
|
||||
|
||||
option(USE_LTO "Enable Link-Time Optimization" ${DEFAULT_LTO})
|
||||
|
||||
if(APPLE AND USE_LTO)
|
||||
set(USE_LTO OFF)
|
||||
message(WARNING "Link-Time Optimization is not supported on macOS because it requires -fuse-ld=lld and lld causes many segfaults on macOS (likely related to stack size)")
|
||||
endif()
|
||||
|
||||
if(WIN32 AND USE_LTO)
|
||||
set(CMAKE_LINKER_TYPE LLD)
|
||||
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
|
||||
|
||||
@@ -4,10 +4,9 @@ source $(dirname -- "${BASH_SOURCE[0]}")/env.sh
|
||||
|
||||
mkdir -p $BUN_DEPS_OUT_DIR
|
||||
cd $BUN_DEPS_DIR/zlib
|
||||
export CFLAGS="-O3"
|
||||
if [[ $(uname -s) == 'Darwin' ]]; then
|
||||
export CFLAGS="$CFLAGS -mmacosx-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
||||
fi
|
||||
CFLAGS="${CFLAGS}" ./configure --static
|
||||
make -j${CPUS} libz.a
|
||||
rm -rf build
|
||||
mkdir build
|
||||
cd build
|
||||
cmake $CMAKE_FLAGS -G Ninja -DCMAKE_BUILD_TYPE=Release ..
|
||||
ninja
|
||||
cp ./libz.a $BUN_DEPS_OUT_DIR/libz.a
|
||||
|
||||
@@ -7,6 +7,12 @@ if [[ "${CI:-}" == "1" || "${CI:-}" == "true" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $(uname -s) == 'Darwin' ]]; then
|
||||
export LLVM_VERSION=18
|
||||
else
|
||||
export LLVM_VERSION=16
|
||||
fi
|
||||
|
||||
# this is the environment script for building bun's dependencies
|
||||
# it sets c compiler and flags
|
||||
export SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
|
||||
@@ -18,26 +24,42 @@ export BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/build/bun-deps}
|
||||
export LC_CTYPE="en_US.UTF-8"
|
||||
export LC_ALL="en_US.UTF-8"
|
||||
|
||||
if [[ "$CI" != "1" && "$CI" != "true" ]]; then
|
||||
if [ -f $SCRIPT_DIR/env.local ]; then
|
||||
echo "Sourcing $SCRIPT_DIR/env.local"
|
||||
source $SCRIPT_DIR/env.local
|
||||
fi
|
||||
elif [[ $(uname -s) == 'Darwin' ]]; then
|
||||
export CXX="$(brew --prefix llvm)@$LLVM_VERSION/bin/clang++"
|
||||
export CC="$(brew --prefix llvm)@$LLVM_VERSION/bin/clang"
|
||||
export AR="$(brew --prefix llvm)@$LLVM_VERSION/bin/llvm-ar"
|
||||
export RANLIB="$(brew --prefix llvm)@$LLVM_VERSION/bin/llvm-ranlib"
|
||||
export LIBTOOL="$(brew --prefix llvm)@$LLVM_VERSION/bin/llvm-libtool-darwin"
|
||||
export PATH="$(brew --prefix llvm)@$LLVM_VERSION/bin:$PATH"
|
||||
ln -sf $LIBTOOL "$(brew --prefix llvm)@$LLVM_VERSION/bin/libtool" || true
|
||||
fi
|
||||
|
||||
# this compiler detection could be better
|
||||
export CC=${CC:-$(which clang-16 || which clang || which cc)}
|
||||
export CXX=${CXX:-$(which clang++-16 || which clang++ || which c++)}
|
||||
export CC=${CC:-$(which clang-$LLVM_VERSION || which clang || which cc)}
|
||||
export CXX=${CXX:-$(which clang++-$LLVM_VERSION || which clang++ || which c++)}
|
||||
export AR=${AR:-$(which llvm-ar || which ar)}
|
||||
export CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
|
||||
export RANLIB=${RANLIB:-$(which llvm-ranlib-16 || which llvm-ranlib || which ranlib)}
|
||||
export RANLIB=${RANLIB:-$(which llvm-ranlib-$LLVM_VERSION || which llvm-ranlib || which ranlib)}
|
||||
|
||||
# on Linux, force using lld as the linker
|
||||
if [[ $(uname -s) == 'Linux' ]]; then
|
||||
export LD=${LD:-$(which ld.lld-16 || which ld.lld || which ld)}
|
||||
export LD=${LD:-$(which ld.lld-$LLVM_VERSION || which ld.lld || which ld)}
|
||||
export LDFLAGS="${LDFLAGS} -fuse-ld=lld "
|
||||
fi
|
||||
|
||||
export CMAKE_CXX_COMPILER=${CXX}
|
||||
export CMAKE_C_COMPILER=${CC}
|
||||
|
||||
export CFLAGS='-O3 -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -faddrsig '
|
||||
export CXXFLAGS='-O3 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -faddrsig -fno-c++-static-destructors '
|
||||
export CFLAGS='-O3 -fno-exceptions -fvisibility=hidden -fvisibility-inlines-hidden -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables '
|
||||
export CXXFLAGS='-O3 -fno-exceptions -fno-rtti -fvisibility=hidden -fvisibility-inlines-hidden -mno-omit-leaf-frame-pointer -fno-omit-frame-pointer -fno-asynchronous-unwind-tables -fno-unwind-tables -fno-c++-static-destructors '
|
||||
|
||||
# Add flags for LTO
|
||||
# We cannot enable LTO on macOS for dependencies because it requires -fuse-ld=lld and lld causes many segfaults on macOS (likely related to stack size)
|
||||
if [ "$BUN_ENABLE_LTO" == "1" ]; then
|
||||
export CFLAGS="$CFLAGS -flto=full "
|
||||
export CXXFLAGS="$CXXFLAGS -flto=full -fwhole-program-vtables -fforce-emit-vtables "
|
||||
@@ -45,16 +67,23 @@ if [ "$BUN_ENABLE_LTO" == "1" ]; then
|
||||
fi
|
||||
|
||||
if [[ $(uname -s) == 'Linux' ]]; then
|
||||
export CFLAGS="$CFLAGS -ffunction-sections -fdata-sections"
|
||||
export CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections"
|
||||
export CFLAGS="$CFLAGS -ffunction-sections -fdata-sections -faddrsig "
|
||||
export CXXFLAGS="$CXXFLAGS -ffunction-sections -fdata-sections -faddrsig "
|
||||
export LDFLAGS="${LDFLAGS} -Wl,-z,norelro"
|
||||
fi
|
||||
|
||||
# Clang 18 on macOS needs to have -fno-define-target-os-macros to fix a zlib build issue
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/25755
|
||||
if [[ $(uname -s) == 'Darwin' && $LLVM_VERSION == '18' ]]; then
|
||||
export CFLAGS="$CFLAGS -fno-define-target-os-macros "
|
||||
export CXXFLAGS="$CXXFLAGS -fno-define-target-os-macros "
|
||||
fi
|
||||
|
||||
# libarchive needs position-independent executables to compile successfully
|
||||
if [ -n "$FORCE_PIC" ]; then
|
||||
export CFLAGS="$CFLAGS -fPIC "
|
||||
export CXXFLAGS="$CXXFLAGS -fPIC "
|
||||
else
|
||||
elif [[ $(uname -s) == 'Linux' ]]; then
|
||||
export CFLAGS="$CFLAGS -fno-pie -fno-pic "
|
||||
export CXXFLAGS="$CXXFLAGS -fno-pie -fno-pic "
|
||||
fi
|
||||
|
||||
@@ -15,12 +15,35 @@ fail() {
|
||||
printf "${C_RED}setup error${C_RESET}: %s\n" "$@"
|
||||
}
|
||||
|
||||
LLVM_VERSION=16
|
||||
if [[ $(uname -s) == 'Darwin' ]]; then
|
||||
export LLVM_VERSION=18
|
||||
|
||||
# this compiler detection could be better
|
||||
# it is copy pasted from ./env.sh
|
||||
CC=${CC:-$(which clang-16 || which clang || which cc)}
|
||||
CXX=${CXX:-$(which clang++-16 || which clang++ || which c++)}
|
||||
# Use from brew --prefix if available
|
||||
if has_exec brew; then
|
||||
export PKG_CONFIG_PATH=$(brew --prefix)/lib/pkgconfig:$PKG_CONFIG_PATH
|
||||
|
||||
# if llvm@18/bin/clang exists, use it
|
||||
if [ -x "$(brew --prefix)/opt/llvm@$LLVM_VERSION/bin/clang" ]; then
|
||||
export PATH=$(brew --prefix)/opt/llvm@$LLVM_VERSION/bin:$PATH
|
||||
export CC=$(brew --prefix)/opt/llvm@$LLVM_VERSION/bin/clang
|
||||
export CXX=$(brew --prefix)/opt/llvm@$LLVM_VERSION/bin/clang++
|
||||
export AR=$(brew --prefix)/opt/llvm@$LLVM_VERSION/bin/llvm-ar
|
||||
else
|
||||
export CC=$(which clang-$LLVM_VERSION || which clang || which cc)
|
||||
export CXX=$(which clang++-$LLVM_VERSION || which clang++ || which c++)
|
||||
export AR=$(which llvm-ar-$LLVM_VERSION || which llvm-ar || which ar)
|
||||
fi
|
||||
fi
|
||||
|
||||
test -n "$CC" || fail "missing LLVM $LLVM_VERSION (could not find clang)"
|
||||
test -n "$CXX" || fail "missing LLVM $LLVM_VERSION (could not find clang++)"
|
||||
else
|
||||
export LLVM_VERSION=16
|
||||
|
||||
export CC=$(which clang-$LLVM_VERSION || which clang || which cc)
|
||||
export CXX=$(which clang++-$LLVM_VERSION || which clang++ || which c++)
|
||||
export AR=$(which llvm-ar-$LLVM_VERSION || which llvm-ar || which ar)
|
||||
fi
|
||||
|
||||
test -n "$CC" || fail "missing LLVM $LLVM_VERSION (could not find clang)"
|
||||
test -n "$CXX" || fail "missing LLVM $LLVM_VERSION (could not find clang++)"
|
||||
@@ -36,9 +59,9 @@ has_exec "bun" || fail "you need an existing copy of 'bun' in your path to build
|
||||
has_exec "cmake" || fail "'cmake' is missing"
|
||||
has_exec "ninja" || fail "'ninja' is missing"
|
||||
$(
|
||||
has_exec "rustc" \
|
||||
&& (test $(cargo --version | awk '{print $2}' | cut -d. -f2) -gt 57) \
|
||||
&& has_exec "cargo"
|
||||
has_exec "rustc" &&
|
||||
(test $(cargo --version | awk '{print $2}' | cut -d. -f2) -gt 57) &&
|
||||
has_exec "cargo"
|
||||
) || fail "Rust and Cargo version must be installed (minimum version 1.57)"
|
||||
has_exec "go" || fail "'go' is missing"
|
||||
|
||||
@@ -59,6 +82,15 @@ printf "C Compiler for dependencies: ${CC}\n"
|
||||
printf "C++ Compiler for dependencies: ${CXX}\n"
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||
|
||||
rm -rf env.local
|
||||
echo "# Environment variables as of last setup.sh run at $(date)" >env.local
|
||||
echo "export CC=\"${CC}\"" >>env.local
|
||||
echo "export CXX\"=${CXX}\"" >>env.local
|
||||
echo "export AR=\"${AR}\"" >>env.local
|
||||
echo "export PATH=\"${PATH}\"" >>env.local
|
||||
echo "Saved environment variables to $(pwd)/env.local"
|
||||
|
||||
bash ./update-submodules.sh
|
||||
bash ./all-dependencies.sh
|
||||
|
||||
@@ -67,7 +99,9 @@ cd ../
|
||||
# Install bun dependencies
|
||||
bun i
|
||||
# Install test dependencies
|
||||
cd test; bun i; cd ..
|
||||
cd test
|
||||
bun i
|
||||
cd ..
|
||||
|
||||
# TODO(@paperdave): do not use the Makefile please
|
||||
has_exec "make" || fail "'make' is missing"
|
||||
@@ -81,7 +115,7 @@ cmake -B build -S . \
|
||||
-DCMAKE_BUILD_TYPE=Debug \
|
||||
-DCMAKE_C_COMPILER="$CC" \
|
||||
-DCMAKE_CXX_COMPILER="$CXX" \
|
||||
-UZIG_COMPILER "$*" \
|
||||
-UZIG_COMPILER "$*"
|
||||
|
||||
ninja -C build
|
||||
|
||||
|
||||
@@ -5560,7 +5560,7 @@ extern "C" EncodedJSValue JSC__JSValue__dateInstanceFromNullTerminatedString(JSC
|
||||
// this is largely copied from dateProtoFuncToISOString
|
||||
extern "C" int JSC__JSValue__toISOString(JSC::JSGlobalObject* globalObject, EncodedJSValue dateValue, char* buf)
|
||||
{
|
||||
char buffer[28];
|
||||
char buffer[29];
|
||||
JSC::DateInstance* thisDateObj = JSC::jsDynamicCast<JSC::DateInstance*>(JSC::JSValue::decode(dateValue));
|
||||
if (!thisDateObj)
|
||||
return -1;
|
||||
|
||||
@@ -4,7 +4,7 @@ pub const boringssl = "29a2cd359458c9384694b75456026e4b57e3e567";
|
||||
pub const libarchive = "898dc8319355b7e985f68a9819f182aaed61b53a";
|
||||
pub const mimalloc = "4c283af60cdae205df5a872530c77e2a6a307d43";
|
||||
pub const picohttpparser = "066d2b1e9ab820703db0837a7255d92d30f0c9f5";
|
||||
pub const webkit = "2be773eeea48c03a4fa92c170934eb2220666809";
|
||||
pub const webkit = "49907bff8781719bc2ded068b0c934f6d0074d1e";
|
||||
pub const zig = @import("std").fmt.comptimePrint("{}", .{@import("builtin").zig_version});
|
||||
pub const zlib = "886098f3f339617b4243b286f5ed364b9989e245";
|
||||
pub const tinycc = "ab631362d839333660a265d3084d8ff060b96753";
|
||||
|
||||
Reference in New Issue
Block a user