Compare commits

..

53 Commits

Author SHA1 Message Date
Ashcon Partovi
88063eaad5 Fix? 2024-09-24 17:39:37 -07:00
Ashcon Partovi
da2d1e12ed Testing 2024-09-24 17:20:21 -07:00
Ashcon Partovi
6b54dbfa07 Test old 2024-09-24 16:45:04 -07:00
Ashcon Partovi
1dfa557ca4 Test changes 2024-09-24 16:18:23 -07:00
Ashcon Partovi
29d1b4db74 Fix linking 2024-09-24 16:13:37 -07:00
Ashcon Partovi
85edb39a2f Fix linking 2024-09-24 15:58:50 -07:00
Ashcon Partovi
f0384f39b7 Fix command 2024-09-24 15:50:16 -07:00
Ashcon Partovi
2e1b19b9fd Fix option 2024-09-24 15:47:57 -07:00
Ashcon Partovi
53ce1ff6c1 Fix 2024-09-24 15:23:03 -07:00
Ashcon Partovi
eee9b51df3 Fix 2024-09-24 15:14:25 -07:00
Ashcon Partovi
f0036cc6c1 Fix target names 2024-09-24 15:05:48 -07:00
Ashcon Partovi
77a25c0188 Fix target names 2024-09-24 15:03:24 -07:00
Ashcon Partovi
a3777b8c22 Fix alias 2024-09-24 15:01:34 -07:00
Ashcon Partovi
0d9d7a3436 Fix 2024-09-24 14:58:54 -07:00
Ashcon Partovi
d5e7846eaf Fix 2024-09-24 14:49:18 -07:00
Ashcon Partovi
582a53e26e Random ID 2024-09-23 16:24:57 -07:00
Ashcon Partovi
57d9cfc24d Fixes 2024-09-23 16:19:34 -07:00
Ashcon Partovi
31dc58fa79 Typo 2024-09-23 13:34:33 -07:00
Ashcon Partovi
03bb9fd9b5 Fix 2024-09-23 13:31:12 -07:00
Ashcon Partovi
f270f235c8 Fix 2024-09-23 13:30:05 -07:00
Ashcon Partovi
8d1b5856d3 Fixes 2024-09-23 13:22:34 -07:00
Ashcon Partovi
bf488d0b19 Fixes 2024-09-23 13:21:13 -07:00
Ashcon Partovi
9dc0672840 Fixes 2024-09-23 12:59:10 -07:00
Ashcon Partovi
b1d0cb0ea3 Maybe fix 2024-09-23 12:44:54 -07:00
Ashcon Partovi
155ba7ebdf Debug logs 2024-09-23 12:41:46 -07:00
Ashcon Partovi
3757a3e30f Maybe fix 2024-09-23 12:00:57 -07:00
Ashcon Partovi
4b443db0d8 Maybe fix 2024-09-23 11:59:20 -07:00
Ashcon Partovi
d74ae08946 Test 2024-09-23 11:54:56 -07:00
Ashcon Partovi
a7a5ed2fba Update ci 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7d7c9877a4 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
1cd43f5bae WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
56b6ed6d97 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
85dd8ef0d4 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
6cb0de3921 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
2c1dcb5a1d Extra if check 2024-09-20 18:58:02 -07:00
Ashcon Partovi
d3f3900da7 Maybe fix webkit 2024-09-20 18:58:02 -07:00
Ashcon Partovi
ef18731db1 Fix format 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7fb15e5a03 Ensure fresh 2024-09-20 18:58:02 -07:00
Ashcon Partovi
2b017cd0ad Fix 2024-09-20 18:58:02 -07:00
Ashcon Partovi
9f857fa418 Run clang-format 2024-09-20 18:58:02 -07:00
Ashcon Partovi
1cde69d0f1 Better webkit download 2024-09-20 18:58:02 -07:00
Ashcon Partovi
800e378b6e Run scripts 2024-09-20 18:58:02 -07:00
Ashcon Partovi
dfe8fb50d9 Build 2024-09-20 18:58:02 -07:00
Ashcon Partovi
0f6cfc0b16 Changes 2024-09-20 18:58:02 -07:00
Ashcon Partovi
019cfb7927 Changes 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7887689fd0 Fixes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
888d8301ca Fix dependency 2024-09-20 18:58:01 -07:00
Ashcon Partovi
704c169e04 changes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
c16e34078a Script changes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
bc9e022c86 Changes 2024-09-20 18:58:00 -07:00
Ashcon Partovi
a88b8130b9 Fix 2024-09-20 18:57:38 -07:00
Ashcon Partovi
2139e8442a Fix 2024-09-20 18:57:38 -07:00
Ashcon Partovi
f50a80a7c1 Linting in buildkite 2024-09-20 18:57:38 -07:00
1099 changed files with 31000 additions and 133441 deletions

View File

@@ -12,17 +12,17 @@ steps:
- key: "darwin-aarch64"
group: ":darwin: aarch64"
steps:
- key: "darwin-aarch64-build-deps"
label: "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: "build-cpp"
label: ":darwin: aarch64 - build-cpp"
agents:
queue: "build-darwin"
os: "darwin"
@@ -33,20 +33,20 @@ steps:
- "bun run build:ci --target bun"
- key: "darwin-aarch64-build-zig"
label: "build-zig"
label: ":darwin: aarch64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain darwin-aarch64"
- key: "darwin-aarch64-build-bun"
label: "build-bun"
label: ":darwin: aarch64 - build-bun"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
depends_on:
- "darwin-aarch64-build-deps"
- "darwin-aarch64-build-vendor"
- "darwin-aarch64-build-cpp"
- "darwin-aarch64-build-zig"
env:
@@ -114,17 +114,17 @@ steps:
- key: "darwin-x64"
group: ":darwin: x64"
steps:
- key: "darwin-x64-build-deps"
label: "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: "build-cpp"
label: ":darwin: x64 - build-cpp"
agents:
queue: "build-darwin"
os: "darwin"
@@ -135,20 +135,20 @@ steps:
- "bun run build:ci --target bun"
- key: "darwin-x64-build-zig"
label: "build-zig"
label: ":darwin: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain darwin-x64"
- key: "darwin-x64-build-bun"
label: "build-bun"
label: ":darwin: x64 - build-bun"
agents:
queue: "build-darwin"
os: "darwin"
arch: "x64"
depends_on:
- "darwin-x64-build-deps"
- "darwin-x64-build-vendor"
- "darwin-x64-build-cpp"
- "darwin-x64-build-zig"
env:
@@ -216,17 +216,17 @@ steps:
- key: "linux-x64"
group: ":linux: x64"
steps:
- key: "linux-x64-build-deps"
label: "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: "build-cpp"
label: ":linux: x64 - build-cpp"
agents:
queue: "build-linux"
os: "linux"
@@ -237,20 +237,20 @@ steps:
- "bun run build:ci --target bun"
- key: "linux-x64-build-zig"
label: "build-zig"
label: ":linux: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain linux-x64"
- key: "linux-x64-build-bun"
label: "build-bun"
label: ":linux: x64 - build-bun"
agents:
queue: "build-linux"
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: "build-deps"
- key: "linux-x64-baseline-build-vendor"
label: ":linux: x64-baseline - build-vendor"
agents:
queue: "build-linux"
os: "linux"
@@ -358,10 +358,10 @@ 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: "build-cpp"
label: ":linux: x64-baseline - build-cpp"
agents:
queue: "build-linux"
os: "linux"
@@ -373,7 +373,7 @@ steps:
- "bun run build:ci --target bun"
- key: "linux-x64-baseline-build-zig"
label: "build-zig"
label: ":linux: x64-baseline - build-zig"
agents:
queue: "build-zig"
env:
@@ -382,13 +382,13 @@ steps:
- "bun run build:ci --target bun-zig --toolchain linux-x64-baseline"
- key: "linux-x64-baseline-build-bun"
label: "build-bun"
label: ":linux: x64-baseline - build-bun"
agents:
queue: "build-linux"
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,17 +488,17 @@ steps:
- key: "linux-aarch64"
group: ":linux: aarch64"
steps:
- key: "linux-aarch64-build-deps"
label: "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: "build-cpp"
label: ":linux: aarch64 - build-cpp"
agents:
queue: "build-linux"
os: "linux"
@@ -509,20 +509,20 @@ steps:
- "bun run build:ci --target bun"
- key: "linux-aarch64-build-zig"
label: "build-zig"
label: ":linux: aarch64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain linux-aarch64"
- key: "linux-aarch64-build-bun"
label: "build-bun"
label: ":linux: aarch64 - build-bun"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
depends_on:
- "linux-aarch64-build-deps"
- "linux-aarch64-build-vendor"
- "linux-aarch64-build-cpp"
- "linux-aarch64-build-zig"
env:
@@ -621,55 +621,43 @@ steps:
- key: "windows-x64"
group: ":windows: x64"
steps:
- key: "windows-x64-build-deps"
label: "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: "build-cpp"
label: ":windows: x64 - build-cpp"
agents:
queue: "build-windows"
os: "windows"
arch: "x64"
retry:
automatic:
- exit_status: 255
limit: 5
env:
BUN_CPP_ONLY: "ON"
command:
- "bun run build:ci --target bun"
- key: "windows-x64-build-zig"
label: "build-zig"
label: ":windows: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain windows-x64"
- key: "windows-x64-build-bun"
label: "build-bun"
label: ":windows: x64 - build-bun"
agents:
queue: "build-windows"
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,31 +692,23 @@ steps:
- key: "windows-x64-baseline"
group: ":windows: x64-baseline"
steps:
- key: "windows-x64-baseline-build-deps"
label: "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: "build-cpp"
label: ":windows: x64-baseline - build-cpp"
agents:
queue: "build-windows"
os: "windows"
arch: "x64"
retry:
automatic:
- exit_status: 255
limit: 5
env:
ENABLE_BASELINE: "ON"
BUN_CPP_ONLY: "ON"
@@ -736,7 +716,7 @@ steps:
- "bun run build:ci --target bun"
- key: "windows-x64-baseline-build-zig"
label: "build-zig"
label: ":windows: x64-baseline - build-zig"
agents:
queue: "build-zig"
env:
@@ -745,19 +725,15 @@ steps:
- "bun run build:ci --target bun-zig --toolchain windows-x64-baseline"
- key: "windows-x64-baseline-build-bun"
label: "build-bun"
label: ":windows: x64-baseline - build-bun"
agents:
queue: "build-windows"
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"

1539
.docker/chrome.json Normal file

File diff suppressed because it is too large Load Diff

14
.docker/chromium.pref Normal file
View File

@@ -0,0 +1,14 @@
# Note: 2 blank lines are required between entries
Package: *
Pin: release a=eoan
Pin-Priority: 500
Package: *
Pin: origin "ftp.debian.org"
Pin-Priority: 300
# Pattern includes 'chromium', 'chromium-browser' and similarly
# named dependencies:
Package: chromium*
Pin: origin "ftp.debian.org"
Pin-Priority: 700

View File

@@ -0,0 +1,8 @@
#!/bin/bash
set -euxo pipefail
name=$(openssl rand -hex 12)
id=$(docker create --name=bun-binary-$name $CONTAINER_TAG)
docker container cp bun-binary-$name:$BUN_RELEASE_DIR bun-binary
echo -e "bun-binary-$name"

3
.docker/debian.list Normal file
View File

@@ -0,0 +1,3 @@
deb http://deb.debian.org/debian buster main
deb http://deb.debian.org/debian buster-updates main
deb http://deb.debian.org/debian-security buster/updates main

View File

@@ -0,0 +1,34 @@
export DOCKER_BUILDKIT=1
export BUILDKIT_ARCH=$(uname -m)
export ARCH=${BUILDKIT_ARCH}
if [ "$BUILDKIT_ARCH" == "amd64" ]; then
export BUILDKIT_ARCH="amd64"
export ARCH=x64
fi
if [ "$BUILDKIT_ARCH" == "x86_64" ]; then
export BUILDKIT_ARCH="amd64"
export ARCH=x64
fi
if [ "$BUILDKIT_ARCH" == "arm64" ]; then
export BUILDKIT_ARCH="arm64"
export ARCH=aarch64
fi
if [ "$BUILDKIT_ARCH" == "aarch64" ]; then
export BUILDKIT_ARCH="arm64"
export ARCH=aarch64
fi
if [ "$BUILDKIT_ARCH" == "armv7l" ]; then
echo "Unsupported platform: $BUILDKIT_ARCH"
exit 1
fi
export BUILD_ID=$(cat build-id)
export CONTAINER_NAME=bun-linux-$ARCH
export DEBUG_CONTAINER_NAME=debug-bun-linux-$ARCH
export TEMP=/tmp/bun-0.0.$BUILD_ID

11
.docker/pull.sh Normal file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
set -euxo pipefail
docker pull bunbunbunbun/bun-test-base:latest --platform=linux/amd64
docker pull bunbunbunbun/bun-base:latest --platform=linux/amd64
docker pull bunbunbunbun/bun-base-with-zig-and-webkit:latest --platform=linux/amd64
docker tag bunbunbunbun/bun-test-base:latest bun-base:latest
docker tag bunbunbunbun/bun-base:latest bun-base:latest
docker tag bunbunbunbun/bun-base-with-zig-and-webkit:latest bun-base-with-zig-and-webkit:latest

47
.docker/run-dockerfile.sh Normal file
View File

@@ -0,0 +1,47 @@
#!/bin/bash
source "dockerfile-common.sh"
export $CONTAINER_NAME=$CONTAINER_NAME-local
rm -rf $TEMP
mkdir -p $TEMP
docker build . --target release --progress=plain -t $CONTAINER_NAME:latest --build-arg BUILDKIT_INLINE_CACHE=1 --platform=linux/$BUILDKIT_ARCH --cache-from $CONTAINER_NAME:latest
if (($?)); then
echo "Failed to build container"
exit 1
fi
id=$(docker create $CONTAINER_NAME:latest)
docker cp $id:/home/ubuntu/bun-release $TEMP/$CONTAINER_NAME
if (($?)); then
echo "Failed to cp container"
exit 1
fi
cd $TEMP
mkdir -p $TEMP/$CONTAINER_NAME $TEMP/$DEBUG_CONTAINER_NAME
mv $CONTAINER_NAME/bun-profile $DEBUG_CONTAINER_NAME/bun
zip -r $CONTAINER_NAME.zip $CONTAINER_NAME
zip -r $DEBUG_CONTAINER_NAME.zip $DEBUG_CONTAINER_NAME
docker rm -v $id
abs=$(realpath $TEMP/$CONTAINER_NAME.zip)
debug_abs=$(realpath $TEMP/$DEBUG_CONTAINER_NAME.zip)
case $(uname -s) in
"Linux") target="linux" ;;
*) target="other" ;;
esac
if [ "$target" = "linux" ]; then
if command -v bun --version >/dev/null; then
cp $TEMP/$CONTAINER_NAME/bun $(which bun)
cp $TEMP/$DEBUG_CONTAINER_NAME/bun $(which bun-profile)
fi
fi
echo "Saved to:"
echo $debug_abs
echo $abs

9
.docker/run-test.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
set -euxo pipefail
bun install
bun install --cwd ./test/snippets
bun install --cwd ./test/scripts
make $BUN_TEST_NAME

5
.docker/runner.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -euxo pipefail
docker container run --security-opt seccomp=.docker/chrome.json --env GITHUB_WORKSPACE=$GITHUB_WORKSPACE --env BUN_TEST_NAME=$BUN_TEST_NAME --ulimit memlock=-1:-1 --init --rm bun-test:latest

5
.docker/unit-tests.sh Normal file
View File

@@ -0,0 +1,5 @@
#!/bin/bash
set -euxo pipefail
docker container run --security-opt seccomp=.docker/chrome.json --env GITHUB_WORKSPACE=$GITHUB_WORKSPACE --ulimit memlock=-1:-1 --init --rm bun-unit-tests:latest

View File

@@ -1,6 +1,6 @@
name: 🇹 TypeScript Type Bug Report
description: Report an issue with TypeScript types
labels: [bug, types]
labels: [bug, typescript]
body:
- type: markdown
attributes:

View File

@@ -11,8 +11,8 @@ body:
- type: textarea
id: package_json
attributes:
label: "`package.json` file"
description: "Can you upload your `package.json` file? This helps us reproduce the crash."
label: `package.json` file
description: Can you upload your `package.json` file? This helps us reproduce the crash.
render: json
- type: textarea
id: repro

View File

