Skip to content

Commit

Permalink
ci: musl builds (#15154)
Browse files Browse the repository at this point in the history
Co-authored-by: Electroid <[email protected]>
Co-authored-by: Meghan Denny <[email protected]>
  • Loading branch information
3 people authored Nov 16, 2024
1 parent 4fedc41 commit 39d8ade
Show file tree
Hide file tree
Showing 26 changed files with 3,293 additions and 684 deletions.
732 changes: 534 additions & 198 deletions .buildkite/ci.mjs
100644 → 100755

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions .buildkite/scripts/upload-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ function create_release() {
bun-linux-x64-profile.zip
bun-linux-x64-baseline.zip
bun-linux-x64-baseline-profile.zip
bun-linux-aarch64-musl.zip
bun-linux-aarch64-musl-profile.zip
bun-linux-x64-musl.zip
bun-linux-x64-musl-profile.zip
bun-linux-x64-musl-baseline.zip
bun-linux-x64-musl-baseline-profile.zip
bun-windows-x64.zip
bun-windows-x64-profile.zip
bun-windows-x64-baseline.zip
Expand Down
18 changes: 18 additions & 0 deletions ci/linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG IMAGE=debian:11
FROM $IMAGE
COPY ./scripts/bootstrap.sh /tmp/bootstrap.sh
ENV CI=true
RUN sh /tmp/bootstrap.sh && rm -rf /tmp/*
WORKDIR /workspace/bun
COPY bunfig.toml bunfig.toml
COPY package.json package.json
COPY CMakeLists.txt CMakeLists.txt
COPY cmake/ cmake/
COPY scripts/ scripts/
COPY patches/ patches/
COPY *.zig ./
COPY src/ src/
COPY packages/ packages/
COPY test/ test/
RUN bun i
RUN bun run build:ci
27 changes: 27 additions & 0 deletions ci/linux/scripts/set-hostname.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

# This script sets the hostname of the current machine.

execute() {
echo "$ $@" >&2
if ! "$@"; then
echo "Command failed: $@" >&2
exit 1
fi
}

main() {
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <hostname>" >&2
exit 1
fi

if [ -f "$(which hostnamectl)" ]; then
execute hostnamectl set-hostname "$1"
else
echo "Error: hostnamectl is not installed." >&2
exit 1
fi
}

main "$@"
22 changes: 22 additions & 0 deletions ci/linux/scripts/start-tailscale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

# This script starts tailscale on the current machine.

execute() {
echo "$ $@" >&2
if ! "$@"; then
echo "Command failed: $@" >&2
exit 1
fi
}

main() {
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <auth-key>" >&2
exit 1
fi

execute tailscale up --reset --ssh --accept-risk=lose-ssh --auth-key="$1"
}

main "$@"
2 changes: 1 addition & 1 deletion ci/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"scripts": {
"bootstrap": "brew install gh jq cirruslabs/cli/tart cirruslabs/cli/sshpass hashicorp/tap/packer && packer init darwin",
"login": "gh auth token | tart login ghcr.io --username $(gh api user --jq .login) --password-stdin",
"login": "token=$(gh auth token); username=$(gh api user --jq .login); echo \"Login as $username...\"; echo \"$token\" | tart login ghcr.io --username \"$username\" --password-stdin; echo \"$token\" | docker login ghcr.io --username \"$username\" --password-stdin",
"fetch:image-name": "echo ghcr.io/oven-sh/bun-vm",
"fetch:darwin-version": "echo 1",
"fetch:macos-version": "sw_vers -productVersion | cut -d. -f1",
Expand Down
18 changes: 10 additions & 8 deletions cmake/Globals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,6 @@ else()
unsupported(CMAKE_HOST_SYSTEM_NAME)
endif()

if(EXISTS "/lib/ld-musl-aarch64.so.1")
set(IS_MUSL ON)
elseif(EXISTS "/lib/ld-musl-x86_64.so.1")
set(IS_MUSL ON)
else()
set(IS_MUSL OFF)
endif()

if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
set(HOST_OS "aarch64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64")
Expand Down Expand Up @@ -144,6 +136,16 @@ else()
set(WARNING WARNING)
endif()

if(LINUX)
if(EXISTS "/etc/alpine-release")
set(DEFAULT_ABI "musl")
else()
set(DEFAULT_ABI "gnu")
endif()

optionx(ABI "musl|gnu" "The ABI to use (e.g. musl, gnu)" DEFAULT ${DEFAULT_ABI})
endif()

# TODO: This causes flaky zig builds in CI, so temporarily disable it.
# if(CI)
# set(DEFAULT_VENDOR_PATH ${CACHE_PATH}/vendor)
Expand Down
121 changes: 41 additions & 80 deletions cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,12 @@ set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o)


if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|arm64|ARM64|aarch64|AARCH64")
set(IS_ARM64 ON)
if(APPLE)
set(ZIG_CPU "apple_m1")
else()
set(ZIG_CPU "native")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64")
set(IS_X86_64 ON)
if(ENABLE_BASELINE)
set(ZIG_CPU "nehalem")
else()
Expand Down Expand Up @@ -761,8 +759,8 @@ if(NOT WIN32)
)
if(DEBUG)
# TODO: this shouldn't be necessary long term
if (NOT IS_MUSL)
set(ABI_PUBLIC_FLAGS
if (NOT ABI STREQUAL "musl")
target_compile_options(${bun} PUBLIC
-fsanitize=null
-fsanitize-recover=all
-fsanitize=bounds
Expand All @@ -773,14 +771,9 @@ if(NOT WIN32)
-fsanitize=returns-nonnull-attribute
-fsanitize=unreachable
)
set(ABI_PRIVATE_FLAGS
target_link_libraries(${bun} PRIVATE
-fsanitize=null
)
else()
set(ABI_PUBLIC_FLAGS
)
set(ABI_PRIVATE_FLAGS
)
endif()

target_compile_options(${bun} PUBLIC
Expand All @@ -798,10 +791,6 @@ if(NOT WIN32)
-Wno-unused-function
-Wno-nullability-completeness
-Werror
${ABI_PUBLIC_FLAGS}
)
target_link_libraries(${bun} PRIVATE
${ABI_PRIVATE_FLAGS}
)
else()
# Leave -Werror=unused off in release builds so we avoid errors from being used in ASSERT
Expand Down Expand Up @@ -846,7 +835,9 @@ if(WIN32)
/delayload:IPHLPAPI.dll
)
endif()
elseif(APPLE)
endif()

if(APPLE)
target_link_options(${bun} PUBLIC
-dead_strip
-dead_strip_dylibs
Expand All @@ -856,63 +847,36 @@ elseif(APPLE)
-fno-keep-static-consts
-Wl,-map,${bun}.linker-map
)
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()
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}")
if(LINUX)
if(NOT ABI STREQUAL "musl")
if(ARCH STREQUAL "aarch64")
target_link_options(${bun} PUBLIC
-Wl,--wrap=fcntl64
-Wl,--wrap=statx
)
endif()

if(ARCH STREQUAL "x64")
target_link_options(${bun} PUBLIC
-Wl,--wrap=fcntl
-Wl,--wrap=fcntl64
-Wl,--wrap=fstat
-Wl,--wrap=fstat64
-Wl,--wrap=fstatat
-Wl,--wrap=fstatat64
-Wl,--wrap=lstat
-Wl,--wrap=lstat64
-Wl,--wrap=mknod
-Wl,--wrap=mknodat
-Wl,--wrap=stat
-Wl,--wrap=stat64
-Wl,--wrap=statx
)
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()

if (NOT IS_MUSL)
if (IS_ARM64)
set(ARCH_WRAP_FLAGS
-Wl,--wrap=fcntl64
-Wl,--wrap=statx
)
elseif(IS_X86_64)
set(ARCH_WRAP_FLAGS
-Wl,--wrap=fcntl
-Wl,--wrap=fcntl64
-Wl,--wrap=fstat
-Wl,--wrap=fstat64
-Wl,--wrap=fstatat
-Wl,--wrap=fstatat64
-Wl,--wrap=lstat
-Wl,--wrap=lstat64
-Wl,--wrap=mknod
-Wl,--wrap=mknodat
-Wl,--wrap=stat
-Wl,--wrap=stat64
-Wl,--wrap=statx
)
endif()
else()
set(ARCH_WRAP_FLAGS
)
endif()

if (NOT IS_MUSL)
set(ABI_WRAP_FLAGS
target_link_options(${bun} PUBLIC
-Wl,--wrap=cosf
-Wl,--wrap=exp
-Wl,--wrap=expf
Expand All @@ -929,13 +893,10 @@ else()
-Wl,--wrap=sinf
-Wl,--wrap=tanf
)
else()
set(ABI_WRAP_FLAGS
)
endif()

target_link_options(${bun} PUBLIC
-fuse-ld=${LLD_NAME}
--ld-path=${LLD_PROGRAM}
-fno-pic
-static-libstdc++
-static-libgcc
Expand All @@ -944,8 +905,6 @@ else()
-Wl,--as-needed
-Wl,--gc-sections
-Wl,-z,stack-size=12800000
${ARCH_WRAP_FLAGS}
${ABI_WRAP_FLAGS}
-Wl,--compress-debug-sections=zlib
-Wl,-z,lazy
-Wl,-z,norelro
Expand Down Expand Up @@ -1095,12 +1054,12 @@ endif()

if(NOT BUN_CPP_ONLY)
set(CMAKE_STRIP_FLAGS "")
if (APPLE)
if(APPLE)
# We do not build with exceptions enabled. These are generated by lolhtml
# and other dependencies. We build lolhtml with abort on panic, so it
# shouldn't be including these in the first place.
set(CMAKE_STRIP_FLAGS --remove-section=__TEXT,__eh_frame --remove-section=__TEXT,__unwind_info --remove-section=__TEXT,__gcc_except_tab)
elseif(LINUX)
elseif(LINUX AND NOT ABI STREQUAL "musl")
# When you use llvm-strip to do this, it doesn't delete it from the binary and instead keeps it as [LOAD #2 [R]]
# So, we must use GNU strip to do this.
set(CMAKE_STRIP_FLAGS -R .eh_frame -R .gcc_except_table)
Expand Down Expand Up @@ -1193,10 +1152,12 @@ if(NOT BUN_CPP_ONLY)
endif()

if(CI)
set(bunTriplet bun-${OS}-${ARCH})
if(ABI STREQUAL "musl")
set(bunTriplet ${bunTriplet}-musl)
endif()
if(ENABLE_BASELINE)
set(bunTriplet bun-${OS}-${ARCH}-baseline)
else()
set(bunTriplet bun-${OS}-${ARCH})
set(bunTriplet ${bunTriplet}-baseline)
endif()
string(REPLACE bun ${bunTriplet} bunPath ${bun})
set(bunFiles ${bunExe} features.json)
Expand Down
6 changes: 6 additions & 0 deletions cmake/toolchains/linux-aarch64-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(ABI musl)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
1 change: 1 addition & 0 deletions cmake/toolchains/linux-aarch64.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(ABI gnu)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
1 change: 1 addition & 0 deletions cmake/toolchains/linux-x64-baseline.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ENABLE_BASELINE ON)
set(ABI gnu)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
7 changes: 7 additions & 0 deletions cmake/toolchains/linux-x64-musl-baseline.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ENABLE_BASELINE ON)
set(ABI musl)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
6 changes: 6 additions & 0 deletions cmake/toolchains/linux-x64-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ABI musl)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
1 change: 1 addition & 0 deletions cmake/toolchains/linux-x64.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ABI gnu)

set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)
2 changes: 1 addition & 1 deletion cmake/tools/SetupGit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ execute_process(
)

if(NOT GIT_DIFF_RESULT EQUAL 0)
message(${WARNING} "Command failed: ${GIT_DIFF_COMMAND} ${GIT_DIFF_ERROR}")
message(WARNING "Command failed: ${GIT_DIFF_COMMAND} ${GIT_DIFF_ERROR}")
return()
endif()

Expand Down
Loading

0 comments on commit 39d8ade

Please sign in to comment.