@@ -47,5 +47,4 @@ runs:
mkdir -p ${{ runner.temp }}/.bun/bin
mv ${target}/bun* ${{ runner.temp }}/.bun/bin/
chmod +x ${{ runner.temp }}/.bun/bin/*
ln -fs ${{ runner.temp }}/.bun/bin/bun ${{ runner.temp }}/.bun/bin/bunx
echo "${{ runner.temp }}/.bun/bin" >> ${GITHUB_PATH}

View File

@@ -1,40 +0,0 @@
name: clang-format
permissions:
contents: write
on:
workflow_call:
workflow_dispatch:
pull_request:
env:
BUN_VERSION: "1.1.27"
LLVM_VERSION: "18.1.8"
LLVM_VERSION_MAJOR: "18"
jobs:
clang-format:
name: clang-format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install LLVM
run: |
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
- name: Clang Format
env:
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-format
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run clang-format`"

View File

@@ -1,40 +0,0 @@
name: clang-tidy
permissions:
contents: write
on:
workflow_call:
workflow_dispatch:
pull_request:
env:
BUN_VERSION: "1.1.27"
LLVM_VERSION: "18.1.8"
LLVM_VERSION_MAJOR: "18"
jobs:
clang-tidy:
name: clang-tidy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Install LLVM
run: |
curl -fsSL https://apt.llvm.org/llvm.sh | sudo bash -s -- ${{ env.LLVM_VERSION_MAJOR }} all
- name: Clang Tidy
env:
LLVM_VERSION: ${{ env.LLVM_VERSION }}
run: |
bun run clang-tidy:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run clang-tidy`"

61
.github/workflows/format.yml vendored Normal file
View File

@@ -0,0 +1,61 @@
name: Format
permissions:
contents: write
concurrency:
group: format-${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && inputs.run-id || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
run-id:
type: string
description: The workflow ID to download artifacts (skips the build step)
pull_request:
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.prettierrc-ci
.github
.vscode
src
scripts
packages
test
bench
package.json
bun.lockb
.clang-format
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: "1.1.25"
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: 0.13.0
- name: Install Dependencies
run: |
bun install
- name: Format
run: |
bun fmt
- name: Format Zig
run: |
bun fmt:zig
- name: Format Cpp
run: |
bun fmt:cpp
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply formatting changes

View File

@@ -114,4 +114,4 @@ jobs:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ github.event.issue.number }}
body: |
Hello @${{ github.event.issue.user.login }}. Please provide a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) using a GitHub repository, [Replit](https://replit.com/@replit/Bun), [CodeSandbox](https://codesandbox.io/templates/bun), or provide a bulleted list of commands to run that reproduce this issue. Issues marked with `needs repro` will be closed if they have no activity within 3 days.
Hello @${{ github.event.issue.user.login }}. Please provide a [minimal reproduction](https://stackoverflow.com/help/minimal-reproducible-example) using a GitHub repository, [Replit](https://replit.com/@replit/Bun), or [CodeSandbox](https://codesandbox.io/templates/bun). Issues marked with `needs repro` will be closed if they have no activity within 3 days.

30
.github/workflows/lint-cpp.yml vendored Normal file
View File

@@ -0,0 +1,30 @@
name: lint-cpp
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && inputs.run-id || github.ref }}
cancel-in-progress: true
on:
workflow_dispatch:
inputs:
run-id:
type: string
description: The workflow ID to download artifacts (skips the build step)
# pull_request:
# paths:
# - ".github/workflows/lint-cpp.yml"
# - "**/*.cpp"
# - "vendor/**/*"
# - "CMakeLists.txt"
jobs:
lint-cpp:
if: ${{ !inputs.run-id }}
name: Lint C++
uses: ./.github/workflows/run-lint-cpp.yml
secrets: inherit
with:
pr-number: ${{ github.event.number }}

View File

@@ -1,36 +0,0 @@
name: prettier-format
permissions:
contents: write
on:
workflow_call:
workflow_dispatch:
pull_request:
env:
BUN_VERSION: "1.1.27"
jobs:
prettier-format:
name: prettier-format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Setup Dependencies
run: |
bun install
- name: Prettier Format
run: |
bun run prettier:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run prettier:extra`"

56
.github/workflows/run-format.yml vendored Normal file
View File

@@ -0,0 +1,56 @@
name: Format
permissions:
contents: write
on:
workflow_call:
inputs:
zig-version:
type: string
required: true
jobs:
format:
name: Format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.prettierrc-ci
.github
.vscode
src
scripts
packages
test
bench
package.json
bun.lockb
.clang-format
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: "1.1.25"
- name: Setup Zig
uses: mlugg/setup-zig@v1
with:
version: ${{ inputs.zig-version }}
- name: Install Dependencies
run: |
bun install
- name: Format
run: |
bun fmt
- name: Format Zig
run: |
bun fmt:zig
- name: Format Cpp
run: |
bun fmt:cpp
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Apply formatting changes

84
.github/workflows/run-lint-cpp.yml vendored Normal file
View File

@@ -0,0 +1,84 @@
name: lint-cpp
permissions:
contents: read
env:
LLVM_VERSION: 18
LC_CTYPE: "en_US.UTF-8"
LC_ALL: "en_US.UTF-8"
on:
workflow_call:
inputs:
pr-number:
required: true
type: number
jobs:
lint-cpp:
name: Lint C++
runs-on: ${{ github.repository_owner == 'oven-sh' && 'macos-13-xlarge' || 'macos-13' }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: 1.1.23
- name: Install Dependencies
env:
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: 1
HOMEBREW_NO_AUTO_UPDATE: 1
HOMEBREW_NO_INSTALL_CLEANUP: 1
run: |
brew install \
llvm@${{ env.LLVM_VERSION }} \
ninja \
coreutils \
openssl@1.1 \
libiconv \
gnu-sed --force --overwrite
echo "$(brew --prefix coreutils)/libexec/gnubin" >> $GITHUB_PATH
echo "$(brew --prefix llvm@$LLVM_VERSION)/bin" >> $GITHUB_PATH
brew link --overwrite llvm@$LLVM_VERSION
- name: Bun install
run: |
bun install
- name: clang-tidy
id: format
env:
CPU_TARGET: native
BUN_SILENT: 1
run: |
rm -f did_fail format.log
echo "${{ inputs.pr-number }}" > pr-number.txt
echo "pr_number=$(cat pr-number.txt)" >> $GITHUB_OUTPUT
bun run --silent build:tidy &> >(tee -p format.log) && echo 0 > did_succeed.txt
# Upload format.log as github artifact for the workflow
if [ -f did_succeed.txt ]; then
echo "0" > did_fail.txt
else
echo "1" > did_fail.txt
fi
echo "did_fail=$(cat did_fail.txt)" >> $GITHUB_OUTPUT
- name: Upload format.log
uses: actions/upload-artifact@v4
with:
name: format.log
path: format.log
- name: Upload PR
uses: actions/upload-artifact@v4
with:
name: pr-number.txt
path: pr-number.txt
- name: Upload PR
uses: actions/upload-artifact@v4
with:
name: did_fail.txt
path: did_fail.txt
- name: Fail if formatting failed
if: ${{ steps.format.outputs.did_fail == '1' }}
run: exit 1

View File

@@ -1,33 +0,0 @@
name: zig-format
permissions:
contents: write
on:
workflow_call:
workflow_dispatch:
pull_request:
env:
BUN_VERSION: "1.1.27"
jobs:
zig-format:
name: zig-format
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Bun
uses: ./.github/actions/setup-bun
with:
bun-version: ${{ env.BUN_VERSION }}
- name: Zig Format
run: |
bun run zig-format:diff
- name: Commit
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "`bun run zig-format`"

3
.gitignore vendored
View File

@@ -142,6 +142,9 @@ test/node.js/upstream
scripts/env.local
*.generated.ts
# Temporary files
/tmp
# Dependencies
/vendor

31
.prettierrc-ci Normal file
View File

@@ -0,0 +1,31 @@
{
"arrowParens": "avoid",
"printWidth": 120,
"trailingComma": "all",
"useTabs": false,
"quoteProps": "preserve",
"plugins": [
"prettier-plugin-organize-imports"
],
"overrides": [
{
"files": [
".vscode/*.json"
],
"options": {
"parser": "jsonc",
"quoteProps": "preserve",
"singleQuote": false,
"trailingComma": "all"
}
},
{
"files": [
"*.md"
],
"options": {
"printWidth": 80
}
}
]
}

6
.vscode/launch.json generated vendored
View File

@@ -172,10 +172,6 @@
"FORCE_COLOR": "1",
"BUN_DEBUG_QUIET_LOGS": "1",
"BUN_GARBAGE_COLLECTOR_LEVEL": "0",
"BUN_DEBUG_IncrementalGraph": "1",
"BUN_DEBUG_Bake": "1",
"BUN_DEBUG_reload_file_list": "1",
"GOMAXPROCS": "1",
},
"console": "internalConsole",
},
@@ -1196,4 +1192,4 @@
"description": "Usage: bun test [...]",
},
],
}
}

View File

@@ -52,15 +52,12 @@
"cmake.configureOnOpen": false,
"C_Cpp.errorSquiggles": "enabled",
"[cpp]": {
"editor.tabSize": 4,
"editor.defaultFormatter": "xaver.clang-format",
},
"[c]": {
"editor.tabSize": 4,
"editor.defaultFormatter": "xaver.clang-format",
},
"[h]": {
"editor.tabSize": 4,
"editor.defaultFormatter": "xaver.clang-format",
},
"clangd.arguments": ["-header-insertion=never"],

52
.vscode/tasks.json vendored
View File

@@ -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,
},
},
],
}

View File

@@ -30,7 +30,6 @@ include(CompilerFlags)
# --- Tools ---
include(SetupGit)
include(SetupBuildkite)
include(SetupBun)
include(SetupEsbuild)
@@ -39,13 +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 ---
if(ENABLE_ANALYSIS)
include(RunClangFormat)
include(RunClangTidy)
include(RunZigFormat)
include(RunPrettier)
endif()
include(RunClangFormat)
include(RunClangTidy)
include(RunZigFormat)

View File

@@ -116,26 +116,42 @@ $ export PATH="$PATH:/usr/lib/llvm16/bin"
## Building Bun
After cloning the repository, run the following command to build. This may take a while as it will clone submodules and build dependencies.
After cloning the repository, run the following command to run the first build. This may take a while as it will clone submodules and build dependencies.
```bash
$ bun setup
```
The binary will be located at `./build/bun-debug`. It is recommended to add this to your `$PATH`. To verify the build worked, let's print the version number on the development build of Bun.
```bash
$ build/bun-debug --version
x.y.z_debug
```
To rebuild, you can invoke `bun run build`
```bash
$ bun run build
```
The binary will be located at `./build/debug/bun-debug`. It is recommended to add this to your `$PATH`. To verify the build worked, let's print the version number on the development build of Bun.
These two scripts, `setup` and `build`, are aliases to do roughly the following:
```bash
$ build/debug/bun-debug --version
x.y.z_debug
$ ./scripts/setup.sh
$ cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug
$ ninja -C build # 'bun run build' runs just this
```
Advanced users can pass CMake flags to customize the build.
## VSCode
VSCode is the recommended IDE for working on Bun, as it has been configured. Once opening, you can run `Extensions: Show Recommended Extensions` to install the recommended extensions for Zig and C++. ZLS is automatically configured.
If you use a different editor, make sure that you tell ZLS to use the automatically installed Zig compiler, which is located at `./vendor/zig/zig.exe`. The filename is `zig.exe` so that it works as expected on Windows, but it still works on macOS/Linux (it just has a surprising file extension).
If you use a different editor, make sure that you tell ZLS to use the automatically installed Zig compiler, which is located at `./.cache/zig/zig.exe`. The filename is `zig.exe` so that it works as expected on Windows, but it still works on macOS/Linux (it just has a surprising file extension).
We recommend adding `./build/debug` to your `$PATH` so that you can run `bun-debug` in your terminal:
We recommend adding `./build` to your `$PATH` so that you can run `bun-debug` in your terminal:
```sh
$ bun-debug
@@ -164,7 +180,7 @@ To compile a release build of Bun, run:
$ bun run build:release
```
The binary will be located at `./build/release/bun` and `./build/release/bun-profile`.
The binary will be located at `./build-release/bun` and `./build-release/bun-profile`.
### Download release build from pull requests
@@ -173,8 +189,8 @@ To save you time spent building a release build locally, we provide a way to run
To run a release build from a pull request, you can use the `bun-pr` npm package:
```sh
bunx bun-pr <pr-number>
bunx bun-pr <branch-name>
bunx bun-pr pr-number
bunx bun-pr branch/branch-name
bunx bun-pr "https://github.com/oven-sh/bun/pull/1234566"
```
@@ -206,18 +222,24 @@ $ valgrind --fair-sched=try --track-origins=yes bun-debug <args>
## Building WebKit locally + Debug mode of JSC
{% callout %}
**TODO**: This is out of date. TLDR is pass `-DUSE_DEBUG_JSC=1` or `-DWEBKIT_DIR=...` to CMake. it will probably need more fiddling. ask @paperdave if you need this.
{% /callout %}
WebKit is not cloned by default (to save time and disk space). To clone and build WebKit locally, run:
```bash
# Clone WebKit into ./vendor/WebKit
$ git clone https://github.com/oven-sh/WebKit vendor/WebKit
# Make a debug build of JSC. This will output build artifacts in ./vendor/WebKit/WebKitBuild/Debug
# Optionally, you can use `make jsc` for a release build
$ make jsc-debug
# Build bun with the local JSC build
$ bun run build:local
# once you run this, `make submodule` can be used to automatically
# update WebKit and the other submodules
$ git submodule update --init --depth 1 --checkout src/bun.js/WebKit
# to make a jsc release build
$ make jsc
# JSC debug build does not work perfectly with Bun yet, this is actively being
# worked on and will eventually become the default.
$ make jsc-build-linux-compile-debug cpp
$ make jsc-build-mac-compile-debug cpp
```
Note that the WebKit folder, including build artifacts, is 8GB+ in size.

2
LATEST
View File

@@ -1 +1 @@
1.1.30
1.1.27

View File

@@ -77,7 +77,7 @@ BUN_RELEASE_BIN = $(PACKAGE_DIR)/bun
PRETTIER ?= $(shell which prettier 2>/dev/null || echo "./node_modules/.bin/prettier")
ESBUILD = "$(shell which esbuild 2>/dev/null || echo "./node_modules/.bin/esbuild")"
DSYMUTIL ?= $(shell which dsymutil 2>/dev/null || which dsymutil-15 2>/dev/null)
WEBKIT_DIR ?= $(realpath vendor/WebKit)
WEBKIT_DIR ?= $(realpath src/bun.js/WebKit)
WEBKIT_RELEASE_DIR ?= $(WEBKIT_DIR)/WebKitBuild/Release
WEBKIT_DEBUG_DIR ?= $(WEBKIT_DIR)/WebKitBuild/Debug
WEBKIT_RELEASE_DIR_LTO ?= $(WEBKIT_DIR)/WebKitBuild/ReleaseLTO
@@ -138,8 +138,8 @@ endif
SED = $(shell which gsed 2>/dev/null || which sed 2>/dev/null)
BUN_DIR ?= $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
BUN_DEPS_DIR ?= $(shell pwd)/vendor
BUN_DEPS_OUT_DIR ?= $(shell pwd)/build/release
BUN_DEPS_DIR ?= $(shell pwd)/src/deps
BUN_DEPS_OUT_DIR ?= $(shell pwd)/build/bun-deps
CPU_COUNT = 2
ifeq ($(OS_NAME),darwin)
CPU_COUNT = $(shell sysctl -n hw.logicalcpu)
@@ -689,10 +689,19 @@ assert-deps:
@test $(shell cargo --version | awk '{print $$2}' | cut -d. -f2) -gt 57 || (echo -e "ERROR: cargo version must be at least 1.57."; exit 1)
@echo "You have the dependencies installed! Woo"
# the following allows you to run `make submodule` to update or init submodules. but we will exclude webkit
# unless you explicitly clone it yourself (a huge download)
SUBMODULE_NAMES=$(shell cat .gitmodules | grep 'path = ' | awk '{print $$3}')
ifeq ("$(wildcard src/bun.js/WebKit/.git)", "")
SUBMODULE_NAMES := $(filter-out src/bun.js/WebKit, $(SUBMODULE_NAMES))
endif
.PHONY: init-submodules
init-submodules: submodule # (backwards-compatibility alias)
.PHONY: submodule
submodule: ## to init or update all submodules
git submodule update --init --recursive --progress --depth=1 --checkout $(SUBMODULE_NAMES)
.PHONY: build-obj
build-obj:
@@ -795,7 +804,7 @@ cls:
@echo -e "\n\n---\n\n"
jsc-check:
@ls $(JSC_BASE_DIR) >/dev/null 2>&1 || (echo -e "Failed to access WebKit build. Please compile the WebKit submodule using the Dockerfile at $(shell pwd)/src/javascript/WebKit/Dockerfile and then copy from /output in the Docker container to $(JSC_BASE_DIR). You can override the directory via JSC_BASE_DIR. \n\n DOCKER_BUILDKIT=1 docker build -t bun-webkit $(shell pwd)/vendor/WebKit -f $(shell pwd)/vendor/WebKit/Dockerfile --progress=plain\n\n docker container create bun-webkit\n\n # Get the container ID\n docker container ls\n\n docker cp DOCKER_CONTAINER_ID_YOU_JUST_FOUND:/output $(JSC_BASE_DIR)" && exit 1)
@ls $(JSC_BASE_DIR) >/dev/null 2>&1 || (echo -e "Failed to access WebKit build. Please compile the WebKit submodule using the Dockerfile at $(shell pwd)/src/javascript/WebKit/Dockerfile and then copy from /output in the Docker container to $(JSC_BASE_DIR). You can override the directory via JSC_BASE_DIR. \n\n DOCKER_BUILDKIT=1 docker build -t bun-webkit $(shell pwd)/src/bun.js/WebKit -f $(shell pwd)/src/bun.js/WebKit/Dockerfile --progress=plain\n\n docker container create bun-webkit\n\n # Get the container ID\n docker container ls\n\n docker cp DOCKER_CONTAINER_ID_YOU_JUST_FOUND:/output $(JSC_BASE_DIR)" && exit 1)
@ls $(JSC_INCLUDE_DIR) >/dev/null 2>&1 || (echo "Failed to access WebKit include directory at $(JSC_INCLUDE_DIR)." && exit 1)
@ls $(JSC_LIB) >/dev/null 2>&1 || (echo "Failed to access WebKit lib directory at $(JSC_LIB)." && exit 1)
@@ -936,7 +945,7 @@ jsc-bindings: headers bindings
.PHONY: clone-submodules
clone-submodules:
git -c submodule."vendor/WebKit".update=none submodule update --init --recursive --depth=1 --progress
git -c submodule."src/bun.js/WebKit".update=none submodule update --init --recursive --depth=1 --progress
.PHONY: headers
@@ -1256,7 +1265,7 @@ jsc-build-mac-compile:
-DENABLE_STATIC_JSC=ON \
-DENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE=ON \
-DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_THIN_ARCHIVES=OFF \
-DBUN_FAST_TLS=ON \
-DENABLE_FTL_JIT=ON \
@@ -1268,7 +1277,7 @@ jsc-build-mac-compile:
$(WEBKIT_DIR) \
$(WEBKIT_RELEASE_DIR) && \
CFLAGS="$(CFLAGS) -ffat-lto-objects" CXXFLAGS="$(CXXFLAGS) -ffat-lto-objects" \
cmake --build $(WEBKIT_RELEASE_DIR) --config RelWithDebInfo --target jsc
cmake --build $(WEBKIT_RELEASE_DIR) --config Release --target jsc
.PHONY: jsc-build-mac-compile-lto
jsc-build-mac-compile-lto:
@@ -1370,7 +1379,7 @@ jsc-build-linux-compile-config-debug:
$(WEBKIT_DEBUG_DIR)
# If you get "Error: could not load cache"
# run rm -rf vendor/WebKit/CMakeCache.txt
# run rm -rf src/bun.js/WebKit/CMakeCache.txt
.PHONY: jsc-build-linux-compile-build
jsc-build-linux-compile-build:
mkdir -p $(WEBKIT_RELEASE_DIR) && \
@@ -1405,7 +1414,7 @@ jsc-build-copy-debug:
cp $(WEBKIT_DEBUG_DIR)/lib/libbmalloc.a $(BUN_DEPS_OUT_DIR)/libbmalloc.a
clean-jsc:
cd vendor/WebKit && rm -rf **/CMakeCache.txt **/CMakeFiles && rm -rf vendor/WebKit/WebKitBuild
cd src/bun.js/WebKit && rm -rf **/CMakeCache.txt **/CMakeFiles && rm -rf src/bun.js/WebKit/WebKitBuild
clean-bindings:
rm -rf $(OBJ_DIR)/*.o $(DEBUG_OBJ_DIR)/*.o $(DEBUG_OBJ_DIR)/webcore/*.o $(DEBUG_BINDINGS_OBJ) $(OBJ_DIR)/webcore/*.o $(BINDINGS_OBJ) $(OBJ_DIR)/*.d $(DEBUG_OBJ_DIR)/*.d

Binary file not shown.

View File

@@ -1,24 +0,0 @@
import { bench, run } from "mitata";
const crypto = require("node:crypto");
const keyPair = crypto.generateKeyPairSync("rsa", {
modulusLength: 2048,
publicKeyEncoding: {
type: "spki",
format: "pem",
},
privateKeyEncoding: {
type: "pkcs8",
format: "pem",
},
});
// Max message size for 2048-bit RSA keys
const plaintext = crypto.getRandomValues(Buffer.alloc(245));
bench("RSA sign RSA_PKCS1_PADDING round-trip", () => {
const sig = crypto.privateEncrypt(keyPair.privateKey, plaintext);
crypto.publicDecrypt(keyPair.publicKey, sig);
});
await run();

View File

@@ -7,7 +7,6 @@
"@swc/core": "^1.2.133",
"benchmark": "^2.1.4",
"braces": "^3.0.2",
"color": "^4.2.3",
"esbuild": "^0.14.12",
"eventemitter3": "^5.0.0",
"execa": "^8.0.1",
@@ -15,7 +14,6 @@
"fdir": "^6.1.0",
"mitata": "^0.1.6",
"string-width": "7.1.0",
"tinycolor2": "^1.6.0",
"zx": "^7.2.3"
},
"scripts": {

View File

@@ -1,25 +0,0 @@
import Color from "color";
import tinycolor from "tinycolor2";
import { bench, group, run } from "./runner.mjs";
const inputs = ["#f00", "rgb(255, 0, 0)", "rgba(255, 0, 0, 1)", "hsl(0, 100%, 50%)"];
for (const input of inputs) {
group(`${input}`, () => {
if (typeof Bun !== "undefined") {
bench("Bun.color()", () => {
Bun.color(input, "css");
});
}
bench("color", () => {
Color(input).hex();
});
bench("'tinycolor2'", () => {
tinycolor(input).toHexString();
});
});
}
await run();

View File

@@ -52,14 +52,14 @@ const BunBuildOptions = struct {
/// instead of at compile time. This is disabled in release or if this flag
/// is set (to allow CI to build a portable executable). Affected files:
///
/// - src/bake/runtime.ts (bundled)
/// - src/kit/runtime.ts (bundled)
/// - src/bun.js/api/FFI.h
///
/// A similar technique is used in C++ code for JavaScript builtins
codegen_embed: bool = false,
force_embed_code: bool = false,
/// `./build/codegen` or equivalent
codegen_path: []const u8,
generated_code_dir: []const u8,
no_llvm: bool,
cached_options_module: ?*Module = null,
@@ -71,7 +71,7 @@ const BunBuildOptions = struct {
}
pub fn shouldEmbedCode(opts: *const BunBuildOptions) bool {
return opts.optimize != .Debug or opts.codegen_embed;
return opts.optimize != .Debug or opts.force_embed_code;
}
pub fn buildOptionsModule(this: *BunBuildOptions, b: *Build) *Module {
@@ -83,10 +83,10 @@ const BunBuildOptions = struct {
opts.addOption([]const u8, "base_path", b.pathFromRoot("."));
opts.addOption([]const u8, "codegen_path", std.fs.path.resolve(b.graph.arena, &.{
b.build_root.path.?,
this.codegen_path,
this.generated_code_dir,
}) catch @panic("OOM"));
opts.addOption(bool, "codegen_embed", this.shouldEmbedCode());
opts.addOption(bool, "embed_code", this.shouldEmbedCode());
opts.addOption(u32, "canary_revision", this.canary_revision orelse 0);
opts.addOption(bool, "is_canary", this.canary_revision != null);
opts.addOption(Version, "version", this.version);
@@ -157,7 +157,7 @@ pub fn build(b: *Build) !void {
// TODO: Upgrade path for 0.14.0
// b.graph.zig_lib_directory = brk: {
// const sub_path = "vendor/zig/lib";
// const sub_path = "src/deps/zig/lib";
// const dir = try b.build_root.handle.openDir(sub_path, .{});
// break :brk .{ .handle = dir, .path = try b.build_root.join(b.graph.arena, &.{sub_path}) };
// };
@@ -195,13 +195,12 @@ pub fn build(b: *Build) !void {
const target = b.resolveTargetQuery(target_query);
const codegen_path = b.pathFromRoot(
b.option([]const u8, "codegen_path", "Set the generated code directory") orelse
const generated_code_dir = b.pathFromRoot(
b.option([]const u8, "generated-code", "Set the generated code directory") orelse
"build/debug/codegen",
);
const codegen_embed = b.option(bool, "codegen_embed", "If codegen files should be embedded in the binary") orelse false;
const bun_version = b.option([]const u8, "version", "Value of `Bun.version`") orelse "0.0.0";
const force_embed_js_code = b.option(bool, "force_embed_js_code", "Always embed JavaScript builtins") orelse false;
b.reference_trace = ref_trace: {
const trace = b.option(u32, "reference-trace", "Set the reference trace") orelse 16;
@@ -219,8 +218,8 @@ pub fn build(b: *Build) !void {
.os = os,
.arch = arch,
.codegen_path = codegen_path,
.codegen_embed = codegen_embed,
.generated_code_dir = generated_code_dir,
.force_embed_code = force_embed_js_code,
.no_llvm = no_llvm,
.version = try Version.parse(bun_version),
@@ -296,7 +295,7 @@ pub fn build(b: *Build) !void {
bun_check_obj.generated_bin = null;
step.dependOn(&bun_check_obj.step);
// The default install step will run zig build check. This is so ZLS
// The default install step will run zig build check This is so ZLS
// identifies the codebase, as well as performs checking if build on
// save is enabled.
@@ -352,7 +351,7 @@ pub inline fn addMultiCheck(
.tracy_callstack_depth = root_build_options.tracy_callstack_depth,
.version = root_build_options.version,
.reported_nodejs_version = root_build_options.reported_nodejs_version,
.codegen_path = root_build_options.codegen_path,
.generated_code_dir = root_build_options.generated_code_dir,
.no_llvm = root_build_options.no_llvm,
};
@@ -369,7 +368,6 @@ pub fn addBunObject(b: *Build, opts: *BunBuildOptions) *Compile {
.root_source_file = switch (opts.os) {
.wasm => b.path("root_wasm.zig"),
else => b.path("root.zig"),
// else => b.path("root_css.zig"),
},
.target = opts.target,
.optimize = opts.optimize,
@@ -476,45 +474,13 @@ fn addInternalPackages(b: *Build, obj: *Compile, opts: *BunBuildOptions) void {
.{ .file = "ZigGeneratedClasses.zig", .import = "ZigGeneratedClasses" },
.{ .file = "ResolvedSourceTag.zig", .import = "ResolvedSourceTag" },
.{ .file = "ErrorCode.zig", .import = "ErrorCode" },
.{ .file = "runtime.out.js" },
.{ .file = "bake.client.js", .import = "bake-codegen/bake.client.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bake.error.js", .import = "bake-codegen/bake.error.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bake.server.js", .import = "bake-codegen/bake.server.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bun-error/index.js", .enable = opts.shouldEmbedCode() },
.{ .file = "bun-error/bun-error.css", .enable = opts.shouldEmbedCode() },
.{ .file = "fallback-decoder.js", .enable = opts.shouldEmbedCode() },
.{ .file = "node-fallbacks/assert.js" },
.{ .file = "node-fallbacks/buffer.js" },
.{ .file = "node-fallbacks/console.js" },
.{ .file = "node-fallbacks/constants.js" },
.{ .file = "node-fallbacks/crypto.js" },
.{ .file = "node-fallbacks/domain.js" },
.{ .file = "node-fallbacks/events.js" },
.{ .file = "node-fallbacks/http.js" },
.{ .file = "node-fallbacks/https.js" },
.{ .file = "node-fallbacks/net.js" },
.{ .file = "node-fallbacks/os.js" },
.{ .file = "node-fallbacks/path.js" },
.{ .file = "node-fallbacks/process.js" },
.{ .file = "node-fallbacks/punycode.js" },
.{ .file = "node-fallbacks/querystring.js" },
.{ .file = "node-fallbacks/stream.js" },
.{ .file = "node-fallbacks/string_decoder.js" },
.{ .file = "node-fallbacks/sys.js" },
.{ .file = "node-fallbacks/timers.js" },
.{ .file = "node-fallbacks/tty.js" },
.{ .file = "node-fallbacks/url.js" },
.{ .file = "node-fallbacks/util.js" },
.{ .file = "node-fallbacks/zlib.js" },
.{ .file = "kit.client.js", .import = "kit-codegen/kit.client.js", .enable = opts.shouldEmbedCode() },
.{ .file = "kit.server.js", .import = "kit-codegen/kit.server.js", .enable = opts.shouldEmbedCode() },
}) |entry| {
if (!@hasField(@TypeOf(entry), "enable") or entry.enable) {
const path = b.pathJoin(&.{ opts.codegen_path, entry.file });
const path = b.pathJoin(&.{ opts.generated_code_dir, entry.file });
validateGeneratedPath(path);
const import_path = if (@hasField(@TypeOf(entry), "import"))
entry.import
else
entry.file;
obj.root_module.addAnonymousImport(import_path, .{
obj.root_module.addAnonymousImport(entry.import, .{
.root_source_file = .{ .cwd_relative = path },
});
}

BIN
bun.lockb

Binary file not shown.

View File

@@ -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.

File diff suppressed because it is too large Load Diff

View File

@@ -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)
@@ -91,8 +91,6 @@ if(LINUX)
optionx(ENABLE_VALGRIND BOOL "If Valgrind support should be enabled" DEFAULT OFF)
endif()
optionx(ENABLE_PRETTIER BOOL "If prettier should be ran" DEFAULT OFF)
if(USE_VALGRIND AND NOT USE_BASELINE)
message(WARNING "If valgrind is enabled, baseline must also be enabled")
setx(USE_BASELINE ON)
@@ -145,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)

View File

@@ -1,12 +1,12 @@
# https://clang.llvm.org/docs/ClangFormat.html
file(GLOB BUN_H_SOURCES LIST_DIRECTORIES false ${CONFIGURE_DEPENDS}
${CWD}/src/bun.js/bindings/*.h
${CWD}/src/bun.js/modules/*.h
find_command(
VARIABLE
CLANG_FORMAT_PROGRAM
COMMAND
clang-format
REQUIRED
OFF
)
set(CLANG_FORMAT_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES} ${BUN_H_SOURCES})
register_command(
TARGET
clang-format-check
@@ -17,8 +17,8 @@ register_command(
-Werror
--dry-run
--verbose
${CLANG_FORMAT_SOURCES}
ALWAYS_RUN
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
)
register_command(
@@ -30,38 +30,6 @@ register_command(
${CLANG_FORMAT_PROGRAM}
-i # edits files in-place
--verbose
${CLANG_FORMAT_SOURCES}
ALWAYS_RUN
)
if(GIT_CHANGED_SOURCES)
set(CLANG_FORMAT_CHANGED_SOURCES)
foreach(source ${CLANG_FORMAT_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND CLANG_FORMAT_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()
if(CLANG_FORMAT_CHANGED_SOURCES)
set(CLANG_FORMAT_DIFF_COMMAND ${CLANG_FORMAT_PROGRAM}
-i # edits files in-place
--verbose
${CLANG_FORMAT_CHANGED_SOURCES}
)
else()
set(CLANG_FORMAT_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for clang-format")
endif()
register_command(
TARGET
clang-format-diff
COMMENT
"Running clang-format on changed files"
COMMAND
${CLANG_FORMAT_DIFF_COMMAND}
CWD
${BUILD_PATH}
ALWAYS_RUN
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
)

View File

@@ -1,14 +1,70 @@
# https://clang.llvm.org/extra/clang-tidy/
find_command(
VARIABLE
CLANG_TIDY_PROGRAM
COMMAND
clang-tidy
VERSION
${LLVM_VERSION}
REQUIRED
OFF
)
set(CLANG_TIDY_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})
set(CLANG_TIDY_COMMAND ${CLANG_TIDY_PROGRAM}
-p ${BUILD_PATH}
--config-file=${CWD}/.clang-tidy
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()
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(
@@ -17,58 +73,7 @@ register_command(
COMMENT
"Running clang-tidy"
COMMAND
${CLANG_TIDY_COMMAND}
${CLANG_TIDY_SOURCES}
--fix
--fix-errors
--fix-notes
${CLANG_TIDY_COMMAND}
CWD
${BUILD_PATH}
ALWAYS_RUN
)
register_command(
TARGET
clang-tidy-check
COMMENT
"Checking clang-tidy"
COMMAND
${CLANG_TIDY_COMMAND}
${CLANG_TIDY_SOURCES}
CWD
${BUILD_PATH}
ALWAYS_RUN
)
if(GIT_CHANGED_SOURCES)
set(CLANG_TIDY_CHANGED_SOURCES)
foreach(source ${CLANG_TIDY_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND CLANG_TIDY_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()
if(CLANG_TIDY_CHANGED_SOURCES)
set(CLANG_TIDY_DIFF_COMMAND ${CLANG_TIDY_PROGRAM}
${CLANG_TIDY_CHANGED_SOURCES}
--fix
--fix-errors
--fix-notes
)
else()
set(CLANG_TIDY_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for clang-tidy")
endif()
register_command(
TARGET
clang-tidy-diff
COMMENT
"Running clang-tidy on changed files"
COMMAND
${CLANG_TIDY_DIFF_COMMAND}
CWD
${BUILD_PATH}
ALWAYS_RUN
)

View File

@@ -1,7 +1,7 @@
# IWYU = "Include What You Use"
# https://include-what-you-use.org/
setx(IWYU_SOURCE_PATH ${CACHE_PATH}/iwyu-${LLVM_VERSION})
setx(IWYU_SOURCE_PATH ${CACHE_PATH}/iwyu-${LLVM_VERSION_MAJOR})
setx(IWYU_BUILD_PATH ${IWYU_SOURCE_PATH}/build)
setx(IWYU_PROGRAM ${IWYU_BUILD_PATH}/bin/include-what-you-use)
@@ -11,7 +11,7 @@ register_repository(
REPOSITORY
include-what-you-use/include-what-you-use
BRANCH
clang_${LLVM_VERSION}
clang_${LLVM_VERSION_MAJOR}
PATH
${IWYU_SOURCE_PATH}
)

View File

@@ -1,123 +0,0 @@
if(CMAKE_HOST_WIN32)
setx(PRETTIER_EXECUTABLE ${CWD}/node_modules/.bin/prettier.exe)
else()
setx(PRETTIER_EXECUTABLE ${CWD}/node_modules/.bin/prettier)
endif()
set(PRETTIER_PATHS
${CWD}/src
${CWD}/packages/bun-error
${CWD}/packages/bun-types
${CWD}/packages/bun-inspector-protocol
${CWD}/packages/bun-inspector-frontend
${CWD}/packages/bun-debug-adapter-protocol
${CWD}/packages/bun-vscode
${CWD}/test
${CWD}/bench
${CWD}/.vscode
${CWD}/.buildkite
${CWD}/.github
)
set(PRETTIER_EXTENSIONS
*.jsonc?
*.ya?ml
*.jsx?
*.tsx?
*.mjs
*.cjs
*.mts
*.cts
)
set(PRETTIER_GLOBS)
foreach(path ${PRETTIER_PATHS})
foreach(extension ${PRETTIER_EXTENSIONS})
list(APPEND PRETTIER_GLOBS ${path}/${extension})
endforeach()
endforeach()
file(GLOB_RECURSE PRETTIER_SOURCES ${PRETTIER_GLOBS})
register_command(
COMMAND
${BUN_EXECUTABLE}
install
--frozen-lockfile
SOURCES
${CWD}/package.json
OUTPUTS
${PRETTIER_EXECUTABLE}
)
set(PRETTIER_COMMAND ${PRETTIER_EXECUTABLE}
--config=${CWD}/.prettierrc
--cache
)
register_command(
TARGET
prettier
COMMENT
"Running prettier"
COMMAND
${PRETTIER_COMMAND}
--write
${PRETTIER_SOURCES}
ALWAYS_RUN
)
register_command(
TARGET
prettier-extra
COMMENT
"Running prettier with extra plugins"
COMMAND
${PRETTIER_COMMAND}
--write
--plugin=prettier-plugin-organize-imports
${PRETTIER_SOURCES}
ALWAYS_RUN
)
register_command(
TARGET
prettier-check
COMMENT
"Checking prettier"
COMMAND
${PRETTIER_COMMAND}
--check
${PRETTIER_SOURCES}
ALWAYS_RUN
)
if(GIT_CHANGED_SOURCES)
set(PRETTIER_CHANGED_SOURCES)
foreach(source ${PRETTIER_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND PRETTIER_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()
if(PRETTIER_CHANGED_SOURCES)
set(PRETTIER_DIFF_COMMAND ${PRETTIER_COMMAND}
--write
--plugin=prettier-plugin-organize-imports
${PRETTIER_CHANGED_SOURCES}
)
else()
set(PRETTIER_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for prettier")
endif()
register_command(
TARGET
prettier-diff
COMMENT
"Running prettier on changed files"
COMMAND
${PRETTIER_DIFF_COMMAND}
ALWAYS_RUN
)

View File

@@ -1,5 +1,3 @@
set(ZIG_FORMAT_SOURCES ${BUN_ZIG_SOURCES})
register_command(
TARGET
zig-format-check
@@ -9,8 +7,7 @@ register_command(
${ZIG_EXECUTABLE}
fmt
--check
${ZIG_FORMAT_SOURCES}
ALWAYS_RUN
${BUN_ZIG_SOURCES}
)
register_command(
@@ -21,37 +18,5 @@ register_command(
COMMAND
${ZIG_EXECUTABLE}
fmt
${ZIG_FORMAT_SOURCES}
ALWAYS_RUN
)
if(GIT_CHANGED_SOURCES)
set(ZIG_FORMAT_CHANGED_SOURCES)
foreach(source ${ZIG_FORMAT_SOURCES})
list(FIND GIT_CHANGED_SOURCES ${source} index)
if(NOT ${index} EQUAL -1)
list(APPEND ZIG_FORMAT_CHANGED_SOURCES ${source})
endif()
endforeach()
endif()
if(ZIG_FORMAT_CHANGED_SOURCES)
set(ZIG_FORMAT_DIFF_COMMAND ${ZIG_EXECUTABLE}
fmt
${ZIG_FORMAT_CHANGED_SOURCES}
)
else()
set(ZIG_FORMAT_DIFF_COMMAND ${CMAKE_COMMAND} -E echo "No changed files for zig-format")
endif()
register_command(
TARGET
zig-format-diff
COMMENT
"Running zig fmt on changed files"
COMMAND
${ZIG_FORMAT_DIFF_COMMAND}
CWD
${BUILD_PATH}
ALWAYS_RUN
${BUN_ZIG_SOURCES}
)

View File

@@ -125,5 +125,7 @@ else()
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})
message(STATUS "Saved ${DOWNLOAD_PATH}")

View File

@@ -1,8 +1,21 @@
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
message(STATUS "Running script: ${SCRIPT_NAME}")
if(NOT ZIG_PATH OR NOT ZIG_COMMIT OR NOT ZIG_VERSION)
message(FATAL_ERROR "ZIG_PATH, ZIG_COMMIT, and ZIG_VERSION are required")
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)
@@ -38,6 +51,7 @@ else()
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(
@@ -58,7 +72,7 @@ if(NOT ZIG_DOWNLOAD_RESULT EQUAL 0)
endif()
if(NOT EXISTS ${ZIG_PATH}/${ZIG_EXE})
message(FATAL_ERROR "Executable not found: \"${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
@@ -67,30 +81,31 @@ if(NOT WIN32)
file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC)
endif()
set(ZIG_REPOSITORY_PATH ${ZIG_PATH}/repository)
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_REPOSITORY_PATH}
-DGIT_REPOSITORY=oven-sh/zig
-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
)
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}")
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()
file(REMOVE_RECURSE ${ZIG_PATH}/lib)
# Use copy_directory instead of file(RENAME) because there were
# race conditions in CI where some files were not copied.
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${ZIG_REPOSITORY_PATH}/lib ${ZIG_PATH}/lib)
file(REMOVE_RECURSE ${ZIG_REPOSITORY_PATH})
message(STATUS "Saved ${ZIG_EXE}")

View File

@@ -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
)

View File

@@ -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
)

View File

@@ -12,25 +12,10 @@ 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)
if(RELEASE OR CI)
set(DEFAULT_CODEGEN_EMBED ON)
else()
set(DEFAULT_CODEGEN_EMBED OFF)
endif()
optionx(CODEGEN_EMBED BOOL "If codegen files should be embedded in the binary" DEFAULT ${DEFAULT_CODEGEN_EMBED})
if((NOT DEFINED CONFIGURE_DEPENDS AND NOT CI) OR CONFIGURE_DEPENDS)
set(CONFIGURE_DEPENDS "CONFIGURE_DEPENDS")
else()
@@ -39,6 +24,37 @@ endif()
# --- Codegen ---
set(BUN_ZIG_IDENTIFIER_SOURCE ${CWD}/src/js_lexer)
set(BUN_ZIG_IDENTIFIER_SCRIPT ${BUN_ZIG_IDENTIFIER_SOURCE}/identifier_data.zig)
file(GLOB BUN_ZIG_IDENTIFIER_SOURCES ${CONFIGURE_DEPENDS}
${BUN_ZIG_IDENTIFIER_SCRIPT}
${BUN_ZIG_IDENTIFIER_SOURCE}/*.zig
)
set(BUN_ZIG_IDENTIFIER_OUTPUTS
${BUN_ZIG_IDENTIFIER_SOURCE}/id_continue_bitset.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_continue_bitset.meta.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_start_bitset.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_start_bitset.meta.blob
)
register_command(
TARGET
bun-identifier-data
COMMENT
"Generating src/js_lexer/*.blob"
COMMAND
${ZIG_EXECUTABLE}
run
${CMAKE_ZIG_FLAGS}
${BUN_ZIG_IDENTIFIER_SCRIPT}
SOURCES
${BUN_ZIG_IDENTIFIER_SOURCES}
OUTPUTS
${BUN_ZIG_IDENTIFIER_OUTPUTS}
)
set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error)
file(GLOB BUN_ERROR_SOURCES ${CONFIGURE_DEPENDS}
@@ -49,7 +65,7 @@ file(GLOB BUN_ERROR_SOURCES ${CONFIGURE_DEPENDS}
${BUN_ERROR_SOURCE}/img/*
)
set(BUN_ERROR_OUTPUT ${CODEGEN_PATH}/bun-error)
set(BUN_ERROR_OUTPUT ${BUN_ERROR_SOURCE}/dist)
set(BUN_ERROR_OUTPUTS
${BUN_ERROR_OUTPUT}/index.js
${BUN_ERROR_OUTPUT}/bun-error.css
@@ -87,13 +103,13 @@ register_command(
)
set(BUN_FALLBACK_DECODER_SOURCE ${CWD}/src/fallback.ts)
set(BUN_FALLBACK_DECODER_OUTPUT ${CODEGEN_PATH}/fallback-decoder.js)
set(BUN_FALLBACK_DECODER_OUTPUT ${CWD}/src/fallback.out.js)
register_command(
TARGET
bun-fallback-decoder
COMMENT
"Building fallback-decoder.js"
"Building src/fallback.out.js"
COMMAND
${ESBUILD_EXECUTABLE} ${ESBUILD_ARGS}
${BUN_FALLBACK_DECODER_SOURCE}
@@ -110,7 +126,7 @@ register_command(
)
set(BUN_RUNTIME_JS_SOURCE ${CWD}/src/runtime.bun.js)
set(BUN_RUNTIME_JS_OUTPUT ${CODEGEN_PATH}/runtime.out.js)
set(BUN_RUNTIME_JS_OUTPUT ${CWD}/src/runtime.out.js)
register_command(
TARGET
@@ -140,7 +156,7 @@ file(GLOB BUN_NODE_FALLBACKS_SOURCES ${CONFIGURE_DEPENDS}
${BUN_NODE_FALLBACKS_SOURCE}/*.js
)
set(BUN_NODE_FALLBACKS_OUTPUT ${CODEGEN_PATH}/node-fallbacks)
set(BUN_NODE_FALLBACKS_OUTPUT ${BUN_NODE_FALLBACKS_SOURCE}/out)
set(BUN_NODE_FALLBACKS_OUTPUTS)
foreach(source ${BUN_NODE_FALLBACKS_SOURCES})
get_filename_component(filename ${source} NAME)
@@ -160,7 +176,7 @@ register_command(
TARGET
bun-node-fallbacks
COMMENT
"Building node-fallbacks/*.js"
"Building src/node-fallbacks/*.js"
CWD
${BUN_NODE_FALLBACKS_SOURCE}
COMMAND
@@ -297,41 +313,40 @@ register_command(
${BUN_JAVASCRIPT_OUTPUTS}
)
set(BUN_BAKE_RUNTIME_CODEGEN_SCRIPT ${CWD}/src/codegen/bake-codegen.ts)
set(BUN_KIT_RUNTIME_CODEGEN_SCRIPT ${CWD}/src/codegen/kit-codegen.ts)
file(GLOB_RECURSE BUN_BAKE_RUNTIME_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/bake/*.ts
${CWD}/src/bake/*/*.ts
${CWD}/src/bake/*/*.css
file(GLOB_RECURSE BUN_KIT_RUNTIME_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/kit/*.ts
${CWD}/src/kit/*/*.ts
)
list(APPEND BUN_BAKE_RUNTIME_CODEGEN_SOURCES
list(APPEND BUN_KIT_RUNTIME_CODEGEN_SOURCES
${CWD}/src/bun.js/bindings/InternalModuleRegistry.cpp
)
set(BUN_BAKE_RUNTIME_OUTPUTS
${CODEGEN_PATH}/bake.client.js
${CODEGEN_PATH}/bake.server.js
set(BUN_KIT_RUNTIME_OUTPUTS
${CODEGEN_PATH}/kit_empty_file
${CODEGEN_PATH}/kit.client.js
${CODEGEN_PATH}/kit.server.js
)
register_command(
TARGET
bun-bake-codegen
bun-kit-codegen
COMMENT
"Bundling Kit Runtime"
COMMAND
${BUN_EXECUTABLE}
run
${BUN_BAKE_RUNTIME_CODEGEN_SCRIPT}
${BUN_KIT_RUNTIME_CODEGEN_SCRIPT}
--debug=${DEBUG}
--codegen_root=${CODEGEN_PATH}
SOURCES
${BUN_BAKE_RUNTIME_SOURCES}
${BUN_BAKE_RUNTIME_CODEGEN_SOURCES}
${BUN_BAKE_RUNTIME_CODEGEN_SCRIPT}
${BUN_KIT_RUNTIME_SOURCES}
${BUN_KIT_RUNTIME_CODEGEN_SOURCES}
${BUN_KIT_RUNTIME_CODEGEN_SCRIPT}
OUTPUTS
${CODEGEN_PATH}/bake_empty_file
${BUN_BAKE_RUNTIME_OUTPUTS}
${BUN_KIT_RUNTIME_OUTPUTS}
)
set(BUN_JS_SINK_SCRIPT ${CWD}/src/codegen/generate-jssink.ts)
@@ -372,7 +387,6 @@ set(BUN_OBJECT_LUT_SOURCES
${CWD}/src/bun.js/bindings/BunProcess.cpp
${CWD}/src/bun.js/bindings/ProcessBindingConstants.cpp
${CWD}/src/bun.js/bindings/ProcessBindingNatives.cpp
${CWD}/src/bun.js/modules/NodeModuleModule.cpp
)
set(BUN_OBJECT_LUT_OUTPUTS
@@ -382,10 +396,8 @@ set(BUN_OBJECT_LUT_OUTPUTS
${CODEGEN_PATH}/BunProcess.lut.h
${CODEGEN_PATH}/ProcessBindingConstants.lut.h
${CODEGEN_PATH}/ProcessBindingNatives.lut.h
${CODEGEN_PATH}/NodeModuleModule.lut.h
)
macro(WEBKIT_ADD_SOURCE_DEPENDENCIES _source _deps)
set(_tmp)
get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
@@ -451,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}
@@ -464,6 +489,7 @@ list(APPEND BUN_ZIG_SOURCES
)
set(BUN_ZIG_GENERATED_SOURCES
${BUN_ZIG_IDENTIFIER_OUTPUTS}
${BUN_ERROR_OUTPUTS}
${BUN_FALLBACK_DECODER_OUTPUT}
${BUN_RUNTIME_JS_OUTPUT}
@@ -475,9 +501,9 @@ set(BUN_ZIG_GENERATED_SOURCES
# In debug builds, these are not embedded, but rather referenced at runtime.
if (DEBUG)
list(APPEND BUN_ZIG_GENERATED_SOURCES ${CODEGEN_PATH}/bake_empty_file)
list(APPEND BUN_ZIG_GENERATED_SOURCES ${CODEGEN_PATH}/kit_empty_file)
else()
list(APPEND BUN_ZIG_GENERATED_SOURCES ${BUN_BAKE_RUNTIME_OUTPUTS})
list(APPEND BUN_ZIG_GENERATED_SOURCES ${BUN_KIT_RUNTIME_OUTPUTS})
endif()
set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o)
@@ -519,21 +545,18 @@ register_command(
-Dsha=${REVISION}
-Dreported_nodejs_version=${NODEJS_VERSION}
-Dcanary=${CANARY_REVISION}
-Dcodegen_path=${CODEGEN_PATH}
-Dcodegen_embed=$<IF:$<BOOL:${CODEGEN_EMBED}>,true,false>
-Dgenerated-code=${CODEGEN_PATH}
ARTIFACTS
${BUN_ZIG_OUTPUT}
TARGETS
clone-zig
SOURCES
${BUN_ZIG_SOURCES}
${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)
@@ -546,8 +569,7 @@ file(GLOB BUN_CXX_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/bun.js/bindings/webcrypto/*.cpp
${CWD}/src/bun.js/bindings/webcrypto/*/*.cpp
${CWD}/src/bun.js/bindings/v8/*.cpp
${CWD}/src/bun.js/bindings/v8/shim/*.cpp
${CWD}/src/bake/*.cpp
${CWD}/src/kit/*.cpp
${CWD}/src/deps/*.cpp
${BUN_USOCKETS_SOURCE}/src/crypto/*.cpp
)
@@ -559,42 +581,15 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}
${BUN_USOCKETS_SOURCE}/src/crypto/*.c
)
list(APPEND BUN_C_SOURCES ${VENDOR_PATH}/picohttpparser/picohttpparser.c)
if(WIN32)
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
endif()
register_repository(
NAME
picohttpparser
REPOSITORY
h2o/picohttpparser
COMMIT
066d2b1e9ab820703db0837a7255d92d30f0c9f5
OUTPUTS
picohttpparser.c
)
set(NODEJS_HEADERS_PATH ${VENDOR_PATH}/nodejs)
register_command(
TARGET
bun-node-headers
COMMENT
"Download node ${NODEJS_VERSION} headers"
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_PATH=${NODEJS_HEADERS_PATH}
-DDOWNLOAD_URL=https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-headers.tar.gz
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
OUTPUTS
${NODEJS_HEADERS_PATH}/include/node/node_version.h
)
list(APPEND BUN_CPP_SOURCES
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
${VENDOR_PATH}/picohttpparser/picohttpparser.c
${NODEJS_HEADERS_PATH}/include/node/node_version.h
${BUN_ZIG_GENERATED_CLASSES_OUTPUTS}
${BUN_JS_SINK_OUTPUTS}
${BUN_JAVASCRIPT_OUTPUTS}
@@ -602,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})
@@ -625,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
@@ -658,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)
@@ -672,7 +659,6 @@ target_include_directories(${bun} PRIVATE
${CWD}/src/bun.js/bindings/webcore
${CWD}/src/bun.js/bindings/webcrypto
${CWD}/src/bun.js/bindings/sqlite
${CWD}/src/bun.js/bindings/v8
${CWD}/src/bun.js/modules
${CWD}/src/js/builtins
${CWD}/src/napi
@@ -680,7 +666,6 @@ target_include_directories(${bun} PRIVATE
${CODEGEN_PATH}
${VENDOR_PATH}
${VENDOR_PATH}/picohttpparser
${NODEJS_HEADERS_PATH}/include
)
# --- C/C++ Definitions ---
@@ -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)
@@ -856,33 +839,26 @@ else()
-Wl,--as-needed
-Wl,--gc-sections
-Wl,-z,stack-size=12800000
-Wl,--wrap=cosf
-Wl,--wrap=exp
-Wl,--wrap=expf
-Wl,--wrap=fcntl
-Wl,--wrap=fcntl64
-Wl,--wrap=fmod
-Wl,--wrap=fmodf
-Wl,--wrap=fstat
-Wl,--wrap=fstat64
-Wl,--wrap=fstatat
-Wl,--wrap=fstatat64
-Wl,--wrap=stat64
-Wl,--wrap=pow
-Wl,--wrap=exp
-Wl,--wrap=expf
-Wl,--wrap=log
-Wl,--wrap=log10f
-Wl,--wrap=log2
-Wl,--wrap=log2f
-Wl,--wrap=logf
-Wl,--wrap=lstat
-Wl,--wrap=stat64
-Wl,--wrap=stat
-Wl,--wrap=fstat
-Wl,--wrap=fstatat
-Wl,--wrap=lstat64
-Wl,--wrap=fstat64
-Wl,--wrap=fstatat64
-Wl,--wrap=mknod
-Wl,--wrap=mknodat
-Wl,--wrap=pow
-Wl,--wrap=sincosf
-Wl,--wrap=sinf
-Wl,--wrap=stat
-Wl,--wrap=stat64
-Wl,--wrap=statx
-Wl,--wrap=tanf
-Wl,--wrap=fmod
-Wl,--compress-debug-sections=zlib
-Wl,-z,lazy
-Wl,-z,norelro
@@ -913,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
@@ -951,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)
@@ -1024,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(
@@ -1035,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()
@@ -1056,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}
)
@@ -1078,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}
@@ -1087,7 +1071,7 @@ if(NOT BUN_CPP_ONLY)
)
endif()
if(CMAKE_HOST_APPLE AND bunStrip)
if(bunStrip AND APPLE)
register_command(
TARGET
${bun}
@@ -1117,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)
@@ -1154,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

View File

@@ -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
)

View File

@@ -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()

View File

@@ -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
)

View File

@@ -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()

View File

@@ -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})

View File

@@ -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()

View File

@@ -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()

View File

@@ -0,0 +1,12 @@
register_vendor_target(picohttpparser)
register_repository(
NAME
${picohttpparser}
REPOSITORY
h2o/picohttpparser
COMMIT
066d2b1e9ab820703db0837a7255d92d30f0c9f5
OUTPUTS
picohttpparser.c
)

View File

@@ -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
.
)

View File

@@ -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}
)

View 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()

View File

@@ -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
.
)

View File

@@ -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
)

View File

@@ -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()

View File

@@ -11,18 +11,11 @@ find_command(
COMMAND
ccache
REQUIRED
${CI}
ON
)
if(NOT CCACHE_PROGRAM)
return()
endif()
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})

View File

@@ -1,43 +0,0 @@
find_command(
VARIABLE
GIT_PROGRAM
COMMAND
git
REQUIRED
OFF
)
if(NOT GIT_PROGRAM)
return()
endif()
set(GIT_DIFF_COMMAND ${GIT_PROGRAM} diff --no-color --name-only --diff-filter=AMCR origin/main HEAD)
execute_process(
COMMAND
${GIT_DIFF_COMMAND}
WORKING_DIRECTORY
${CWD}
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE
GIT_DIFF
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE
GIT_DIFF_ERROR
RESULT_VARIABLE
GIT_DIFF_RESULT
)
if(NOT GIT_DIFF_RESULT EQUAL 0)
message(${WARNING} "Command failed: ${GIT_DIFF_COMMAND} ${GIT_DIFF_ERROR}")
return()
endif()
string(REPLACE "\n" ";" GIT_CHANGED_SOURCES "${GIT_DIFF}")
if(CI)
setx(GIT_CHANGED_SOURCES ${GIT_CHANGED_SOURCES})
endif()
list(TRANSFORM GIT_CHANGED_SOURCES PREPEND ${CWD}/)
list(LENGTH GIT_CHANGED_SOURCES GIT_CHANGED_SOURCES_COUNT)

View File

@@ -1,9 +1,3 @@
optionx(ENABLE_LLVM BOOL "If LLVM should be used for compilation" DEFAULT ON)
if(NOT ENABLE_LLVM)
return()
endif()
if(CMAKE_HOST_WIN32 OR CMAKE_HOST_APPLE)
set(DEFAULT_LLVM_VERSION "18.1.8")
else()
@@ -11,90 +5,43 @@ else()
endif()
optionx(LLVM_VERSION STRING "The version of LLVM to use" DEFAULT ${DEFAULT_LLVM_VERSION})
string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" USE_LLVM_VERSION ${LLVM_VERSION})
if(USE_LLVM_VERSION)
set(LLVM_VERSION_MAJOR ${CMAKE_MATCH_1})
set(LLVM_VERSION_MINOR ${CMAKE_MATCH_2})
set(LLVM_VERSION_PATCH ${CMAKE_MATCH_3})
endif()
set(LLVM_PATHS)
parse_semver(${LLVM_VERSION} LLVM)
if(APPLE)
execute_process(
COMMAND brew --prefix
OUTPUT_VARIABLE HOMEBREW_PREFIX
COMMAND brew --prefix llvm@${LLVM_VERSION_MAJOR}
OUTPUT_VARIABLE DEFAULT_LLVM_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT HOMEBREW_PREFIX)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
set(HOMEBREW_PREFIX /opt/homebrew)
else()
set(HOMEBREW_PREFIX /usr/local)
endif()
endif()
list(APPEND LLVM_PATHS ${HOMEBREW_PREFIX}/opt/llvm/bin)
if(USE_LLVM_VERSION)
list(APPEND LLVM_PATHS ${HOMEBREW_PREFIX}/opt/llvm@${LLVM_VERSION_MAJOR}/bin)
if(NOT DEFAULT_LLVM_PREFIX)
set(DEFAULT_LLVM_PREFIX /opt/homebrew/opt/llvm)
endif()
elseif(NOT WIN32)
set(DEFAULT_LLVM_PREFIX /usr/lib/llvm-${LLVM_VERSION_MAJOR})
else()
set(DEFAULT_LLVM_PREFIX /usr/lib)
endif()
if(UNIX)
list(APPEND LLVM_PATHS /usr/lib/llvm/bin)
if(USE_LLVM_VERSION)
list(APPEND LLVM_PATHS
/usr/lib/llvm-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}/bin
/usr/lib/llvm-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}/bin
/usr/lib/llvm-${LLVM_VERSION_MAJOR}/bin
)
endif()
endif()
macro(find_llvm_command variable command)
set(commands ${command})
if(USE_LLVM_VERSION)
list(APPEND commands
${command}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
${command}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
${command}-${LLVM_VERSION_MAJOR}
)
endif()
optionx(LLVM_PREFIX FILEPATH "The path to the LLVM installation" DEFAULT ${DEFAULT_LLVM_PREFIX})
set(LLVM_PATH ${LLVM_PREFIX}/bin)
macro(find_llvm_command VARIABLE COMMAND)
find_command(
VARIABLE ${variable}
VERSION_VARIABLE LLVM_VERSION
COMMAND ${commands}
PATHS ${LLVM_PATHS}
VARIABLE ${VARIABLE}
COMMAND ${COMMAND} ${COMMAND}-${LLVM_VERSION_MAJOR}
PATHS ${LLVM_PATH}
VERSION ${LLVM_VERSION}
)
list(APPEND CMAKE_ARGS -D${variable}=${${variable}})
endmacro()
macro(find_llvm_command_no_version variable command)
set(commands ${command})
if(USE_LLVM_VERSION)
list(APPEND commands
${command}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}
${command}-${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}
${command}-${LLVM_VERSION_MAJOR}
)
endif()
macro(find_llvm_command_no_version VARIABLE COMMAND)
find_command(
VARIABLE ${variable}
VERSION_VARIABLE LLVM_VERSION
COMMAND ${commands}
PATHS ${LLVM_PATHS}
VARIABLE ${VARIABLE}
COMMAND ${COMMAND} ${COMMAND}-${LLVM_VERSION_MAJOR}
PATHS ${LLVM_PATH}
REQUIRED ON
)
list(APPEND CMAKE_ARGS -D${variable}=${${variable}})
endmacro()
if(WIN32)
@@ -114,8 +61,3 @@ else()
find_llvm_command(CMAKE_DSYMUTIL dsymutil)
endif()
endif()
if(ENABLE_ANALYSIS)
find_llvm_command(CLANG_FORMAT_PROGRAM clang-format)
find_llvm_command(CLANG_TIDY_PROGRAM clang-tidy)
endif()

View File

@@ -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}
)

View File

@@ -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 428a917f5a38ac4b79799d73497b57e5c62afb36)
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()

View File

@@ -16,8 +16,6 @@ else()
unsupported(CMAKE_SYSTEM_NAME)
endif()
optionx(ZIG_VERSION STRING "The zig version of the compiler to download" DEFAULT "0.13.0")
optionx(ZIG_COMMIT STRING "The zig commit to use in oven-sh/zig" DEFAULT "131a009ba2eb127a3447d05b9e12f710429aa5ee")
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
@@ -66,18 +64,12 @@ set(CMAKE_ZIG_FLAGS
)
register_command(
TARGET
clone-zig
COMMENT
"Downloading zig"
COMMAND
${CMAKE_COMMAND}
-DZIG_PATH=${ZIG_PATH}
-DZIG_VERSION=${ZIG_VERSION}
-DZIG_COMMIT=${ZIG_COMMIT}
-P ${CWD}/cmake/scripts/DownloadZig.cmake
SOURCES
${CWD}/cmake/scripts/DownloadZig.cmake
OUTPUTS
${ZIG_EXECUTABLE}
)

View File

@@ -1,262 +0,0 @@
`Bun.color(input, outputFormat?)` leverages Bun's CSS parser to parse, normalize, and convert colors from user input to a variety of output formats, including:
| Format | Example |
| ------------ | -------------------------------- |
| `"css"` | `"red"` |
| `"ansi"` | `"\x1b[38;2;255;0;0m"` |
| `"ansi-16"` | `"\x1b[38;5;\tm"` |
| `"ansi-256"` | `"\x1b[38;5;196m"` |
| `"ansi-16m"` | `"\x1b[38;2;255;0;0m"` |
| `"number"` | `0x1a2b3c` |
| `"rgb"` | `"rgb(255, 99, 71)"` |
| `"rgba"` | `"rgba(255, 99, 71, 0.5)"` |
| `"hsl"` | `"hsl(120, 50%, 50%)"` |
| `"hex"` | `"#1a2b3c"` |
| `"HEX"` | `"#1A2B3C"` |
| `"{rgb}"` | `{ r: 255, g: 99, b: 71 }` |
| `"{rgba}"` | `{ r: 255, g: 99, b: 71, a: 1 }` |
| `"[rgb]"` | `[ 255, 99, 71 ]` |
| `"[rgba]"` | `[ 255, 99, 71, 255]` |
There are many different ways to use this API:
- Validate and normalize colors to persist in a database (`number` is the most database-friendly)
- Convert colors to different formats
- Colorful logging beyond the 16 colors many use today (use `ansi` if you don't want to figure out what the user's terminal supports, otherwise use `ansi-16`, `ansi-256`, or `ansi-16m` for how many colors the terminal supports)
- Format colors for use in CSS injected into HTML
- Get the `r`, `g`, `b`, and `a` color components as JavaScript objects or numbers from a CSS color string
You can think of this as an alternative to the popular npm packages [`color`](https://github.com/Qix-/color) and [`tinycolor2`](https://github.com/bgrins/TinyColor) except with full support for parsing CSS color strings and zero dependencies built directly into Bun.
### Flexible input
You can pass in any of the following:
- Standard CSS color names like `"red"`
- Numbers like `0xff0000`
- Hex strings like `"#f00"`
- RGB strings like `"rgb(255, 0, 0)"`
- RGBA strings like `"rgba(255, 0, 0, 1)"`
- HSL strings like `"hsl(0, 100%, 50%)"`
- HSLA strings like `"hsla(0, 100%, 50%, 1)"`
- RGB objects like `{ r: 255, g: 0, b: 0 }`
- RGBA objects like `{ r: 255, g: 0, b: 0, a: 1 }`
- RGB arrays like `[255, 0, 0]`
- RGBA arrays like `[255, 0, 0, 255]`
- LAB strings like `"lab(50% 50% 50%)"`
- ... anything else that CSS can parse as a single color value
### Format colors as CSS
The `"css"` format outputs valid CSS for use in stylesheets, inline styles, CSS variables, css-in-js, etc. It returns the most compact representation of the color as a string.
```ts
Bun.color("red", "css"); // "red"
Bun.color(0xff0000, "css"); // "#f000"
Bun.color("#f00", "css"); // "red"
Bun.color("#ff0000", "css"); // "red"
Bun.color("rgb(255, 0, 0)", "css"); // "red"
Bun.color("rgba(255, 0, 0, 1)", "css"); // "red"
Bun.color("hsl(0, 100%, 50%)", "css"); // "red"
Bun.color("hsla(0, 100%, 50%, 1)", "css"); // "red"
Bun.color({ r: 255, g: 0, b: 0 }, "css"); // "red"
Bun.color({ r: 255, g: 0, b: 0, a: 1 }, "css"); // "red"
Bun.color([255, 0, 0], "css"); // "red"
Bun.color([255, 0, 0, 255], "css"); // "red"
```
If the input is unknown or fails to parse, `Bun.color` returns `null`.
### Format colors as ANSI (for terminals)
The `"ansi"` format outputs ANSI escape codes for use in terminals to make text colorful.
```ts
Bun.color("red", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color(0xff0000, "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("#f00", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("#ff0000", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("rgb(255, 0, 0)", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("rgba(255, 0, 0, 1)", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("hsl(0, 100%, 50%)", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color("hsla(0, 100%, 50%, 1)", "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color({ r: 255, g: 0, b: 0 }, "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color({ r: 255, g: 0, b: 0, a: 1 }, "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color([255, 0, 0], "ansi"); // "\u001b[38;2;255;0;0m"
Bun.color([255, 0, 0, 255], "ansi"); // "\u001b[38;2;255;0;0m"
```
This gets the color depth of stdout and automatically chooses one of `"ansi-16m"`, `"ansi-256"`, `"ansi-16"` based on the environment variables. If stdout doesn't support any form of ANSI color, it returns an empty string. As with the rest of Bun's color API, if the input is unknown or fails to parse, it returns `null`.
#### 24-bit ANSI colors (`ansi-16m`)
The `"ansi-16m"` format outputs 24-bit ANSI colors for use in terminals to make text colorful. 24-bit color means you can display 16 million colors on supported terminals, and requires a modern terminal that supports it.
This converts the input color to RGBA, and then outputs that as an ANSI color.
```ts
Bun.color("red", "ansi-16m"); // "\x1b[38;2;255;0;0m"
Bun.color(0xff0000, "ansi-16m"); // "\x1b[38;2;255;0;0m"
Bun.color("#f00", "ansi-16m"); // "\x1b[38;2;255;0;0m"
Bun.color("#ff0000", "ansi-16m"); // "\x1b[38;2;255;0;0m"
```
#### 256 ANSI colors (`ansi-256`)
The `"ansi-256"` format approximates the input color to the nearest of the 256 ANSI colors supported by some terminals.
```ts
Bun.color("red", "ansi-256"); // "\u001b[38;5;196m"
Bun.color(0xff0000, "ansi-256"); // "\u001b[38;5;196m"
Bun.color("#f00", "ansi-256"); // "\u001b[38;5;196m"
Bun.color("#ff0000", "ansi-256"); // "\u001b[38;5;196m"
```
To convert from RGBA to one of the 256 ANSI colors, we ported the algorithm that [`tmux` uses](https://github.com/tmux/tmux/blob/dae2868d1227b95fd076fb4a5efa6256c7245943/colour.c#L44-L55).
#### 16 ANSI colors (`ansi-16`)
The `"ansi-16"` format approximates the input color to the nearest of the 16 ANSI colors supported by most terminals.
```ts
Bun.color("red", "ansi-16"); // "\u001b[38;5;\tm"
Bun.color(0xff0000, "ansi-16"); // "\u001b[38;5;\tm"
Bun.color("#f00", "ansi-16"); // "\u001b[38;5;\tm"
Bun.color("#ff0000", "ansi-16"); // "\u001b[38;5;\tm"
```
This works by first converting the input to a 24-bit RGB color space, then to `ansi-256`, and then we convert that to the nearest 16 ANSI color.
### Format colors as numbers
The `"number"` format outputs a 24-bit number for use in databases, configuration, or any other use case where a compact representation of the color is desired.
```ts
Bun.color("red", "number"); // 16711680
Bun.color(0xff0000, "number"); // 16711680
Bun.color({ r: 255, g: 0, b: 0 }, "number"); // 16711680
Bun.color([255, 0, 0], "number"); // 16711680
Bun.color("rgb(255, 0, 0)", "number"); // 16711680
Bun.color("rgba(255, 0, 0, 1)", "number"); // 16711680
Bun.color("hsl(0, 100%, 50%)", "number"); // 16711680
Bun.color("hsla(0, 100%, 50%, 1)", "number"); // 16711680
```
### Get the red, green, blue, and alpha channels
You can use the `"{rgba}"`, `"{rgb}"`, `"[rgba]"` and `"[rgb]"` formats to get the red, green, blue, and alpha channels as objects or arrays.
#### `{rgba}` object
The `"{rgba}"` format outputs an object with the red, green, blue, and alpha channels.
```ts
type RGBAObject = {
// 0 - 255
r: number;
// 0 - 255
g: number;
// 0 - 255
b: number;
// 0 - 1
a: number;
};
```
Example:
```ts
Bun.color("hsl(0, 0%, 50%)", "{rgba}"); // { r: 128, g: 128, b: 128, a: 1 }
Bun.color("red", "{rgba}"); // { r: 255, g: 0, b: 0, a: 1 }
Bun.color(0xff0000, "{rgba}"); // { r: 255, g: 0, b: 0, a: 1 }
Bun.color({ r: 255, g: 0, b: 0 }, "{rgba}"); // { r: 255, g: 0, b: 0, a: 1 }
Bun.color([255, 0, 0], "{rgba}"); // { r: 255, g: 0, b: 0, a: 1 }
```
To behave similarly to CSS, the `a` channel is a decimal number between `0` and `1`.
The `"{rgb}"` format is similar, but it doesn't include the alpha channel.
```ts
Bun.color("hsl(0, 0%, 50%)", "{rgb}"); // { r: 128, g: 128, b: 128 }
Bun.color("red", "{rgb}"); // { r: 255, g: 0, b: 0 }
Bun.color(0xff0000, "{rgb}"); // { r: 255, g: 0, b: 0 }
Bun.color({ r: 255, g: 0, b: 0 }, "{rgb}"); // { r: 255, g: 0, b: 0 }
Bun.color([255, 0, 0], "{rgb}"); // { r: 255, g: 0, b: 0 }
```
#### `[rgba]` array
The `"[rgba]"` format outputs an array with the red, green, blue, and alpha channels.
```ts
// All values are 0 - 255
type RGBAArray = [number, number, number, number];
```
Example:
```ts
Bun.color("hsl(0, 0%, 50%)", "[rgba]"); // [128, 128, 128, 255]
Bun.color("red", "[rgba]"); // [255, 0, 0, 255]
Bun.color(0xff0000, "[rgba]"); // [255, 0, 0, 255]
Bun.color({ r: 255, g: 0, b: 0 }, "[rgba]"); // [255, 0, 0, 255]
Bun.color([255, 0, 0], "[rgba]"); // [255, 0, 0, 255]
```
Unlike the `"{rgba}"` format, the alpha channel is an integer between `0` and `255`. This is useful for typed arrays where each channel must be the same underlying type.
The `"[rgb]"` format is similar, but it doesn't include the alpha channel.
```ts
Bun.color("hsl(0, 0%, 50%)", "[rgb]"); // [128, 128, 128]
Bun.color("red", "[rgb]"); // [255, 0, 0]
Bun.color(0xff0000, "[rgb]"); // [255, 0, 0]
Bun.color({ r: 255, g: 0, b: 0 }, "[rgb]"); // [255, 0, 0]
Bun.color([255, 0, 0], "[rgb]"); // [255, 0, 0]
```
### Format colors as hex strings
The `"hex"` format outputs a lowercase hex string for use in CSS or other contexts.
```ts
Bun.color("hsl(0, 0%, 50%)", "hex"); // "#808080"
Bun.color("red", "hex"); // "#ff0000"
Bun.color(0xff0000, "hex"); // "#ff0000"
Bun.color({ r: 255, g: 0, b: 0 }, "hex"); // "#ff0000"
Bun.color([255, 0, 0], "hex"); // "#ff0000"
```
The `"HEX"` format is similar, but it outputs a hex string with uppercase letters instead of lowercase letters.
```ts
Bun.color("hsl(0, 0%, 50%)", "HEX"); // "#808080"
Bun.color("red", "HEX"); // "#FF0000"
Bun.color(0xff0000, "HEX"); // "#FF0000"
Bun.color({ r: 255, g: 0, b: 0 }, "HEX"); // "#FF0000"
Bun.color([255, 0, 0], "HEX"); // "#FF0000"
```
### Bundle-time client-side color formatting
Like many of Bun's APIs, you can use macros to invoke `Bun.color` at bundle-time for use in client-side JavaScript builds:
```ts#client-side.ts
import { color } from "bun" with { type: "macro" };
console.log(color("#f00", "css"));
```
Then, build the client-side code:
```sh
bun build ./client-side.ts
```
This will output the following to `client-side.js`:
```js
// client-side.ts
console.log("red");
```

View File

@@ -14,7 +14,7 @@ In Bun v1.1.9, we added support for DNS caching. This cache makes repeated conne
At the time of writing, we cache up to 255 entries for a maximum of 30 seconds (each). If any connections to a host fail, we remove the entry from the cache. When multiple connections are made to the same host simultaneously, DNS lookups are deduplicated to avoid making multiple requests for the same host.
This cache is automatically used by:
This cache is automatically used by;
- `bun install`
- `fetch()`
@@ -99,7 +99,7 @@ console.log(stats);
### Configuring DNS cache TTL
Bun defaults to 30 seconds for the TTL of DNS cache entries. To change this, you can set the environment variable `$BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`. For example, to set the TTL to 5 seconds:
Bun defaults to 30 seconds for the TTL of DNS cache entries. To change this, you can set the envionrment variable `$BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS`. For example, to set the TTL to 5 seconds:
```sh
BUN_CONFIG_DNS_TIME_TO_LIVE_SECONDS=5 bun run my-script.ts

View File

@@ -206,42 +206,4 @@ console.log(arr);
// => Uint8Array(32) [ 185, 77, 39, 185, 147, ... ]
```
### HMAC in `Bun.CryptoHasher`
`Bun.CryptoHasher` can be used to compute HMAC digests. To do so, pass the key to the constructor.
```ts
const hasher = new Bun.CryptoHasher("sha256", "secret-key");
hasher.update("hello world");
console.log(hasher.digest("hex"));
// => "095d5a21fe6d0646db223fdf3de6436bb8dfb2fab0b51677ecf6441fcf5f2a67"
```
When using HMAC, a more limited set of algorithms are supported:
- `"blake2b512"`
- `"md5"`
- `"sha1"`
- `"sha224"`
- `"sha256"`
- `"sha384"`
- `"sha512-224"`
- `"sha512-256"`
- `"sha512"`
Unlike the non-HMAC `Bun.CryptoHasher`, the HMAC `Bun.CryptoHasher` instance is not reset after `.digest()` is called, and attempting to use the same instance again will throw an error.
Other methods like `.copy()` and `.update()` are supported (as long as it's before `.digest()`), but methods like `.digest()` that finalize the hasher are not.
```ts
const hasher = new Bun.CryptoHasher("sha256", "secret-key");
hasher.update("hello world");
const copy = hasher.copy();
copy.update("!");
console.log(copy.digest("hex"));
// => "3840176c3d8923f59ac402b7550404b28ab11cb0ef1fa199130a5c37864b5497"
console.log(hasher.digest("hex"));
// => "095d5a21fe6d0646db223fdf3de6436bb8dfb2fab0b51677ecf6441fcf5f2a67"
```
<!-- Bun.sha; -->

View File

@@ -325,28 +325,6 @@ As a performance optimization, the class constructor is not called, default init
The database columns are set as properties on the class instance.
### `.iterate()` (`@@iterator`)
Use `.iterate()` to run a query and incrementally return results. This is useful for large result sets that you want to process one row at a time without loading all the results into memory.
```ts
const query = db.query("SELECT * FROM foo");
for (const row of query.iterate()) {
console.log(row);
}
```
You can also use the `@@iterator` protocol:
```ts
const query = db.query("SELECT * FROM foo");
for (const row of query) {
console.log(row);
}
```
This feature was added in Bun v1.1.31.
### `.values()`
Use `values()` to run a query and get back all results as an array of arrays.

View File

@@ -580,65 +580,6 @@ const foo = new Foo();
console.log(foo); // => "foo"
```
## `Bun.inspect.table(tabularData, properties, options)`
Format tabular data into a string. Like [`console.table`](https://developer.mozilla.org/en-US/docs/Web/API/console/table_static), except it returns a string rather than printing to the console.
```ts
console.log(
Bun.inspect.table([
{ a: 1, b: 2, c: 3 },
{ a: 4, b: 5, c: 6 },
{ a: 7, b: 8, c: 9 },
]),
);
//
// ┌───┬───┬───┬───┐
// │ │ a │ b │ c │
// ├───┼───┼───┼───┤
// │ 0 │ 1 │ 2 │ 3 │
// │ 1 │ 4 │ 5 │ 6 │
// │ 2 │ 7 │ 8 │ 9 │
// └───┴───┴───┴───┘
```
Additionally, you can pass an array of property names to display only a subset of properties.
```ts
console.log(
Bun.inspect.table(
[
{ a: 1, b: 2, c: 3 },
{ a: 4, b: 5, c: 6 },
],
["a", "c"],
),
);
//
// ┌───┬───┬───┐
// │ │ a │ c │
// ├───┼───┼───┤
// │ 0 │ 1 │ 3 │
// │ 1 │ 4 │ 6 │
// └───┴───┴───┘
```
You can also conditionally enable ANSI colors by passing `{ colors: true }`.
```ts
console.log(
Bun.inspect.table(
[
{ a: 1, b: 2, c: 3 },
{ a: 4, b: 5, c: 6 },
],
{
colors: true,
},
),
);
```
## `Bun.nanoseconds()`
Returns the number of nanoseconds since the current `bun` process started, as a `number`. Useful for high-precision timing and benchmarking.

View File

@@ -100,30 +100,12 @@ When deploying to production, we recommend the following:
bun build --compile --minify --sourcemap ./path/to/my/app.ts --outfile myapp
```
### Bytecode compilation
To improve startup time, enable bytecode compilation:
```sh
bun build --compile --minify --sourcemap --bytecode ./path/to/my/app.ts --outfile myapp
```
Using bytecode compilation, `tsc` starts 2x faster:
{% image src="https://github.com/user-attachments/assets/dc8913db-01d2-48f8-a8ef-ac4e984f9763" width="689" /%}
Bytecode compilation moves parsing overhead for large input files from runtime to bundle time. Your app starts faster, in exchange for making the `bun build` command a little slower. It doesn't obscure source code.
**Experimental:** Bytecode compilation is an experimental feature introduced in Bun v1.1.30. Only `cjs` format is supported (which means no top-level-await). Let us know if you run into any issues!
### What do these flags do?
**What do these flags do?**
The `--minify` argument optimizes the size of the transpiled output code. If you have a large application, this can save megabytes of space. For smaller applications, it might still improve start time a little.
The `--sourcemap` argument embeds a sourcemap compressed with zstd, so that errors & stacktraces point to their original locations instead of the transpiled location. Bun will automatically decompress & resolve the sourcemap when an error occurs.
The `--bytecode` argument enables bytecode compilation. Every time you run JavaScript code in Bun, JavaScriptCore (the engine) will compile your source code into bytecode. We can move this parsing work from runtime to bundle time, saving you startup time.
## Worker
To use workers in a standalone executable, add the worker's entrypoint to the CLI arguments:

View File

@@ -330,8 +330,6 @@ Depending on the target, Bun will apply different module resolution rules and op
If any entrypoints contains a Bun shebang (`#!/usr/bin/env bun`) the bundler will default to `target: "bun"` instead of `"browser"`.
When using `target: "bun"` and `format: "cjs"` together, the `// @bun @bun-cjs` pragma is added and the CommonJS wrapper function is not compatible with Node.js.
---
- `node`
@@ -343,11 +341,7 @@ Depending on the target, Bun will apply different module resolution rules and op
Specifies the module format to be used in the generated bundles.
Bun defaults to `"esm"`, and provides experimental support for `"cjs"` and `"iife"`.
#### `format: "esm"` - ES Module
This is the default format, which supports ES Module syntax including top-level `await`, import.meta, and more.
Currently the bundler only supports one module format: `"esm"`. Support for `"cjs"` and `"iife"` are planned.
{% codetabs %}
@@ -365,31 +359,44 @@ $ bun build ./index.tsx --outdir ./out --format esm
{% /codetabs %}
To use ES Module syntax in browsers, set `format` to `"esm"` and make sure your `<script type="module">` tag has `type="module"` set.
<!-- ### `bundling`
#### `format: "cjs"` - CommonJS
Whether to enable bundling.
To build a CommonJS module, set `format` to `"cjs"`. When choosing `"cjs"`, the default target changes from `"browser"` (esm) to `"node"` (cjs). CommonJS modules transpiled with `format: "cjs", target: "node"` can be executed in both Bun and Node.js (assuming the APIs in use are supported by both).
{% codetabs %}
{% codetabs group="a" %}
```ts#JavaScript
await Bun.build({
entrypoints: ['./index.tsx'],
outdir: './out',
format: "cjs",
bundling: true, // default
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --format cjs
# bundling is enabled by default
$ bun build ./index.tsx --outdir ./out
```
{% /codetabs %}
#### `format: "iife"` - IIFE
Set to `false` to disable bundling. Instead, files will be transpiled and individually written to `outdir`.
TODO: document IIFE once we support globalNames.
{% codetabs group="a" %}
```ts#JavaScript
await Bun.build({
entrypoints: ['./index.tsx'],
outdir: './out',
bundling: false,
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --no-bundling
```
{% /codetabs %} -->
### `splitting`
@@ -751,7 +758,7 @@ $ bun build ./index.tsx --outdir ./out --external '*'
### `packages`
Control whatever package dependencies are included to bundle or not. Possible values: `bundle` (default), `external`. Bun treats any import which path do not start with `.`, `..` or `/` as package.
Control whatever package dependencies are included to bundle or not. Possible values: `bundle` (default), `external`. Bun threats any import which path do not start with `.`, `..` or `/` as package.
{% codetabs group="a" %}
@@ -1090,84 +1097,6 @@ $ bun build ./index.tsx --outdir ./out --loader .png:dataurl --loader .txt:file
{% /codetabs %}
### `banner`
A banner to be added to the final bundle, this can be a directive like "use client" for react or a comment block such as a license for the code.
{% codetabs %}
```ts#JavaScript
await Bun.build({
entrypoints: ['./index.tsx'],
outdir: './out',
banner: '"use client";'
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --banner "\"use client\";"
```
{% /codetabs %}
### `footer`
A footer to be added to the final bundle, this can be something like a comment block for a license or just a fun easter egg.
{% codetabs %}
```ts#JavaScript
await Bun.build({
entrypoints: ['./index.tsx'],
outdir: './out',
footer: '// built with love in SF'
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --footer="// built with love in SF"
```
{% /codetabs %}
### `drop`
Remove function calls from a bundle. For example, `--drop=console` will remove all calls to `console.log`. Arguments to calls will also be removed, regardless of if those arguments may have side effects. Dropping `debugger` will remove all `debugger` statements.
{% codetabs %}
```ts#JavaScript
await Bun.build({
entrypoints: ['./index.tsx'],
outdir: './out',
drop: ["console", "debugger", "anyIdentifier.or.propertyAccess"],
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --drop=console --drop=debugger --drop=anyIdentifier.or.propertyAccess
```
{% /codetabs %}
### `experimentalCss`
Whether to enable _experimental_ support for bundling CSS files. Defaults to `false`.
This supports bundling CSS files imported from JS, as well as CSS entrypoints.
{% codetabs group="a" %}
```ts#JavaScript
const result = await Bun.build({
entrypoints: ["./index.ts"],
experimentalCss: true,
});
// => { success: boolean, outputs: BuildArtifact[], logs: BuildMessage[] }
```
{% /codetabs %}
## Outputs
The `Bun.build` function returns a `Promise<BuildOutput>`, defined as:
@@ -1209,7 +1138,7 @@ Each artifact also contains the following properties:
---
- `kind`
- What kind of build output this file is. A build generates bundled entrypoints, code-split "chunks", sourcemaps, bytecode, and copied assets (like images).
- What kind of build output this file is. A build generates bundled entrypoints, code-split "chunks", sourcemaps, and copied assets (like images).
---
@@ -1274,26 +1203,6 @@ BuildArtifact (entry-point) {
{% /codetabs %}
### Bytecode
The `bytecode: boolean` option can be used to generate bytecode for any JavaScript/TypeScript entrypoints. This can greatly improve startup times for large applications. Only supported for `"cjs"` format, only supports `"target": "bun"` and dependent on a matching version of Bun. This adds a corresponding `.jsc` file for each entrypoint.
{% codetabs %}
```ts#JavaScript
await Bun.build({
entrypoints: ["./index.tsx"],
outdir: "./out",
bytecode: true,
})
```
```bash#CLI
$ bun build ./index.tsx --outdir ./out --bytecode
```
{% /codetabs %}
### Executables
Bun supports "compiling" a JavaScript/TypeScript entrypoint into a standalone executable. This executable contains a copy of the Bun binary.
@@ -1357,104 +1266,33 @@ interface Bun {
build(options: BuildOptions): Promise<BuildOutput>;
}
interface BuildConfig {
entrypoints: string[]; // list of file path
outdir?: string; // output directory
target?: Target; // default: "browser"
/**
* Output module format. Top-level await is only supported for `"esm"`.
*
* Can be:
* - `"esm"`
* - `"cjs"` (**experimental**)
* - `"iife"` (**experimental**)
*
* @default "esm"
*/
format?: /**
* ECMAScript Module format
*/
| "esm"
/**
* CommonJS format
* **Experimental**
*/
| "cjs"
/**
* IIFE format
* **Experimental**
*/
| "iife";
interface BuildOptions {
entrypoints: string[]; // required
outdir?: string; // default: no write (in-memory only)
format?: "esm"; // later: "cjs" | "iife"
target?: "browser" | "bun" | "node"; // "browser"
splitting?: boolean; // true
plugins?: BunPlugin[]; // [] // See https://bun.sh/docs/bundler/plugins
loader?: { [k in string]: Loader }; // See https://bun.sh/docs/bundler/loaders
manifest?: boolean; // false
external?: string[]; // []
sourcemap?: "none" | "inline" | "linked" | "external" | "linked" | boolean; // "none"
root?: string; // computed from entrypoints
naming?:
| string
| {
chunk?: string;
entry?: string;
asset?: string;
}; // | string;
root?: string; // project root
splitting?: boolean; // default true, enable code splitting
plugins?: BunPlugin[];
// manifest?: boolean; // whether to return manifest
external?: string[];
packages?: "bundle" | "external";
publicPath?: string;
define?: Record<string, string>;
// origin?: string; // e.g. http://mydomain.com
loader?: { [k in string]: Loader };
sourcemap?: "none" | "linked" | "inline" | "external" | "linked"; // default: "none", true -> "inline"
/**
* package.json `exports` conditions used when resolving imports
*
* Equivalent to `--conditions` in `bun build` or `bun run`.
*
* https://nodejs.org/api/packages.html#exports
*/
conditions?: Array<string> | string;
entry?: string; // '[dir]/[name].[ext]'
chunk?: string; // '[name]-[hash].[ext]'
asset?: string; // '[name]-[hash].[ext]'
};
publicPath?: string; // e.g. http://mydomain.com/
minify?:
| boolean
| boolean // false
| {
identifiers?: boolean;
whitespace?: boolean;
syntax?: boolean;
identifiers?: boolean;
};
/**
* Ignore dead code elimination/tree-shaking annotations such as @__PURE__ and package.json
* "sideEffects" fields. This should only be used as a temporary workaround for incorrect
* annotations in libraries.
*/
ignoreDCEAnnotations?: boolean;
/**
* Force emitting @__PURE__ annotations even if minify.whitespace is true.
*/
emitDCEAnnotations?: boolean;
// treeshaking?: boolean;
// jsx?:
// | "automatic"
// | "classic"
// | /* later: "preserve" */ {
// runtime?: "automatic" | "classic"; // later: "preserve"
// /** Only works when runtime=classic */
// factory?: string; // default: "React.createElement"
// /** Only works when runtime=classic */
// fragment?: string; // default: "React.Fragment"
// /** Only works when runtime=automatic */
// importSource?: string; // default: "react"
// };
/**
* Generate bytecode for the output. This can dramatically improve cold
* start times, but will make the final output larger and slightly increase
* memory usage.
*
* Bytecode is currently only supported for CommonJS (`format: "cjs"`).
*
* Must be `target: "bun"`
* @default false
*/
bytecode?: boolean;
}
interface BuildOutput {
@@ -1466,9 +1304,9 @@ interface BuildOutput {
interface BuildArtifact extends Blob {
path: string;
loader: Loader;
hash: string | null;
kind: "entry-point" | "chunk" | "asset" | "sourcemap" | "bytecode";
sourcemap: BuildArtifact | null;
hash?: string;
kind: "entry-point" | "chunk" | "asset" | "sourcemap";
sourcemap?: BuildArtifact;
}
type Loader =

View File

@@ -59,7 +59,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `--format`
- `--format`
- Bun supports `"esm"` and `"cjs"` currently, but more module formats are planned. esbuild defaults to `"iife"`.
- Bun only supports `"esm"` currently but other module formats are planned. esbuild defaults to `"iife"`.
---
@@ -154,14 +154,8 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
---
- `--banner`
- `--banner`
- Only applies to js bundles
---
- `--footer`
- `--footer`
- Only applies to js bundles
- n/a
- Not supported
---
@@ -190,7 +184,8 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
---
- `--drop`
- `--drop`
- n/a
- Not supported
---
@@ -200,6 +195,12 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
---
- `--footer`
- n/a
- Not supported
---
- `--global-name`
- n/a
- Not applicable, Bun does not support `iife` output at this time

View File

@@ -1,22 +1,5 @@
The `bun pm` command group provides a set of utilities for working with Bun's package manager.
## pack
To create a tarball of the current workspace:
```bash
$ bun pm pack
```
Options for the `pack` command:
- `--dry-run`: Perform all tasks except writing the tarball to disk.
- `--destination`: Specify the directory where the tarball will be saved.
- `--ignore-scripts`: Skip running pre/postpack and prepare scripts.
- `--gzip-level`: Set a custom compression level for gzip, ranging from 0 to 9 (default is 9).
## bin
To print the path to the `bin` directory for the local project:
```bash
@@ -31,8 +14,6 @@ $ bun pm bin -g
<$HOME>/.bun/bin
```
## ls
To print a list of installed dependencies in the current project and their resolved versions, excluding their dependencies.
```bash
@@ -64,36 +45,6 @@ $ bun pm ls --all
├── ...
```
## whoami
Print your npm username. Requires you to be logged in (`bunx npm login`) with credentials in either `bunfig.toml` or `.npmrc`:
```bash
$ bun pm whoami
```
## hash
To generate and print the hash of the current lockfile:
```bash
$ bun pm hash
```
To print the string used to hash the lockfile:
```bash
$ bun pm hash-string
```
To print the hash stored in the current lockfile:
```bash
$ bun pm hash-print
```
## cache
To print the path to Bun's global module cache:
```bash
@@ -106,45 +57,16 @@ To clear Bun's global module cache:
$ bun pm cache rm
```
## migrate
## List global installs
To migrate another package manager's lockfile without installing anything:
To list all globally installed packages:
```bash
$ bun pm migrate
$ bun pm ls -g
```
## untrusted
To print current untrusted dependencies with scripts:
To list all globally installed packages, including nth-order dependencies:
```bash
$ bun pm untrusted
./node_modules/@biomejs/biome @1.8.3
» [postinstall]: node scripts/postinstall.js
These dependencies had their lifecycle scripts blocked during install.
$ bun pm ls -g --all
```
## trust
To run scripts for untrusted dependencies and add to `trustedDependencies`:
```bash
$ bun pm trust <names>
```
Options for the `trust` command:
- `--all`: Trust all untrusted dependencies.
## default-trusted
To print the default trusted dependencies list:
```bash
$ bun pm default-trusted
```
see the current list on GitHub [here](https://github.com/oven-sh/bun/blob/main/src/install/default-trusted-dependencies.txt)

View File

@@ -1,107 +0,0 @@
Use `bun publish` to publish a package to the npm registry.
`bun publish` will automatically pack your package into a tarball, strip workspace protocols from the `package.json` (resolving versions if necessary), and publish to the registry specified in your configuration files. Both `bunfig.toml` and `.npmrc` files are supported.
```sh
## Publishing the package from the current working directory
$ bun publish
## Output
bun publish v1.1.30 (ca7428e9)
packed 203B package.json
packed 224B README.md
packed 30B index.ts
packed 0.64KB tsconfig.json
Total files: 4
Shasum: 79e2b4377b63f4de38dc7ea6e5e9dbee08311a69
Integrity: sha512-6QSNlDdSwyG/+[...]X6wXHriDWr6fA==
Unpacked size: 1.1KB
Packed size: 0.76KB
Tag: latest
Access: default
Registry: http://localhost:4873/
+ publish-1@1.0.0
```
Alternatively, you can pack and publish your package separately by using `bun pm pack` followed by `bun publish` with the path to the output tarball.
```sh
$ bun pm pack
...
$ bun publish ./package.tgz
```
{% callout %}
**Note** - `bun publish` will not run lifecycle scripts (`prepublishOnly/prepack/prepare/postpack/publish/postpublish`) if a tarball path is provided. Scripts will only be run if the package is packed by `bun publish`.
{% /callout %}
### `--access`
The `--access` flag can be used to set the access level of the package being published. The access level can be one of `public` or `restricted`. Unscoped packages are always public, and attempting to publish an unscoped package with `--access restricted` will result in an error.
```sh
$ bun publish --access public
```
`--access` can also be set in the `publishConfig` field of your `package.json`.
```json
{
"publishConfig": {
"access": "restricted"
}
}
```
### `--tag`
Set the tag of the package version being published. By default, the tag is `latest`. The initial version of a package is always given the `latest` tag in addition to the specified tag.
```sh
$ bun publish --tag alpha
```
`--tag` can also be set in the `publishConfig` field of your `package.json`.
```json
{
"publishConfig": {
"tag": "next"
}
}
```
### `--dry-run`
The `--dry-run` flag can be used to simulate the publish process without actually publishing the package. This is useful for verifying the contents of the published package without actually publishing the package.
```sh
$ bun publish --dry-run
```
### `--auth-type`
If you have 2FA enabled for your npm account, `bun publish` will prompt you for a one-time password. This can be done through a browser or the CLI. The `--auth-type` flag can be used to tell the npm registry which method you prefer. The possible values are `web` and `legacy`, with `web` being the default.
```sh
$ bun publish --auth-type legacy
...
This operation requires a one-time password.
Enter OTP: 123456
...
```
### `--otp`
Provide a one-time password directly to the CLI. If the password is valid, this will skip the extra prompt for a one-time password before publishing. Example usage:
```sh
$ bun publish --otp 123456
```
### `--gzip-level`
Specify the level of gzip compression to use when packing the package. Only applies to `bun publish` without a tarball path argument. Values range from `0` to `9` (default is `9`).

View File

@@ -2,6 +2,12 @@
name: Build an app with Next.js and Bun
---
{% callout %}
The Next.js [App Router](https://nextjs.org/docs/app) currently relies on Node.js APIs that Bun does not yet implement. The guide below uses Bun to initialize a project and install dependencies, but it uses Node.js to run the dev server.
{% /callout %}
---
Initialize a Next.js app with `create-next-app`. This automatically installs dependencies using `npm`.
```sh

View File

@@ -1,214 +0,0 @@
---
name: Migrate from npm install to bun install
---
`bun install` is a Node.js compatible npm client designed to be an incredibly fast successor to npm.
We've put a lot of work into making sure that the migration path from `npm install` to `bun install` is as easy as running `bun install` instead of `npm install`.
- **Designed for Node.js & Bun**: `bun install` installs a Node.js compatible `node_modules` folder. You can use it in place of `npm install` for Node.js projects without any code changes and without using Bun's runtime.
- **Automatically converts `package-lock.json`** to bun's `bun.lockb` lockfile format, preserving your existing resolved dependency versions without any manual work on your part. You can secretly use `bun install` in place of `npm install` at work without anyone noticing.
- **`.npmrc` compatible**: bun install reads npm registry configuration from npm's `.npmrc`, so you can use the same configuration for both npm and Bun.
- **Hardlinks**: On Windows and Linux, `bun install` uses hardlinks to conserve disk space and install times.
```bash
# It only takes one command to migrate
$ bun i
# To add dependencies:
$ bun i @types/bun
# To add devDependencies:
$ bun i -d @types/bun
# To remove a dependency:
$ bun rm @types/bun
```
---
## Run package.json scripts faster
Run scripts from package.json, executables from `node_modules/.bin` (sort of like `npx`), and JavaScript/TypeScript files (just like `node`) - all from a single simple command.
| NPM | Bun |
| ------------------ | ---------------- |
| `npm run <script>` | `bun <script>` |
| `npm exec <bin>` | `bun <bin>` |
| `node <file>` | `bun <file>` |
| `npx <package>` | `bunx <package>` |
When you use `bun run <executable>`, it will choose the locally-installed executable
```sh
# Run a package.json script:
$ bun my-script
$ bun run my-script
# Run an executable in node_modules/.bin:
$ bun my-executable # such as tsc, esbuild, etc.
$ bun run my-executable
# Run a JavaScript/TypeScript file:
$ bun ./index.ts
```
---
## Workspaces? Yes.
`bun install` supports workspaces similarly to npm, with more features.
In package.json, you can set `"workspaces"` to an array of relative paths.
```json#package.json
{
"name": "my-app",
"workspaces": ["packages/*", "apps/*"]
}
```
---
### Filter scripts by workspace name
In Bun, the `--filter` flag accepts a glob pattern, and will run the command concurrently for all workspace packages with a `name` that matches the pattern, respecting dependency order.
```sh
$ bun --filter 'lib-*' my-script
# instead of:
# npm run --workspace lib-foo --workspace lib-bar my-script
```
---
## Update dependencies
To update a dependency, you can use `bun update <package>`. This will update the dependency to the latest version that satisfies the semver range specified in package.json.
```sh
# Update a single dependency
$ bun update @types/bun
# Update all dependencies
$ bun update
# Ignore semver, update to the latest version
$ bun update @types/bun --latest
# Update a dependency to a specific version
$ bun update @types/bun@1.1.10
# Update all dependencies to the latest versions
$ bun update --latest
```
---
### View outdated dependencies
To view outdated dependencies, run `bun outdated`. This is like `npm outdated` but with more compact output.
```sh
$ bun outdated
┌────────────────────────────────────────┬─────────┬────────┬────────┐
│ Package │ Current │ Update │ Latest │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ @types/bun (dev) │ 1.1.6 │ 1.1.10 │ 1.1.10 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ @types/react (dev) │ 18.3.3 │ 18.3.8 │ 18.3.8 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ @typescript-eslint/eslint-plugin (dev) │ 7.16.1 │ 7.18.0 │ 8.6.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ @typescript-eslint/parser (dev) │ 7.16.1 │ 7.18.0 │ 8.6.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ @vscode/debugadapter (dev) │ 1.66.0 │ 1.67.0 │ 1.67.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ esbuild (dev) │ 0.21.5 │ 0.21.5 │ 0.24.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ eslint (dev) │ 9.7.0 │ 9.11.0 │ 9.11.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ mitata (dev) │ 0.1.11 │ 0.1.14 │ 1.0.2 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ prettier-plugin-organize-imports (dev) │ 4.0.0 │ 4.1.0 │ 4.1.0 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ source-map-js (dev) │ 1.2.0 │ 1.2.1 │ 1.2.1 │
├────────────────────────────────────────┼─────────┼────────┼────────┤
│ typescript (dev) │ 5.5.3 │ 5.6.2 │ 5.6.2 │
└────────────────────────────────────────┴─────────┴────────┴────────┘
```
---
## List installed packages
To list installed packages, you can use `bun pm ls`. This will list all the packages that are installed in the `node_modules` folder using Bun's lockfile as the source of truth. You can pass the `-a` flag to list all installed packages, including transitive dependencies.
```sh
# List top-level installed packages:
$ bun pm ls
my-pkg node_modules (781)
├── @types/node@20.16.5
├── @types/react@18.3.8
├── @types/react-dom@18.3.0
├── eslint@8.57.1
├── eslint-config-next@14.2.8
# List all installed packages:
$ bun pm ls -a
my-pkg node_modules
├── @alloc/quick-lru@5.2.0
├── @isaacs/cliui@8.0.2
│ └── strip-ansi@7.1.0
│ └── ansi-regex@6.1.0
├── @jridgewell/gen-mapping@0.3.5
├── @jridgewell/resolve-uri@3.1.2
...
```
---
## Create a package tarball
To create a package tarball, you can use `bun pm pack`. This will create a tarball of the package in the current directory.
```sh
# Create a tarball
$ bun pm pack
Total files: 46
Shasum: 2ee19b6f0c6b001358449ca0eadead703f326216
Integrity: sha512-ZV0lzWTEkGAMz[...]Gl4f8lA9sl97g==
Unpacked size: 0.41MB
Packed size: 117.50KB
```
---
## Shebang
If the package references `node` in the `#!/usr/bin/env node` shebang, `bun run` will by default respect it and use the system's `node` executable. You can force it to use Bun's `node` by passing `--bun` to `bun run`.
When you pass `--bun` to `bun run`, we create a symlink to the locally-installed Bun executable named `"node"` in a temporary directory and add that to your `PATH` for the duration of the script's execution.
```sh
# Force using Bun's runtime instead of node
$ bun --bun my-script
# This also works:
$ bun run --bun my-script
```
---
## Global installs
You can install packages globally using `bun i -g <package>`. This will install into a `.bun/install/global/node_modules` folder inside your home directory by default.
```sh
# Install a package globally
$ bun i -g eslint
# Run a globally-installed package without the `bun run` prefix
$ eslint --init
```

View File

@@ -17,7 +17,7 @@ If you are seeing one of the following errors, you are probably trying to use a
---
To allow Bun to execute lifecycle scripts for a specific package, add the package to `trustedDependencies` in your package.json file. You can do this automatically by running the command `bun pm trust <pkg>`.
To tell Bun to allow lifecycle scripts for a particular package, add the package to `trustedDependencies` in your package.json.
{% callout %}
Note that this only allows lifecycle scripts for the specific package listed in `trustedDependencies`, _not_ the dependencies of that dependency!

View File

@@ -27,6 +27,16 @@ data.version; // => "1.0.0"
data.author.name; // => "John Dough"
```
Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes/) and [JSON modules](https://github.com/tc39/proposal-json-modules) syntax.
```ts
import data from "./package.json" with { type: "json" };
data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"
```
---
Bun also supports [Import Attributes](https://github.com/tc39/proposal-import-attributes/) and [JSON modules](https://github.com/tc39/proposal-json-modules) syntax.

View File

@@ -16,7 +16,7 @@ Add the following to your local or global `.gitattributes` file:
*.lockb binary diff=lockb
```
Then add the following to your local git config with:
Then add the following to you local git config with:
```sh
$ git config diff.lockb.textconv bun

View File

@@ -41,7 +41,7 @@ In the root `package.json`, the `"workspaces"` key is used to indicate which sub
**Glob support** — Bun supports full glob syntax in `"workspaces"` (see [here](https://bun.sh/docs/api/glob#supported-glob-patterns) for a comprehensive list of supported syntax), _except_ for exclusions (e.g. `!**/excluded/**`), which are not implemented yet.
{% /callout %}
Each workspace has it's own `package.json`. When referencing other packages in the monorepo, semver or workspace protocols (e.g. `workspace:*`) can be used as the version field in your `package.json`.
Each workspace has it's own `package.json` When referencing other packages in the monorepo, use `"workspace:*"` as the version field in your `package.json`.
```json
{
@@ -53,6 +53,10 @@ Each workspace has it's own `package.json`. When referencing other packages in t
}
```
{% callout %}
**Version support** — Bun supports simple `workspace:*` versions in `"dependencies"`. Full version syntax (e.g. `workspace:^*`) is not yet supported.
{% /callout %}
Workspaces have a couple major benefits.
- **Code can be split into logical parts.** If one package relies on another, you can simply add it as a dependency in `package.json`. If package `b` depends on `a`, `bun install` will install your local `packages/a` directory into `node_modules` instead of downloading it from the npm registry.

View File

@@ -72,9 +72,8 @@ There are also image variants for different operating systems.
```bash
$ docker pull oven/bun:debian
$ docker pull oven/bun:slim
$ docker pull oven/bun:alpine
$ docker pull oven/bun:distroless
# alpine not recommended until #918 is fixed
# $ docker pull oven/bun:alpine
```
## Checking installation

View File

@@ -164,9 +164,6 @@ export default {
page("cli/update", "`bun update`", {
description: "Update your project's dependencies.",
}),
page("cli/publish", "`bun publish`", {
description: "Publish your package to an npm registry.",
}),
page("cli/outdated", "`bun outdated`", {
description: "Check for outdated dependencies.",
}),
@@ -377,10 +374,6 @@ export default {
description: `Bun's native Semver implementation is 20x faster than the popular \`node-semver\` package.`,
}), // "`Semver`"),
page("api/color", "Color", {
description: `Bun's color function leverages Bun's CSS parser for parsing, normalizing, and converting colors from user input to a variety of output formats.`,
}), // "`Color`"),
// divider("Dev Server"),
// page("bun-dev", "Vanilla"),
// page("dev/css", "CSS"),

View File

@@ -67,7 +67,6 @@ After Visual Studio, you need the following:
- Perl
- Ruby
- Node.js
- Ccache
{% callout %}
**Note** The Zig compiler is automatically downloaded, installed, and updated by the building process.
@@ -79,12 +78,12 @@ After Visual Studio, you need the following:
```ps1#WinGet
## Select "Add LLVM to the system PATH for all users" in the LLVM installer
> winget install -i LLVM.LLVM -v 18.1.8 && winget install GoLang.Go Rustlang.Rustup NASM.NASM StrawberryPerl.StrawberryPerl RubyInstallerTeam.Ruby.3.2 OpenJS.NodeJS.LTS Ccache.Ccache
> winget install -i LLVM.LLVM -v 18.1.8 && winget install GoLang.Go Rustlang.Rustup NASM.NASM StrawberryPerl.StrawberryPerl RubyInstallerTeam.Ruby.3.2 OpenJS.NodeJS.LTS
```
```ps1#Scoop
> irm https://get.scoop.sh | iex
> scoop install nodejs-lts go rust nasm ruby perl ccache
> scoop install nodejs-lts go rust nasm ruby perl
# scoop seems to be buggy if you install llvm and the rest at the same time
> scoop install llvm@18.1.8
```
@@ -105,10 +104,10 @@ If you intend on building WebKit locally (optional), you should install these pa
{% /codetabs %}
From here on out, it is **expected you use a PowerShell Terminal with `.\scripts\vs-shell.ps1` sourced**. This script is available in the Bun repository and can be loaded by executing it:
From here on out, it is **expected you use a PowerShell Terminal with `.\scripts\env.ps1` sourced**. This script is available in the Bun repository and can be loaded by executing it:
```ps1
> .\scripts\vs-shell.ps1
> .\scripts\env.ps1
```
To verify, you can check for an MSVC-only command line such as `mt.exe`
@@ -118,41 +117,49 @@ To verify, you can check for an MSVC-only command line such as `mt.exe`
```
{% callout %}
It is not recommended to install `ninja` / `cmake` into your global path, because you may run into a situation where you try to build bun without .\scripts\vs-shell.ps1 sourced.
It is not recommended to install `ninja` / `cmake` into your global path, because you may run into a situation where you try to build bun without .\scripts\env.ps1 sourced.
{% /callout %}
## Building
```ps1
> bun run build
> bun install
# after the initial `bun run build` you can use the following to build
> ninja -Cbuild/debug
> .\scripts\env.ps1
> .\scripts\update-submodules.ps1 # this syncs git submodule state
> .\scripts\all-dependencies.ps1 # this builds all dependencies
> .\scripts\make-old-js.ps1 # runs some old code generators
# Configure build environment
> cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug
# Build bun
> ninja -Cbuild
```
If this was successful, you should have a `bun-debug.exe` in the `build/debug` folder.
If this was successful, you should have a `bun-debug.exe` in the `build` folder.
```ps1
> .\build\debug\bun-debug.exe --revision
> .\build\bun-debug.exe --revision
```
You should add this to `$Env:PATH`. The simplest way to do so is to open the start menu, type "Path", and then navigate the environment variables menu to add `C:\.....\bun\build\debug` to the user environment variable `PATH`. You should then restart your editor (if it does not update still, log out and log back in).
You should add this to `$Env:PATH`. The simplest way to do so is to open the start menu, type "Path", and then navigate the environment variables menu to add `C:\.....\bun\build` to the user environment variable `PATH`. You should then restart your editor (if it does not update still, log out and log back in).
## Extra paths
- WebKit is extracted to `build/debug/cache/webkit/`
- Zig is extracted to `build/debug/cache/zig/bin/zig.exe`
- WebKit is extracted to `build/bun-webkit`
- Zig is extracted to `.cache/zig/zig.exe`
## Tests
You can run the test suite either using `bun test <path>`, or by using the wrapper script `packages\bun-internal-test`. The internal test package is a wrapper cli to run every test file in a separate instance of bun.exe, to prevent a crash in the test runner from stopping the entire suite.
You can run the test suite either using `bun test`, or by using the wrapper script `packages\bun-internal-test`. The internal test package is a wrapper cli to run every test file in a separate instance of bun.exe, to prevent a crash in the test runner from stopping the entire suite.
```ps1
# Setup
> bun i --cwd packages\bun-internal-test
# Run the entire test suite with reporter
# the package.json script "test" uses "build/debug/bun-debug.exe" by default
# the package.json script "test" uses "build/bun-debug.exe" by default
> bun run test
# Run an individual test file:

View File

@@ -370,19 +370,6 @@ myorg = { username = "myusername", password = "$npm_password", url = "https://re
myorg = { token = "$npm_token", url = "https://registry.myorg.com/" }
```
### `install.ca` and `install.cafile`
To configure a CA certificate, use `install.ca` or `install.cafile` to specify a path to a CA certificate file.
```toml
[install]
# The CA certificate as a string
ca = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
# A path to a CA certificate file. The file can contain multiple certificates.
cafile = "path/to/cafile"
```
### `install.cache`
To configure the cache behavior:

View File

@@ -238,30 +238,6 @@ If `exports` is not defined, Bun falls back to `"module"` (ESM imports only) the
}
```
### Custom conditions
The `--conditions` flag allows you to specify a list of conditions to use when resolving packages from package.json `"exports"`.
This flag is supported in both `bun build` and Bun's runtime.
```sh
# Use it with bun build:
$ bun build --conditions="react-server" --target=bun ./app/foo/route.js
# Use it with bun's runtime:
$ bun --conditions="react-server" ./app/foo/route.js
```
You can also use `conditions` programmatically with `Bun.build`:
```js
await Bun.build({
conditions: ["react-server"],
target: "bun",
entryPoints: ["./app/foo/route.js"],
});
```
## Path re-mapping
In the spirit of treating TypeScript as a first-class citizen, the Bun runtime will re-map import paths according to the [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) field in `tsconfig.json`. This is a major divergence from Node.js, which doesn't support any form of import path re-mapping.

View File

@@ -76,12 +76,6 @@ test("wat", async () => {
}, 500); // test must run in <500ms
```
In `bun:test`, test timeouts throw an uncatchable exception to force the test to stop running and fail. We also kill any child processes that were spawned in the test to avoid leaving behind zombie processes lurking in the background.
### 🧟 Zombie process killer
When a test times out and processes spawned in the test via `Bun.spawn`, `Bun.spawnSync`, or `node:child_process` are not killed, they will be automatically killed and a message will be logged to the console.
## `test.skip`
Skip individual tests with `test.skip`. These tests will not be run.
@@ -330,7 +324,6 @@ Bun implements the following matchers. Full Jest compatibility is on the roadmap
- [`.toContainAllValues()`](https://jest-extended.jestcommunity.dev/docs/matchers/Object#tocontainallvaluesvalues)
---
- ✅
- [`.toContainAnyValues()`](https://jest-extended.jestcommunity.dev/docs/matchers/Object#tocontainanyvaluesvalues)

View File

@@ -40,7 +40,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionWrite, (JSC::JSGlobalObject * globalObject,
int32_t fd = STDOUT_FILENO;
if (callframe->argumentCount() > 1) {
fd = arg1.toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
RETURN_IF_EXCEPTION(scope, encodedJSValue());
} else {
toWriteArg = arg1;
}
@@ -53,7 +53,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionWrite, (JSC::JSGlobalObject * globalObject,
}
auto string = toWriteArg.toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, {});
RETURN_IF_EXCEPTION(scope, encodedJSValue());
auto utf8 = string.utf8();
auto length = utf8.length();
auto written = write(fd, utf8.data(), length);

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.1.31",
"version": "1.1.29",
"workspaces": [
"./packages/bun-types"
],
@@ -21,10 +21,7 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"source-map-js": "^1.2.0",
"typescript": "^5.4.5",
"caniuse-lite": "^1.0.30001620",
"autoprefixer": "^10.4.19",
"@mdn/browser-compat-data": "~5.5.28"
"typescript": "^5.4.5"
},
"resolutions": {
"bun-types": "workspace:packages/bun-types"
@@ -43,36 +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",
"css-properties": "bun run src/css/properties/generate_properties.ts",
"bump": "bun ./scripts/bump.ts",
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
"fmt": "bun run prettier",
"fmt:cpp": "bun run clang-format",
"fmt:zig": "bun run zig-format",
"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": "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 --exec-path ./build/debug/bun-debug",
"test:release": "node scripts/runner.node.mjs --exec-path ./build/release/bun",
"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-format",
"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",
"analysis": "bun ./scripts/build.mjs -DCMAKE_BUILD_TYPE=Debug -DENABLE_ANALYSIS=ON -DENABLE_CCACHE=OFF -B build/analysis",
"analysis:no-llvm": "bun run analysis -DENABLE_LLVM=OFF",
"clang-format": "bun run analysis --target clang-format",
"clang-format:check": "bun run analysis --target clang-format-check",
"clang-format:diff": "bun run analysis --target clang-format-diff",
"clang-tidy": "bun run analysis --target clang-tidy",
"clang-tidy:check": "bun run analysis --target clang-tidy-check",
"clang-tidy:diff": "bun run analysis --target clang-tidy-diff",
"zig-format": "bun run analysis:no-llvm --target zig-format",
"zig-format:check": "bun run analysis:no-llvm --target zig-format-check",
"zig-format:diff": "bun run analysis:no-llvm --target zig-format-diff",
"prettier": "bun run analysis:no-llvm --target prettier",
"prettier:check": "bun run analysis:no-llvm --target prettier-check",
"prettier:extra": "bun run analysis:no-llvm --target prettier-extra",
"prettier:diff": "bun run analysis:no-llvm --target prettier-diff"
"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"
}
}

View File

@@ -0,0 +1,4 @@
bin/bun-profile
bin/*.o
*.o
*.a

View File

@@ -2,27 +2,13 @@ import type { InspectorEventMap } from "../../../bun-inspector-protocol/src/insp
import type { JSC } from "../../../bun-inspector-protocol/src/protocol";
import type { DAP } from "../protocol";
// @ts-ignore
import { ChildProcess, spawn } from "node:child_process";
import type { ChildProcess } from "node:child_process";
import { spawn } from "node:child_process";
import { EventEmitter } from "node:events";
import { AddressInfo, createServer } from "node:net";
import * as path from "node:path";
import { remoteObjectToString, WebSocketInspector } from "../../../bun-inspector-protocol/index";
import { randomUnixPath, TCPSocketSignal, UnixSignal } from "./signal";
import { WebSocketInspector, remoteObjectToString } from "../../../bun-inspector-protocol/index";
import { UnixSignal, randomUnixPath } from "./signal";
import { Location, SourceMap } from "./sourcemap";
export async function getAvailablePort(): Promise<number> {
const server = createServer();
server.listen(0);
return new Promise((resolve, reject) => {
server.on("listening", () => {
const { port } = server.address() as AddressInfo;
server.close(() => {
resolve(port);
});
});
});
}
const capabilities: DAP.Capabilities = {
supportsConfigurationDoneRequest: true,
supportsFunctionBreakpoints: true,
@@ -503,73 +489,36 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
...env,
};
if (process.platform !== "win32") {
// we're on unix
const url = `ws+unix://${randomUnixPath()}`;
const signal = new UnixSignal();
const url = `ws+unix://${randomUnixPath()}`;
const signal = new UnixSignal();
signal.on("Signal.received", () => {
this.#attach({ url });
});
signal.on("Signal.received", () => {
this.#attach({ url });
});
this.once("Adapter.terminated", () => {
signal.close();
});
this.once("Adapter.terminated", () => {
signal.close();
});
const query = stopOnEntry ? "break=1" : "wait=1";
processEnv["BUN_INSPECT"] = `${url}?${query}`;
processEnv["BUN_INSPECT_NOTIFY"] = signal.url;
const query = stopOnEntry ? "break=1" : "wait=1";
processEnv["BUN_INSPECT"] = `${url}?${query}`;
processEnv["BUN_INSPECT_NOTIFY"] = signal.url;
// This is probably not correct, but it's the best we can do for now.
processEnv["FORCE_COLOR"] = "1";
processEnv["BUN_QUIET_DEBUG_LOGS"] = "1";
processEnv["BUN_DEBUG_QUIET_LOGS"] = "1";
// This is probably not correct, but it's the best we can do for now.
processEnv["FORCE_COLOR"] = "1";
processEnv["BUN_QUIET_DEBUG_LOGS"] = "1";
processEnv["BUN_DEBUG_QUIET_LOGS"] = "1";
const started = await this.#spawn({
command: runtime,
args: processArgs,
env: processEnv,
cwd,
isDebugee: true,
});
const started = await this.#spawn({
command: runtime,
args: processArgs,
env: processEnv,
cwd,
isDebugee: true,
});
if (!started) {
throw new Error("Program could not be started.");
}
} else {
// we're on windows
// Create TCPSocketSignal
const url = `ws://127.0.0.1:${await getAvailablePort()}/${getRandomId()}`; // 127.0.0.1 so it resolves correctly on windows
const signal = new TCPSocketSignal(await getAvailablePort());
signal.on("Signal.received", async () => {
this.#attach({ url });
});
this.once("Adapter.terminated", () => {
signal.close();
});
const query = stopOnEntry ? "break=1" : "wait=1";
processEnv["BUN_INSPECT"] = `${url}?${query}`;
processEnv["BUN_INSPECT_NOTIFY"] = signal.url; // 127.0.0.1 so it resolves correctly on windows
// This is probably not correct, but it's the best we can do for now.
processEnv["FORCE_COLOR"] = "1";
processEnv["BUN_QUIET_DEBUG_LOGS"] = "1";
processEnv["BUN_DEBUG_QUIET_LOGS"] = "1";
const started = await this.#spawn({
command: runtime,
args: processArgs,
env: processEnv,
cwd,
isDebugee: true,
});
if (!started) {
throw new Error("Program could not be started.");
}
if (!started) {
throw new Error("Program could not be started.");
}
}
@@ -735,9 +684,6 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
async breakpointLocations(request: DAP.BreakpointLocationsRequest): Promise<DAP.BreakpointLocationsResponse> {
const { line, endLine, column, endColumn, source: source0 } = request;
if (process.platform === "win32") {
source0.path = source0.path ? normalizeWindowsPath(source0.path) : source0.path;
}
const source = await this.#getSource(sourceToId(source0));
const { locations } = await this.send("Debugger.getBreakpointLocations", {
@@ -842,9 +788,6 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
}
async #setBreakpointsByUrl(url: string, requests: DAP.SourceBreakpoint[], unsetOld?: boolean): Promise<Breakpoint[]> {
if (process.platform === "win32") {
url = url ? normalizeWindowsPath(url) : url;
}
const source = this.#getSourceIfPresent(url);
// If the source is not loaded, set a placeholder breakpoint at the start of the file.
@@ -1218,9 +1161,6 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
async gotoTargets(request: DAP.GotoTargetsRequest): Promise<DAP.GotoTargetsResponse> {
const { source: source0 } = request;
if (process.platform === "win32") {
source0.path = source0.path ? normalizeWindowsPath(source0.path) : source0.path;
}
const source = await this.#getSource(sourceToId(source0));
const { breakpoints } = await this.breakpointLocations(request);
@@ -1387,7 +1327,7 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
// 1. If it has a `path`, the client retrieves the source from the file system.
// 2. If it has a `sourceReference`, the client sends a `source` request.
// Moreover, the code is usually shown in a read-only editor.
const isUserCode = path.isAbsolute(url);
const isUserCode = url.startsWith("/");
const sourceMap = SourceMap(sourceMapURL);
const name = sourceName(url);
const presentationHint = sourcePresentationHint(url);
@@ -1706,11 +1646,12 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
// If the source does not have a path or is a builtin module,
// it cannot be retrieved from the file system.
if (typeof sourceId === "number" || !path.isAbsolute(sourceId)) {
if (typeof sourceId === "number" || !sourceId.startsWith("/")) {
throw new Error(`Source not found: ${sourceId}`);
}
// If the source is not present, it may not have been loaded yet.
// In that case, wait for it to be loaded.
let resolves = this.#pendingSources.get(sourceId);
if (!resolves) {
this.#pendingSources.set(sourceId, (resolves = []));
@@ -2166,6 +2107,7 @@ export class DebugAdapter extends EventEmitter<DebugAdapterEventMap> implements
close(): void {
this.#process?.kill();
// this.#signal?.close();
this.#inspector.close();
this.#reset();
}
@@ -2207,10 +2149,10 @@ function titleize(name: string): string {
}
function sourcePresentationHint(url?: string): DAP.Source["presentationHint"] {
if (!url || !path.isAbsolute(url)) {
if (!url || !url.startsWith("/")) {
return "deemphasize";
}
if (url.includes("/node_modules/") || url.includes("\\node_modules\\")) {
if (url.includes("/node_modules/")) {
return "normal";
}
return "emphasize";
@@ -2221,9 +2163,6 @@ function sourceName(url?: string): string {
return "unknown.js";
}
if (isJavaScript(url)) {
if (process.platform === "win32") {
url = url.replaceAll("\\", "/");
}
return url.split("/").pop() || url;
}
return `${url}.js`;
@@ -2628,15 +2567,3 @@ let sequence = 1;
function nextId(): number {
return sequence++;
}
export function getRandomId() {
return Math.random().toString(36).slice(2);
}
export function normalizeWindowsPath(winPath: string): string {
winPath = path.normalize(winPath);
if (winPath[1] === ":" && (winPath[2] === "\\" || winPath[2] === "/")) {
return (winPath.charAt(0).toUpperCase() + winPath.slice(1)).replaceAll("\\\\", "\\");
}
return winPath;
}

View File

@@ -1,5 +1,5 @@
import { EventEmitter } from "node:events";
import type { Server, Socket } from "node:net";
import type { Server } from "node:net";
import { createServer } from "node:net";
import { tmpdir } from "node:os";
import { join } from "node:path";
@@ -85,75 +85,3 @@ function parseUnixPath(path: string | URL): string {
throw new Error(`Invalid UNIX path: ${path}`);
}
}
export type TCPSocketSignalEventMap = {
"Signal.listening": [];
"Signal.error": [Error];
"Signal.closed": [];
"Signal.received": [string];
};
export class TCPSocketSignal extends EventEmitter {
#port: number;
#server: ReturnType<typeof createServer>;
#ready: Promise<void>;
constructor(port: number) {
super();
this.#port = port;
this.#server = createServer((socket: Socket) => {
socket.on("data", data => {
this.emit("Signal.received", data.toString());
});
socket.on("error", error => {
this.emit("Signal.error", error);
});
socket.on("close", () => {
this.emit("Signal.closed");
});
});
this.#ready = new Promise((resolve, reject) => {
this.#server.listen(this.#port, () => {
this.emit("Signal.listening");
resolve();
});
this.#server.on("error", reject);
});
}
emit<E extends keyof TCPSocketSignalEventMap>(event: E, ...args: TCPSocketSignalEventMap[E]): boolean {
if (isDebug) {
console.log(event, ...args);
}
return super.emit(event, ...args);
}
/**
* The TCP port.
*/
get port(): number {
return this.#port;
}
get url(): string {
return `tcp://127.0.0.1:${this.#port}`;
}
/**
* Resolves when the server is listening or rejects if an error occurs.
*/
get ready(): Promise<void> {
return this.#ready;
}
/**
* Closes the server.
*/
close(): void {
this.#server.close();
}
}

View File

@@ -0,0 +1,4 @@
bin/bun-profile
bin/*.o
*.o
*.a

View File

@@ -0,0 +1,3 @@
# `bun-plugin-css`
Not implemented.

Some files were not shown because too many files have changed in this diff Show More