mirror of
https://github.com/oven-sh/bun
synced 2026-02-07 01:18:51 +00:00
Compare commits
53 Commits
fix-14345
...
fix-format
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88063eaad5 | ||
|
|
da2d1e12ed | ||
|
|
6b54dbfa07 | ||
|
|
1dfa557ca4 | ||
|
|
29d1b4db74 | ||
|
|
85edb39a2f | ||
|
|
f0384f39b7 | ||
|
|
2e1b19b9fd | ||
|
|
53ce1ff6c1 | ||
|
|
eee9b51df3 | ||
|
|
f0036cc6c1 | ||
|
|
77a25c0188 | ||
|
|
a3777b8c22 | ||
|
|
0d9d7a3436 | ||
|
|
d5e7846eaf | ||
|
|
582a53e26e | ||
|
|
57d9cfc24d | ||
|
|
31dc58fa79 | ||
|
|
03bb9fd9b5 | ||
|
|
f270f235c8 | ||
|
|
8d1b5856d3 | ||
|
|
bf488d0b19 | ||
|
|
9dc0672840 | ||
|
|
b1d0cb0ea3 | ||
|
|
155ba7ebdf | ||
|
|
3757a3e30f | ||
|
|
4b443db0d8 | ||
|
|
d74ae08946 | ||
|
|
a7a5ed2fba | ||
|
|
7d7c9877a4 | ||
|
|
1cd43f5bae | ||
|
|
56b6ed6d97 | ||
|
|
85dd8ef0d4 | ||
|
|
6cb0de3921 | ||
|
|
2c1dcb5a1d | ||
|
|
d3f3900da7 | ||
|
|
ef18731db1 | ||
|
|
7fb15e5a03 | ||
|
|
2b017cd0ad | ||
|
|
9f857fa418 | ||
|
|
1cde69d0f1 | ||
|
|
800e378b6e | ||
|
|
dfe8fb50d9 | ||
|
|
0f6cfc0b16 | ||
|
|
019cfb7927 | ||
|
|
7887689fd0 | ||
|
|
888d8301ca | ||
|
|
704c169e04 | ||
|
|
c16e34078a | ||
|
|
bc9e022c86 | ||
|
|
a88b8130b9 | ||
|
|
2139e8442a | ||
|
|
f50a80a7c1 |
@@ -12,14 +12,14 @@ steps:
|
||||
- key: "darwin-aarch64"
|
||||
group: ":darwin: aarch64"
|
||||
steps:
|
||||
- key: "darwin-aarch64-build-deps"
|
||||
label: ":darwin: aarch64 - build-deps"
|
||||
- key: "darwin-aarch64-build-vendor"
|
||||
label: ":darwin: aarch64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-darwin"
|
||||
os: "darwin"
|
||||
arch: "aarch64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "darwin-aarch64-build-cpp"
|
||||
label: ":darwin: aarch64 - build-cpp"
|
||||
@@ -46,7 +46,7 @@ steps:
|
||||
os: "darwin"
|
||||
arch: "aarch64"
|
||||
depends_on:
|
||||
- "darwin-aarch64-build-deps"
|
||||
- "darwin-aarch64-build-vendor"
|
||||
- "darwin-aarch64-build-cpp"
|
||||
- "darwin-aarch64-build-zig"
|
||||
env:
|
||||
@@ -114,14 +114,14 @@ steps:
|
||||
- key: "darwin-x64"
|
||||
group: ":darwin: x64"
|
||||
steps:
|
||||
- key: "darwin-x64-build-deps"
|
||||
label: ":darwin: x64 - build-deps"
|
||||
- key: "darwin-x64-build-vendor"
|
||||
label: ":darwin: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-darwin"
|
||||
os: "darwin"
|
||||
arch: "x64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "darwin-x64-build-cpp"
|
||||
label: ":darwin: x64 - build-cpp"
|
||||
@@ -148,7 +148,7 @@ steps:
|
||||
os: "darwin"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "darwin-x64-build-deps"
|
||||
- "darwin-x64-build-vendor"
|
||||
- "darwin-x64-build-cpp"
|
||||
- "darwin-x64-build-zig"
|
||||
env:
|
||||
@@ -216,14 +216,14 @@ steps:
|
||||
- key: "linux-x64"
|
||||
group: ":linux: x64"
|
||||
steps:
|
||||
- key: "linux-x64-build-deps"
|
||||
label: ":linux: x64 - build-deps"
|
||||
- key: "linux-x64-build-vendor"
|
||||
label: ":linux: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-x64-build-cpp"
|
||||
label: ":linux: x64 - build-cpp"
|
||||
@@ -250,7 +250,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "linux-x64-build-deps"
|
||||
- "linux-x64-build-vendor"
|
||||
- "linux-x64-build-cpp"
|
||||
- "linux-x64-build-zig"
|
||||
env:
|
||||
@@ -349,8 +349,8 @@ steps:
|
||||
- key: "linux-x64-baseline"
|
||||
group: ":linux: x64-baseline"
|
||||
steps:
|
||||
- key: "linux-x64-baseline-build-deps"
|
||||
label: ":linux: x64-baseline - build-deps"
|
||||
- key: "linux-x64-baseline-build-vendor"
|
||||
label: ":linux: x64-baseline - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
@@ -358,7 +358,7 @@ steps:
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-x64-baseline-build-cpp"
|
||||
label: ":linux: x64-baseline - build-cpp"
|
||||
@@ -388,7 +388,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "linux-x64-baseline-build-deps"
|
||||
- "linux-x64-baseline-build-vendor"
|
||||
- "linux-x64-baseline-build-cpp"
|
||||
- "linux-x64-baseline-build-zig"
|
||||
env:
|
||||
@@ -488,14 +488,14 @@ steps:
|
||||
- key: "linux-aarch64"
|
||||
group: ":linux: aarch64"
|
||||
steps:
|
||||
- key: "linux-aarch64-build-deps"
|
||||
label: ":linux: aarch64 - build-deps"
|
||||
- key: "linux-aarch64-build-vendor"
|
||||
label: ":linux: aarch64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-linux"
|
||||
os: "linux"
|
||||
arch: "aarch64"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "linux-aarch64-build-cpp"
|
||||
label: ":linux: aarch64 - build-cpp"
|
||||
@@ -522,7 +522,7 @@ steps:
|
||||
os: "linux"
|
||||
arch: "aarch64"
|
||||
depends_on:
|
||||
- "linux-aarch64-build-deps"
|
||||
- "linux-aarch64-build-vendor"
|
||||
- "linux-aarch64-build-cpp"
|
||||
- "linux-aarch64-build-zig"
|
||||
env:
|
||||
@@ -621,18 +621,14 @@ steps:
|
||||
- key: "windows-x64"
|
||||
group: ":windows: x64"
|
||||
steps:
|
||||
- key: "windows-x64-build-deps"
|
||||
label: ":windows: x64 - build-deps"
|
||||
- key: "windows-x64-build-vendor"
|
||||
label: ":windows: x64 - build-vendor"
|
||||
agents:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "windows-x64-build-cpp"
|
||||
label: ":windows: x64 - build-cpp"
|
||||
@@ -640,10 +636,6 @@ steps:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
BUN_CPP_ONLY: "ON"
|
||||
command:
|
||||
@@ -663,13 +655,9 @@ steps:
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "windows-x64-build-deps"
|
||||
- "windows-x64-build-vendor"
|
||||
- "windows-x64-build-cpp"
|
||||
- "windows-x64-build-zig"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
BUN_LINK_ONLY: "ON"
|
||||
command:
|
||||
@@ -704,20 +692,16 @@ steps:
|
||||
- key: "windows-x64-baseline"
|
||||
group: ":windows: x64-baseline"
|
||||
steps:
|
||||
- key: "windows-x64-baseline-build-deps"
|
||||
label: ":windows: x64-baseline - build-deps"
|
||||
- key: "windows-x64-baseline-build-vendor"
|
||||
label: ":windows: x64-baseline - build-vendor"
|
||||
agents:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
command:
|
||||
- "bun run build:ci --target dependencies"
|
||||
- "bun run build:ci --target vendor"
|
||||
|
||||
- key: "windows-x64-baseline-build-cpp"
|
||||
label: ":windows: x64-baseline - build-cpp"
|
||||
@@ -725,10 +709,6 @@ steps:
|
||||
queue: "build-windows"
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
BUN_CPP_ONLY: "ON"
|
||||
@@ -751,13 +731,9 @@ steps:
|
||||
os: "windows"
|
||||
arch: "x64"
|
||||
depends_on:
|
||||
- "windows-x64-baseline-build-deps"
|
||||
- "windows-x64-baseline-build-vendor"
|
||||
- "windows-x64-baseline-build-cpp"
|
||||
- "windows-x64-baseline-build-zig"
|
||||
retry:
|
||||
automatic:
|
||||
- exit_status: 255
|
||||
limit: 5
|
||||
env:
|
||||
ENABLE_BASELINE: "ON"
|
||||
BUN_LINK_ONLY: "ON"
|
||||
|
||||
1539
.docker/chrome.json
Normal file
1539
.docker/chrome.json
Normal file
File diff suppressed because it is too large
Load Diff
14
.docker/chromium.pref
Normal file
14
.docker/chromium.pref
Normal 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
|
||||
8
.docker/copy-bun-binary.sh
Normal file
8
.docker/copy-bun-binary.sh
Normal 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
3
.docker/debian.list
Normal 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
|
||||
34
.docker/dockerfile-common.sh
Normal file
34
.docker/dockerfile-common.sh
Normal 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
11
.docker/pull.sh
Normal 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
47
.docker/run-dockerfile.sh
Normal 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
9
.docker/run-test.sh
Executable 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
5
.docker/runner.sh
Normal 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
5
.docker/unit-tests.sh
Normal 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
|
||||
1
.github/actions/setup-bun/action.yml
vendored
1
.github/actions/setup-bun/action.yml
vendored
@@ -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}
|
||||
|
||||
40
.github/workflows/clang-format.yml
vendored
40
.github/workflows/clang-format.yml
vendored
@@ -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:diff
|
||||
- name: Commit
|
||||
uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "`bun run clang-format`"
|
||||
40
.github/workflows/clang-tidy.yml
vendored
40
.github/workflows/clang-tidy.yml
vendored
@@ -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
61
.github/workflows/format.yml
vendored
Normal 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
|
||||
30
.github/workflows/lint-cpp.yml
vendored
Normal file
30
.github/workflows/lint-cpp.yml
vendored
Normal 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 }}
|
||||
36
.github/workflows/prettier-format.yml
vendored
36
.github/workflows/prettier-format.yml
vendored
@@ -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
56
.github/workflows/run-format.yml
vendored
Normal 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
84
.github/workflows/run-lint-cpp.yml
vendored
Normal 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
|
||||
33
.github/workflows/zig-format.yml
vendored
33
.github/workflows/zig-format.yml
vendored
@@ -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
3
.gitignore
vendored
@@ -142,6 +142,9 @@ test/node.js/upstream
|
||||
scripts/env.local
|
||||
*.generated.ts
|
||||
|
||||
# Temporary files
|
||||
/tmp
|
||||
|
||||
# Dependencies
|
||||
/vendor
|
||||
|
||||
|
||||
31
.prettierrc-ci
Normal file
31
.prettierrc-ci
Normal 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
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
2
.vscode/launch.json
generated
vendored
2
.vscode/launch.json
generated
vendored
@@ -1192,4 +1192,4 @@
|
||||
"description": "Usage: bun test [...]",
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -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
52
.vscode/tasks.json
vendored
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Install Dependencies",
|
||||
"command": "scripts/all-dependencies.sh",
|
||||
"windows": {
|
||||
"command": "scripts/all-dependencies.ps1",
|
||||
},
|
||||
"icon": {
|
||||
"id": "arrow-down",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Setup Environment",
|
||||
"dependsOn": ["Install Dependencies"],
|
||||
"command": "scripts/setup.sh",
|
||||
"windows": {
|
||||
"command": "scripts/setup.ps1",
|
||||
},
|
||||
"icon": {
|
||||
"id": "check",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
},
|
||||
{
|
||||
"type": "process",
|
||||
"label": "Build Bun",
|
||||
"dependsOn": ["Setup Environment"],
|
||||
"command": "bun",
|
||||
"args": ["run", "build"],
|
||||
"icon": {
|
||||
"id": "gear",
|
||||
},
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
},
|
||||
"isBuildCommand": true,
|
||||
"runOptions": {
|
||||
"instanceLimit": 1,
|
||||
"reevaluateOnRerun": true,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -116,19 +116,35 @@ $ 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.
|
||||
|
||||
27
Makefile
27
Makefile
@@ -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
|
||||
|
||||
|
||||
BIN
bench/bun.lockb
BIN
bench/bun.lockb
Binary file not shown.
@@ -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();
|
||||
@@ -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": {
|
||||
|
||||
@@ -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();
|
||||
11
build.zig
11
build.zig
@@ -52,7 +52,7 @@ 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
|
||||
@@ -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}) };
|
||||
// };
|
||||
@@ -295,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.
|
||||
|
||||
@@ -368,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,
|
||||
@@ -475,8 +474,8 @@ 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 = "bake.client.js", .import = "bake-codegen/bake.client.js", .enable = opts.shouldEmbedCode() },
|
||||
.{ .file = "bake.server.js", .import = "bake-codegen/bake.server.js", .enable = opts.shouldEmbedCode() },
|
||||
.{ .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.generated_code_dir, entry.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.
|
||||
|
||||
1084
cmake/Globals.cmake
1084
cmake/Globals.cmake
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
|
||||
set(CLANG_FORMAT_SOURCES ${BUN_C_SOURCES} ${BUN_CXX_SOURCES})
|
||||
find_command(
|
||||
VARIABLE
|
||||
CLANG_FORMAT_PROGRAM
|
||||
COMMAND
|
||||
clang-format
|
||||
REQUIRED
|
||||
OFF
|
||||
)
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
@@ -12,8 +17,8 @@ register_command(
|
||||
-Werror
|
||||
--dry-run
|
||||
--verbose
|
||||
${CLANG_FORMAT_SOURCES}
|
||||
ALWAYS_RUN
|
||||
${BUN_C_SOURCES}
|
||||
${BUN_CXX_SOURCES}
|
||||
)
|
||||
|
||||
register_command(
|
||||
@@ -25,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}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -1,21 +1,31 @@
|
||||
register_vendor_target(boringssl)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
boringssl
|
||||
${boringssl}
|
||||
REPOSITORY
|
||||
oven-sh/boringssl
|
||||
COMMIT
|
||||
29a2cd359458c9384694b75456026e4b57e3e567
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
register_libraries(
|
||||
TARGET ${boringssl}
|
||||
crypto
|
||||
ssl
|
||||
decrepit
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
boringssl
|
||||
LIBRARIES
|
||||
${boringssl}
|
||||
CMAKE_TARGET
|
||||
crypto
|
||||
ssl
|
||||
decrepit
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
INCLUDES
|
||||
include
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${boringssl}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
)
|
||||
|
||||
@@ -1,31 +1,43 @@
|
||||
register_vendor_target(brotli)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
brotli
|
||||
${brotli}
|
||||
REPOSITORY
|
||||
google/brotli
|
||||
TAG
|
||||
v1.1.0
|
||||
COMMIT
|
||||
ed738e842d2fbdf2d6459e39267a633c4a9b2f5d
|
||||
)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${brotli}
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${brotli}
|
||||
CMAKE_TARGET
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${brotli}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
BROTLI_BUILD_TOOLS=OFF
|
||||
BROTLI_EMSCRIPTEN=OFF
|
||||
BROTLI_DISABLE_TESTS=ON
|
||||
)
|
||||
|
||||
# Tests fail with "BrotliDecompressionError" when LTO is enabled
|
||||
# only on Linux x64 (non-baseline). It's a mystery.
|
||||
if(LINUX AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64" AND NOT ENABLE_BASELINE)
|
||||
set(BROTLI_CMAKE_ARGS "-DCMAKE_C_FLAGS=-fno-lto")
|
||||
if(LINUX AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64" AND NOT ENABLE_BASELINE)
|
||||
register_compiler_flags(
|
||||
TARGET ${brotli}
|
||||
-fno-lto
|
||||
)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
brotli
|
||||
LIBRARIES
|
||||
brotlicommon
|
||||
brotlidec
|
||||
brotlienc
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DBROTLI_BUILD_TOOLS=OFF
|
||||
-DBROTLI_EMSCRIPTEN=OFF
|
||||
-DBROTLI_DISABLE_TESTS=ON
|
||||
${BROTLI_CMAKE_ARGS}
|
||||
INCLUDES
|
||||
c/include
|
||||
)
|
||||
|
||||
@@ -12,15 +12,6 @@ else()
|
||||
set(bunStrip bun)
|
||||
endif()
|
||||
|
||||
set(bunExe ${bun}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
|
||||
if(bunStrip)
|
||||
set(bunStripExe ${bunStrip}${CMAKE_EXECUTABLE_SUFFIX})
|
||||
set(buns ${bun} ${bunStrip})
|
||||
else()
|
||||
set(buns ${bun})
|
||||
endif()
|
||||
|
||||
# Some commands use this path, and some do not.
|
||||
# In the future, change those commands so that generated files are written to this path.
|
||||
optionx(CODEGEN_PATH FILEPATH "Path to the codegen directory" DEFAULT ${BUILD_PATH}/codegen)
|
||||
@@ -60,8 +51,6 @@ register_command(
|
||||
${BUN_ZIG_IDENTIFIER_SCRIPT}
|
||||
SOURCES
|
||||
${BUN_ZIG_IDENTIFIER_SOURCES}
|
||||
TARGETS
|
||||
clone-zig
|
||||
OUTPUTS
|
||||
${BUN_ZIG_IDENTIFIER_OUTPUTS}
|
||||
)
|
||||
@@ -324,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)
|
||||
@@ -399,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
|
||||
@@ -409,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)
|
||||
@@ -478,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}
|
||||
@@ -503,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)
|
||||
@@ -550,17 +548,15 @@ register_command(
|
||||
-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)
|
||||
|
||||
@@ -573,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
|
||||
)
|
||||
@@ -586,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}
|
||||
@@ -629,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})
|
||||
@@ -652,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
|
||||
@@ -685,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)
|
||||
@@ -699,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
|
||||
@@ -707,7 +666,6 @@ target_include_directories(${bun} PRIVATE
|
||||
${CODEGEN_PATH}
|
||||
${VENDOR_PATH}
|
||||
${VENDOR_PATH}/picohttpparser
|
||||
${NODEJS_HEADERS_PATH}/include
|
||||
)
|
||||
|
||||
# --- C/C++ Definitions ---
|
||||
@@ -741,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
|
||||
@@ -758,7 +715,6 @@ if(DEBUG AND NOT CI)
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
# --- Compiler options ---
|
||||
|
||||
if(NOT WIN32)
|
||||
@@ -883,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
|
||||
@@ -940,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
|
||||
@@ -978,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)
|
||||
@@ -1051,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(
|
||||
@@ -1062,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()
|
||||
|
||||
@@ -1083,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}
|
||||
)
|
||||
@@ -1105,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}
|
||||
@@ -1114,7 +1071,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(CMAKE_HOST_APPLE AND bunStrip)
|
||||
if(bunStrip AND APPLE)
|
||||
register_command(
|
||||
TARGET
|
||||
${bun}
|
||||
@@ -1144,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)
|
||||
@@ -1181,7 +1138,7 @@ if(NOT BUN_CPP_ONLY)
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E rm -rf ${bunStripPath} ${bunStripPath}.zip
|
||||
&& ${CMAKE_COMMAND} -E make_directory ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E copy ${bunStripExe} ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E copy ${${BUN_EXE_STRIP_OUTPUT}} ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E tar cfv ${bunStripPath}.zip --format=zip ${bunStripPath}
|
||||
&& ${CMAKE_COMMAND} -E rm -rf ${bunStripPath}
|
||||
CWD
|
||||
|
||||
@@ -1,27 +1,32 @@
|
||||
register_vendor_target(cares)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
cares
|
||||
${cares}
|
||||
REPOSITORY
|
||||
c-ares/c-ares
|
||||
COMMIT
|
||||
d1722e6e8acaf10eb73fa995798a9cd421d9f85e
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
cares
|
||||
TARGETS
|
||||
c-ares
|
||||
ARGS
|
||||
-DCARES_STATIC=ON
|
||||
-DCARES_STATIC_PIC=ON # FORCE_PIC was set to 1, but CARES_STATIC_PIC was set to OFF??
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DCARES_SHARED=OFF
|
||||
-DCARES_BUILD_TOOLS=OFF # this was set to ON?
|
||||
LIB_PATH
|
||||
lib
|
||||
LIBRARIES
|
||||
cares
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${cares}
|
||||
PATH lib
|
||||
cares
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${cares}
|
||||
CMAKE_TARGET
|
||||
c-ares
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${cares}
|
||||
CARES_STATIC=ON
|
||||
CARES_STATIC_PIC=ON
|
||||
CARES_SHARED=OFF
|
||||
CARES_BUILD_TOOLS=OFF
|
||||
CMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
)
|
||||
|
||||
@@ -1,53 +1,61 @@
|
||||
register_vendor_target(libarchive)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libarchive
|
||||
${libarchive}
|
||||
REPOSITORY
|
||||
libarchive/libarchive
|
||||
COMMIT
|
||||
898dc8319355b7e985f68a9819f182aaed61b53a
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libarchive
|
||||
TARGETS
|
||||
archive_static
|
||||
ARGS
|
||||
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DENABLE_INSTALL=OFF
|
||||
-DENABLE_TEST=OFF
|
||||
-DENABLE_WERROR=OFF
|
||||
-DENABLE_BZIP2=OFF
|
||||
-DENABLE_CAT=OFF
|
||||
-DENABLE_EXPAT=OFF
|
||||
-DENABLE_ICONV=OFF
|
||||
-DENABLE_LIBB2=OFF
|
||||
-DENABLE_LibGCC=OFF
|
||||
-DENABLE_LIBXML2=OFF
|
||||
-DENABLE_LZ4=OFF
|
||||
-DENABLE_LZMA=OFF
|
||||
-DENABLE_LZO=OFF
|
||||
-DENABLE_MBEDTLS=OFF
|
||||
-DENABLE_NETTLE=OFF
|
||||
-DENABLE_OPENSSL=OFF
|
||||
-DENABLE_PCRE2POSIX=OFF
|
||||
-DENABLE_PCREPOSIX=OFF
|
||||
-DENABLE_ZSTD=OFF
|
||||
# libarchive depends on zlib headers, otherwise it will
|
||||
# spawn a processes to compress instead of using the library.
|
||||
-DENABLE_ZLIB=OFF
|
||||
-DHAVE_ZLIB_H=ON
|
||||
-DCMAKE_C_FLAGS="-I${VENDOR_PATH}/zlib"
|
||||
LIB_PATH
|
||||
libarchive
|
||||
LIBRARIES
|
||||
archive
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${libarchive}
|
||||
PATH libarchive
|
||||
archive
|
||||
)
|
||||
|
||||
# Must be loaded after zlib is defined
|
||||
if(TARGET clone-zlib)
|
||||
add_dependencies(libarchive clone-zlib)
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libarchive}
|
||||
CMAKE_TARGET
|
||||
archive_static
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libarchive}
|
||||
CMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
ENABLE_INSTALL=OFF
|
||||
ENABLE_TEST=OFF
|
||||
ENABLE_WERROR=OFF
|
||||
ENABLE_BZIP2=OFF
|
||||
ENABLE_CAT=OFF
|
||||
ENABLE_EXPAT=OFF
|
||||
ENABLE_ICONV=OFF
|
||||
ENABLE_LIBB2=OFF
|
||||
ENABLE_LibGCC=OFF
|
||||
ENABLE_LIBXML2=OFF
|
||||
ENABLE_LZ4=OFF
|
||||
ENABLE_LZMA=OFF
|
||||
ENABLE_LZO=OFF
|
||||
ENABLE_MBEDTLS=OFF
|
||||
ENABLE_NETTLE=OFF
|
||||
ENABLE_OPENSSL=OFF
|
||||
ENABLE_PCRE2POSIX=OFF
|
||||
ENABLE_PCREPOSIX=OFF
|
||||
ENABLE_ZSTD=OFF
|
||||
ENABLE_ZLIB=OFF
|
||||
HAVE_ZLIB_H=ON
|
||||
)
|
||||
|
||||
# libarchive depends on zlib headers, otherwise it will
|
||||
# spawn a processes to compress instead of using the library.
|
||||
register_includes(
|
||||
TARGET ${libarchive}
|
||||
${VENDOR_PATH}/${zlib}
|
||||
)
|
||||
|
||||
if(TARGET clone-${zlib})
|
||||
add_dependencies(${libarchive} clone-${zlib})
|
||||
endif()
|
||||
|
||||
@@ -1,24 +1,30 @@
|
||||
register_vendor_target(libdeflate)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libdeflate
|
||||
${libdeflate}
|
||||
REPOSITORY
|
||||
ebiggers/libdeflate
|
||||
COMMIT
|
||||
dc76454a39e7e83b68c3704b6e3784654f8d5ac5
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libdeflate
|
||||
TARGETS
|
||||
libdeflate_static
|
||||
ARGS
|
||||
-DLIBDEFLATE_BUILD_STATIC_LIB=ON
|
||||
-DLIBDEFLATE_BUILD_SHARED_LIB=OFF
|
||||
-DLIBDEFLATE_BUILD_GZIP=OFF
|
||||
LIBRARIES
|
||||
deflatestatic WIN32
|
||||
deflate UNIX
|
||||
INCLUDES
|
||||
.
|
||||
register_libraries(
|
||||
TARGET ${libdeflate}
|
||||
deflatestatic ${WIN32}
|
||||
deflate ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libdeflate}
|
||||
CMAKE_TARGET
|
||||
libdeflate_static
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libdeflate}
|
||||
LIBDEFLATE_BUILD_STATIC_LIB=ON
|
||||
LIBDEFLATE_BUILD_SHARED_LIB=OFF
|
||||
LIBDEFLATE_BUILD_GZIP=OFF
|
||||
)
|
||||
|
||||
@@ -1,29 +1,39 @@
|
||||
register_vendor_target(libuv)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
libuv
|
||||
${libuv}
|
||||
REPOSITORY
|
||||
libuv/libuv
|
||||
COMMIT
|
||||
da527d8d2a908b824def74382761566371439003
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LIBUV_CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS -Wno-int-conversion")
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
libuv
|
||||
TARGETS
|
||||
uv_a
|
||||
ARGS
|
||||
-DLIBUV_BUILD_SHARED=OFF
|
||||
-DLIBUV_BUILD_TESTS=OFF
|
||||
-DLIBUV_BUILD_BENCH=OFF
|
||||
-DCMAKE_C_FLAGS=${LIBUV_CMAKE_C_FLAGS}
|
||||
LIBRARIES
|
||||
libuv WIN32
|
||||
uv UNIX
|
||||
INCLUDES
|
||||
include
|
||||
register_libraries(
|
||||
TARGET ${libuv}
|
||||
uv_a ${WIN32}
|
||||
uv ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${libuv}
|
||||
CMAKE_TARGET
|
||||
uv_a
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${libuv}
|
||||
LIBUV_BUILD_SHARED=OFF
|
||||
LIBUV_BUILD_TESTS=OFF
|
||||
LIBUV_BUILD_BENCH=OFF
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
register_compiler_flags(
|
||||
TARGET ${libuv}
|
||||
/DWIN32
|
||||
/D_WINDOWS
|
||||
-Wno-int-conversion
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,45 +1,50 @@
|
||||
register_vendor_target(lolhtml)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
lolhtml
|
||||
${lolhtml}
|
||||
REPOSITORY
|
||||
cloudflare/lol-html
|
||||
COMMIT
|
||||
8d4c273ded322193d017042d1f48df2766b0f88b
|
||||
)
|
||||
|
||||
set(LOLHTML_CWD ${VENDOR_PATH}/lolhtml/c-api)
|
||||
set(LOLHTML_BUILD_PATH ${BUILD_PATH}/lolhtml)
|
||||
|
||||
if(DEBUG)
|
||||
set(LOLHTML_BUILD_TYPE debug)
|
||||
set(${lolhtml}_BUILD_TYPE debug)
|
||||
else()
|
||||
set(LOLHTML_BUILD_TYPE release)
|
||||
set(${lolhtml}_BUILD_TYPE release)
|
||||
endif()
|
||||
|
||||
set(LOLHTML_LIBRARY ${LOLHTML_BUILD_PATH}/${LOLHTML_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}lolhtml${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||
register_libraries(
|
||||
TARGET ${lolhtml}
|
||||
PATH ${${lolhtml}_BUILD_TYPE}
|
||||
VARIABLE ${lolhtml}_LIBRARY
|
||||
lolhtml
|
||||
)
|
||||
|
||||
set(LOLHTML_BUILD_ARGS
|
||||
--target-dir ${BUILD_PATH}/lolhtml
|
||||
set(${lolhtml}_BUILD_COMMAND
|
||||
${CARGO_EXECUTABLE}
|
||||
build
|
||||
--target-dir ${${lolhtml}_BUILD_PATH}
|
||||
)
|
||||
|
||||
if(RELEASE)
|
||||
list(APPEND LOLHTML_BUILD_ARGS --release)
|
||||
list(APPEND ${lolhtml}_BUILD_COMMAND --release)
|
||||
endif()
|
||||
|
||||
register_command(
|
||||
TARGET
|
||||
lolhtml
|
||||
build-${lolhtml}
|
||||
CWD
|
||||
${LOLHTML_CWD}
|
||||
${${lolhtml}_CWD}/c-api
|
||||
COMMAND
|
||||
${CARGO_EXECUTABLE}
|
||||
build
|
||||
${LOLHTML_BUILD_ARGS}
|
||||
${${lolhtml}_BUILD_COMMAND}
|
||||
ARTIFACTS
|
||||
${LOLHTML_LIBRARY}
|
||||
${${lolhtml}_LIBRARY}
|
||||
)
|
||||
|
||||
target_link_libraries(${bun} PRIVATE ${LOLHTML_LIBRARY})
|
||||
if(BUN_LINK_ONLY)
|
||||
target_sources(${bun} PRIVATE ${LOLHTML_LIBRARY})
|
||||
if(TARGET clone-${lolhtml})
|
||||
add_dependencies(build-${lolhtml} clone-${lolhtml})
|
||||
endif()
|
||||
|
||||
add_dependencies(${lolhtml} build-${lolhtml})
|
||||
|
||||
@@ -1,33 +1,42 @@
|
||||
register_vendor_target(lshpack)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
lshpack
|
||||
${lshpack}
|
||||
REPOSITORY
|
||||
litespeedtech/ls-hpack
|
||||
COMMIT
|
||||
3d0f1fc1d6e66a642e7a98c55deb38aa986eb4b0
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(LSHPACK_INCLUDES . compat/queue)
|
||||
else()
|
||||
set(LSHPACK_INCLUDES .)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
lshpack
|
||||
LIBRARIES
|
||||
ls-hpack
|
||||
ARGS
|
||||
-DSHARED=OFF
|
||||
-DLSHPACK_XXH=ON
|
||||
# There are linking errors when built with non-Release
|
||||
# Undefined symbols for architecture arm64:
|
||||
# "___asan_handle_no_return", referenced from:
|
||||
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
|
||||
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
|
||||
# _update_hash in libls-hpack.a(lshpack.c.o)
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
INCLUDES
|
||||
${LSHPACK_INCLUDES}
|
||||
register_libraries(
|
||||
TARGET ${lshpack}
|
||||
ls-hpack
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${lshpack}
|
||||
CMAKE_TARGET
|
||||
ls-hpack
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${lshpack}
|
||||
SHARED=OFF
|
||||
LSHPACK_XXH=ON
|
||||
BUILD_TESTING=OFF
|
||||
)
|
||||
|
||||
# FIXME: There are linking errors when built with non-Release
|
||||
# Undefined symbols for architecture arm64:
|
||||
# "___asan_handle_no_return", referenced from:
|
||||
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
|
||||
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
|
||||
# _update_hash in libls-hpack.a(lshpack.c.o)
|
||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
register_cmake_definitions(
|
||||
TARGET ${lshpack}
|
||||
CMAKE_BUILD_TYPE=Release
|
||||
)
|
||||
endif()
|
||||
|
||||
@@ -1,60 +1,63 @@
|
||||
register_vendor_target(mimalloc)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
mimalloc
|
||||
${mimalloc}
|
||||
REPOSITORY
|
||||
oven-sh/mimalloc
|
||||
COMMIT
|
||||
4c283af60cdae205df5a872530c77e2a6a307d43
|
||||
)
|
||||
|
||||
set(MIMALLOC_CMAKE_ARGS
|
||||
-DMI_BUILD_STATIC=ON
|
||||
-DMI_BUILD_OBJECT=ON
|
||||
-DMI_BUILD_SHARED=OFF
|
||||
-DMI_BUILD_TESTS=OFF
|
||||
-DMI_USE_CXX=ON
|
||||
-DMI_OVERRIDE=OFF
|
||||
-DMI_OSX_ZONE=OFF
|
||||
-DMI_OSX_INTERPOSE=OFF
|
||||
-DMI_SKIP_COLLECT_ON_EXIT=ON
|
||||
)
|
||||
|
||||
if(DEBUG)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_FULL=ON)
|
||||
endif()
|
||||
|
||||
if(ENABLE_VALGRIND)
|
||||
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_VALGRIND=ON)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
set(MIMALLOC_LIBRARY mimalloc-static-debug)
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY mimalloc-static)
|
||||
endif()
|
||||
elseif(DEBUG)
|
||||
set(MIMALLOC_LIBRARY mimalloc-debug)
|
||||
else()
|
||||
set(MIMALLOC_LIBRARY mimalloc)
|
||||
endif()
|
||||
|
||||
# Workaround for linker issue on macOS and Linux x64
|
||||
# https://github.com/microsoft/mimalloc/issues/512
|
||||
if(APPLE OR (LINUX AND NOT DEBUG))
|
||||
set(MIMALLOC_LIBRARY CMakeFiles/mimalloc-obj.dir/src/static.c.o)
|
||||
register_libraries(
|
||||
TARGET ${mimalloc}
|
||||
PATH CMakeFiles/mimalloc-obj.dir/src
|
||||
static.c.o
|
||||
)
|
||||
else()
|
||||
register_libraries(
|
||||
TARGET ${mimalloc}
|
||||
mimalloc-static-debug ${WIN32} AND ${DEBUG}
|
||||
mimalloc-static ${WIN32} AND ${RELEASE}
|
||||
mimalloc-debug ${UNIX} AND ${DEBUG}
|
||||
mimalloc ${UNIX} AND ${RELEASE}
|
||||
)
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
mimalloc
|
||||
TARGETS
|
||||
${mimalloc}
|
||||
CMAKE_TARGETS
|
||||
mimalloc-static
|
||||
mimalloc-obj
|
||||
ARGS
|
||||
${MIMALLOC_CMAKE_ARGS}
|
||||
LIBRARIES
|
||||
${MIMALLOC_LIBRARY}
|
||||
INCLUDES
|
||||
include
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_BUILD_STATIC=ON
|
||||
MI_BUILD_OBJECT=ON
|
||||
MI_BUILD_SHARED=OFF
|
||||
MI_BUILD_TESTS=OFF
|
||||
MI_USE_CXX=ON
|
||||
MI_OVERRIDE=OFF
|
||||
MI_OSX_ZONE=OFF
|
||||
MI_OSX_INTERPOSE=OFF
|
||||
MI_SKIP_COLLECT_ON_EXIT=ON
|
||||
)
|
||||
|
||||
if(ENABLE_ASSERTIONS)
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_DEBUG_FULL=ON
|
||||
MI_SHOW_ERRORS=ON
|
||||
)
|
||||
if(ENABLE_VALGRIND)
|
||||
register_cmake_definitions(
|
||||
TARGET ${mimalloc}
|
||||
MI_VALGRIND=ON
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
12
cmake/targets/BuildPicoHTTPParser.cmake
Normal file
12
cmake/targets/BuildPicoHTTPParser.cmake
Normal file
@@ -0,0 +1,12 @@
|
||||
register_vendor_target(picohttpparser)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
${picohttpparser}
|
||||
REPOSITORY
|
||||
h2o/picohttpparser
|
||||
COMMIT
|
||||
066d2b1e9ab820703db0837a7255d92d30f0c9f5
|
||||
OUTPUTS
|
||||
picohttpparser.c
|
||||
)
|
||||
@@ -1,10 +1,13 @@
|
||||
register_cmake_command(
|
||||
register_vendor_target(sqlite)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${sqlite}
|
||||
sqlite3
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
sqlite
|
||||
${sqlite}
|
||||
CWD
|
||||
${CWD}/src/bun.js/bindings/sqlite
|
||||
LIBRARIES
|
||||
sqlite3
|
||||
INCLUDES
|
||||
.
|
||||
)
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
register_vendor_target(tinycc)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
tinycc
|
||||
${tinycc}
|
||||
REPOSITORY
|
||||
oven-sh/tinycc
|
||||
COMMIT
|
||||
29985a3b59898861442fa3b43f663fc1af2591d7
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
tinycc
|
||||
LIBRARIES
|
||||
tcc
|
||||
register_libraries(
|
||||
TARGET ${tinycc}
|
||||
tcc
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${tinycc}
|
||||
)
|
||||
|
||||
88
cmake/targets/BuildWebKit.cmake
Normal file
88
cmake/targets/BuildWebKit.cmake
Normal file
@@ -0,0 +1,88 @@
|
||||
optionx(WEBKIT_LOCAL BOOL "If a local version of WebKit should be used instead of downloading" DEFAULT OFF)
|
||||
optionx(WEBKIT_VERSION STRING "The version of WebKit to use" DEFAULT "4a2db3254a9535949a5d5380eb58cf0f77c8e15a")
|
||||
|
||||
if(WEBKIT_LOCAL)
|
||||
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
|
||||
else()
|
||||
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/webkit)
|
||||
endif()
|
||||
|
||||
optionx(WEBKIT_PATH FILEPATH "The path to the WebKit directory" DEFAULT ${DEFAULT_WEBKIT_PATH})
|
||||
|
||||
set(WEBKIT_INCLUDE_PATH ${WEBKIT_PATH}/include)
|
||||
set(WEBKIT_LIB_PATH ${WEBKIT_PATH}/lib)
|
||||
|
||||
register_vendor_target(webkit)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${webkit}
|
||||
PATH ${WEBKIT_PATH}/lib
|
||||
JavaScriptCore
|
||||
WTF
|
||||
bmalloc ${LINUX}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
register_libraries(
|
||||
TARGET ${webkit}
|
||||
PATH ${WEBKIT_PATH}/lib
|
||||
sicudt ${RELEASE}
|
||||
sicudtd ${DEBUG}
|
||||
sicuin ${RELEASE}
|
||||
sicuind ${DEBUG}
|
||||
sicuuc ${RELEASE}
|
||||
sicuucd ${DEBUG}
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WEBKIT_LOCAL)
|
||||
# Must be built seperately, in the future this can be integrated into the build process
|
||||
register_target(build-webkit)
|
||||
else()
|
||||
if(WIN32)
|
||||
set(WEBKIT_OS "windows")
|
||||
elseif(APPLE)
|
||||
set(WEBKIT_OS "macos")
|
||||
elseif(LINUX)
|
||||
set(WEBKIT_OS "linux")
|
||||
else()
|
||||
unsupported(CMAKE_SYSTEM_NAME)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
|
||||
set(WEBKIT_ARCH "arm64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
|
||||
set(WEBKIT_ARCH "amd64")
|
||||
else()
|
||||
unsupported(CMAKE_SYSTEM_PROCESSOR)
|
||||
endif()
|
||||
|
||||
if(DEBUG)
|
||||
set(WEBKIT_SUFFIX "-debug")
|
||||
elseif(ENABLE_LTO AND NOT WIN32)
|
||||
set(WEBKIT_SUFFIX "-lto")
|
||||
else()
|
||||
set(WEBKIT_SUFFIX "")
|
||||
endif()
|
||||
|
||||
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
|
||||
set(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_NAME}.tar.gz)
|
||||
|
||||
get_libraries(${webkit} WEBKIT_LIBRARIES)
|
||||
register_command(
|
||||
TARGET
|
||||
clone-${webkit}
|
||||
COMMENT
|
||||
"Downloading ${WEBKIT_NAME}"
|
||||
COMMAND
|
||||
${CMAKE_COMMAND}
|
||||
-DDOWNLOAD_PATH=${WEBKIT_PATH}
|
||||
-DDOWNLOAD_URL=${WEBKIT_DOWNLOAD_URL}
|
||||
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
|
||||
OUTPUTS
|
||||
${WEBKIT_PATH}/package.json
|
||||
${WEBKIT_LIBRARIES}
|
||||
)
|
||||
|
||||
register_outputs(TARGET clone-${webkit} ${WEBKIT_PATH})
|
||||
endif()
|
||||
@@ -1,40 +1,38 @@
|
||||
register_vendor_target(zlib)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
zlib
|
||||
${zlib}
|
||||
REPOSITORY
|
||||
cloudflare/zlib
|
||||
COMMIT
|
||||
886098f3f339617b4243b286f5ed364b9989e245
|
||||
)
|
||||
|
||||
register_libraries(
|
||||
TARGET ${zlib}
|
||||
z ${UNIX}
|
||||
zlib ${WIN32} AND ${RELEASE}
|
||||
zlibd ${WIN32} AND ${DEBUG}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${zlib}
|
||||
CMAKE_TARGET
|
||||
zlib
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${zlib}
|
||||
BUILD_SHARED_LIBS=OFF
|
||||
BUILD_EXAMPLES=OFF
|
||||
)
|
||||
|
||||
# https://gitlab.kitware.com/cmake/cmake/-/issues/25755
|
||||
if(APPLE)
|
||||
set(ZLIB_CMAKE_C_FLAGS "-fno-define-target-os-macros")
|
||||
set(ZLIB_CMAKE_CXX_FLAGS "-fno-define-target-os-macros")
|
||||
register_compiler_flags(
|
||||
TARGET ${zlib}
|
||||
-fno-define-target-os-macros
|
||||
)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
if(DEBUG)
|
||||
set(ZLIB_LIBRARY "zlibd")
|
||||
else()
|
||||
set(ZLIB_LIBRARY "zlib")
|
||||
endif()
|
||||
else()
|
||||
set(ZLIB_LIBRARY "z")
|
||||
endif()
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
zlib
|
||||
TARGETS
|
||||
zlib
|
||||
ARGS
|
||||
-DBUILD_SHARED_LIBS=OFF
|
||||
-DBUILD_EXAMPLES=OFF
|
||||
"-DCMAKE_C_FLAGS=${ZLIB_CMAKE_C_FLAGS}"
|
||||
"-DCMAKE_CXX_FLAGS=${ZLIB_CMAKE_CXX_FLAGS}"
|
||||
LIBRARIES
|
||||
${ZLIB_LIBRARY}
|
||||
INCLUDES
|
||||
.
|
||||
)
|
||||
|
||||
@@ -1,26 +1,34 @@
|
||||
register_vendor_target(zstd)
|
||||
|
||||
register_repository(
|
||||
NAME
|
||||
zstd
|
||||
${zstd}
|
||||
REPOSITORY
|
||||
facebook/zstd
|
||||
COMMIT
|
||||
794ea1b0afca0f020f4e57b6732332231fb23c70
|
||||
)
|
||||
|
||||
register_cmake_command(
|
||||
TARGET
|
||||
zstd
|
||||
TARGETS
|
||||
libzstd_static
|
||||
ARGS
|
||||
-Sbuild/cmake
|
||||
-DZSTD_BUILD_STATIC=ON
|
||||
-DZSTD_BUILD_PROGRAMS=OFF
|
||||
-DZSTD_BUILD_TESTS=OFF
|
||||
-DZSTD_BUILD_CONTRIB=OFF
|
||||
LIB_PATH
|
||||
lib
|
||||
LIBRARIES
|
||||
zstd_static WIN32
|
||||
zstd UNIX
|
||||
register_libraries(
|
||||
TARGET ${zstd}
|
||||
PATH lib
|
||||
zstd_static ${WIN32}
|
||||
zstd ${UNIX}
|
||||
)
|
||||
|
||||
register_cmake_project(
|
||||
TARGET
|
||||
${zstd}
|
||||
CMAKE_TARGET
|
||||
libzstd_static
|
||||
CMAKE_PATH
|
||||
build/cmake
|
||||
)
|
||||
|
||||
register_cmake_definitions(
|
||||
TARGET ${zstd}
|
||||
ZSTD_BUILD_STATIC=ON
|
||||
ZSTD_BUILD_PROGRAMS=OFF
|
||||
ZSTD_BUILD_TESTS=OFF
|
||||
ZSTD_BUILD_CONTRIB=OFF
|
||||
)
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
optionx(BUILDKITE_CACHE BOOL "If the build can use Buildkite caches, even if not running in Buildkite" DEFAULT ${BUILDKITE})
|
||||
|
||||
if(NOT BUILDKITE_CACHE OR NOT BUN_LINK_ONLY)
|
||||
if(NOT BUN_LINK_ONLY)
|
||||
return()
|
||||
endif()
|
||||
|
||||
@@ -33,7 +31,7 @@ if(NOT BUILDKITE_BUILD_ID)
|
||||
endif()
|
||||
|
||||
setx(BUILDKITE_BUILD_URL https://buildkite.com/${BUILDKITE_ORGANIZATION_SLUG}/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_ID})
|
||||
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/builds/${BUILDKITE_BUILD_ID})
|
||||
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/${BUILDKITE_BUILD_ID})
|
||||
|
||||
file(
|
||||
DOWNLOAD ${BUILDKITE_BUILD_URL}
|
||||
@@ -125,15 +123,14 @@ foreach(i RANGE ${BUILDKITE_JOBS_MAX_INDEX})
|
||||
set(BUILDKITE_DOWNLOAD_COMMAND curl -L -o ${BUILDKITE_ARTIFACT_PATH} ${BUILDKITE_ARTIFACTS_URL}/${BUILDKITE_ARTIFACT_ID})
|
||||
endif()
|
||||
|
||||
add_custom_command(
|
||||
COMMENT
|
||||
"Downloading ${BUILDKITE_ARTIFACT_PATH}"
|
||||
VERBATIM COMMAND
|
||||
${BUILDKITE_DOWNLOAD_COMMAND}
|
||||
WORKING_DIRECTORY
|
||||
${BUILD_PATH}
|
||||
OUTPUT
|
||||
${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}
|
||||
message(STATUS "Downloading ${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}")
|
||||
get_filename_component(BUILDKITE_ARTIFACT_NAME ${BUILDKITE_ARTIFACT_PATH} NAME_WE)
|
||||
register_command(
|
||||
TARGET download-${BUILDKITE_ARTIFACT_NAME}
|
||||
COMMENT "Downloading ${BUILDKITE_ARTIFACT_PATH}"
|
||||
COMMAND ${BUILDKITE_DOWNLOAD_COMMAND}
|
||||
CWD ${BUILD_PATH}
|
||||
OUTPUTS ${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}
|
||||
)
|
||||
endforeach()
|
||||
|
||||
|
||||
@@ -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})
|
||||
|
||||
@@ -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)
|
||||
@@ -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()
|
||||
|
||||
@@ -52,8 +52,3 @@ if(CMAKE_OSX_SYSROOT_ERROR)
|
||||
endif()
|
||||
|
||||
optionx(CMAKE_OSX_SYSROOT STRING "The macOS SDK path to target" DEFAULT ${DEFAULT_CMAKE_OSX_SYSROOT})
|
||||
|
||||
list(APPEND CMAKE_ARGS
|
||||
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
|
||||
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
|
||||
)
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
option(WEBKIT_VERSION "The version of WebKit to use")
|
||||
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
|
||||
|
||||
if(NOT WEBKIT_VERSION)
|
||||
set(WEBKIT_VERSION 76798f7b2fb287ee9f1ecce98bae895a2d026d93)
|
||||
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()
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
@@ -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");
|
||||
```
|
||||
@@ -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; -->
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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`
|
||||
|
||||
@@ -1131,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).
|
||||
|
||||
---
|
||||
|
||||
@@ -1196,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.
|
||||
@@ -1279,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 {
|
||||
@@ -1388,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 =
|
||||
|
||||
@@ -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"`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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`).
|
||||
@@ -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
|
||||
```
|
||||
@@ -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.
|
||||
|
||||
@@ -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"),
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
41
package.json
41
package.json
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "bun",
|
||||
"version": "1.1.30",
|
||||
"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,35 +40,25 @@
|
||||
"build:release:local": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -DWEBKIT_LOCAL=ON -B build/release",
|
||||
"build:release:with_logs": "cmake . -DCMAKE_BUILD_TYPE=Release -DENABLE_LOGS=true -GNinja -Bbuild-release && ninja -Cbuild-release",
|
||||
"build:debug-zig-release": "cmake . -DCMAKE_BUILD_TYPE=Release -DZIG_OPTIMIZE=Debug -GNinja -Bbuild-debug-zig-release && ninja -Cbuild-debug-zig-release",
|
||||
"bump": "bun ./scripts/bump.ts",
|
||||
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
|
||||
"fmt": "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"
|
||||
}
|
||||
}
|
||||
|
||||
4
packages/bun-darwin-aarch64/.npmignore
Normal file
4
packages/bun-darwin-aarch64/.npmignore
Normal file
@@ -0,0 +1,4 @@
|
||||
bin/bun-profile
|
||||
bin/*.o
|
||||
*.o
|
||||
*.a
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
4
packages/bun-linux-x64/.npmignore
Normal file
4
packages/bun-linux-x64/.npmignore
Normal file
@@ -0,0 +1,4 @@
|
||||
bin/bun-profile
|
||||
bin/*.o
|
||||
*.o
|
||||
*.a
|
||||
3
packages/bun-plugin-css/README.md
Normal file
3
packages/bun-plugin-css/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# `bun-plugin-css`
|
||||
|
||||
Not implemented.
|
||||
1
packages/bun-plugin-css/index.ts
Normal file
1
packages/bun-plugin-css/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
throw new Error("Not implemented.");
|
||||
10
packages/bun-plugin-css/package.json
Normal file
10
packages/bun-plugin-css/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "bun-plugin-css",
|
||||
"version": "0.0.1-alpha.0",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
3
packages/bun-plugin-lightningcss/README.md
Normal file
3
packages/bun-plugin-lightningcss/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# `bun-plugin-lightningcss`
|
||||
|
||||
Not implemented.
|
||||
1
packages/bun-plugin-lightningcss/index.ts
Normal file
1
packages/bun-plugin-lightningcss/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
throw new Error("Not implemented.");
|
||||
10
packages/bun-plugin-lightningcss/package.json
Normal file
10
packages/bun-plugin-lightningcss/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "bun-plugin-lightningcss",
|
||||
"version": "0.0.1-alpha.0",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
3
packages/bun-plugin-mdx/README.md
Normal file
3
packages/bun-plugin-mdx/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# `bun-plugin-mdx`
|
||||
|
||||
Not implemented.
|
||||
1
packages/bun-plugin-mdx/index.ts
Normal file
1
packages/bun-plugin-mdx/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
throw new Error("Not implemented.");
|
||||
10
packages/bun-plugin-mdx/package.json
Normal file
10
packages/bun-plugin-mdx/package.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "bun-plugin-mdx",
|
||||
"version": "0.0.1-alpha.0",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"files": [
|
||||
"index.ts",
|
||||
"package.json"
|
||||
]
|
||||
}
|
||||
169
packages/bun-plugin-server-components/.gitignore
vendored
Normal file
169
packages/bun-plugin-server-components/.gitignore
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
\*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
\*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
\*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
\*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
.cache/
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.\*
|
||||
149
packages/bun-plugin-server-components/README.md
Normal file
149
packages/bun-plugin-server-components/README.md
Normal file
@@ -0,0 +1,149 @@
|
||||
# `bun-plugin-server-components`
|
||||
|
||||
The official Bun plugin for **server components**.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
bun add bun-plugin-server-components -d
|
||||
```
|
||||
|
||||
## Context
|
||||
|
||||
Server components are a new abstraction for building web applications. They look similar to standard React/JSX components, but render exclusively on the server. They differ from classic "client components" in a few ways:
|
||||
|
||||
1. They can be `async`.
|
||||
2. Their implementation can run privileged code like database queries. Normally this would be unsafe, because the source code of client components are typically bundled and sent to the client, where they can be inspected and reverse-engineered. Server components are never sent to the client, so they can run privileged code safely.
|
||||
3. They _cannot_ contain stateful hooks like `useState` or `useEffect`.
|
||||
|
||||
Server components require a deep integration with the bundler to work. To understand why, we need a bit of background on how server components work.
|
||||
|
||||
### How server components work
|
||||
|
||||
Imagine you have a server component that looks like this:
|
||||
|
||||
```tsx
|
||||
// index.tsx
|
||||
import { Component } from "./Component";
|
||||
export default async function HomePage() {
|
||||
return (
|
||||
<div>
|
||||
<Component />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
This file imports a client component called `Component`.
|
||||
|
||||
```ts
|
||||
// ./Component.tsx
|
||||
"use client";
|
||||
|
||||
export function Component() {
|
||||
return <div>Hello world</div>;
|
||||
}
|
||||
```
|
||||
|
||||
To run this component we need to generate two builds.
|
||||
|
||||
> Here the term "build" refers to a typical bundling step—the act of converting a set of entrypoints into a set of bundles.
|
||||
|
||||
1. The first is our "server component build". It contains all the code we need to render `HomePage` to a component tree. When an incoming `Request` comes in, we can use React's built-in tools to convert this tree into a "virtual DOM stream" that we can return as a `Response`.
|
||||
2. The second is our "client build". It contains the bundled versions of all client components that were referenced by our server components.
|
||||
|
||||
The browser hits the server and gets back the "virtual DOM stream". The virtual DOM stream will contain references to client components, which will be loaded from the client bundle. React provides a built-in utility (`createFromFetch`)that accepts the VDOM stream, dynamically loads the necessary client components, and returns a renderable component.
|
||||
|
||||
```ts
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { createFromFetch } from "react-server-dom-webpack/client.browser";
|
||||
|
||||
const stream = fetch("/", { headers: { Accept: "text/x-component" } });
|
||||
const data = createFromFetch(stream);
|
||||
|
||||
const root = createRoot(document);
|
||||
root.render(<App />);
|
||||
```
|
||||
|
||||
### Server-side rendering
|
||||
|
||||
One potentially confusing aspect of server components is that they "return" virtual DOM. From the perspective of a server component, client components are black boxes.
|
||||
|
||||
If we want to do server-side rendering, we need to render our server component to VDOM, _then_ render the VDOM to plain HTML. These are two distinct steps. The second step requires a _third build_, we we'll call the "SSR build". Like the "client build", this build will bundle all the client components. Unlike the "client build", those bundles will be intended for consumption on the server; in bundler terms, the build's `"target"` will be`"bun"` (or perhaps `"node"`).
|
||||
|
||||
### Bundling server components
|
||||
|
||||
That's a high-level overview of how server components work. The important takeaway is that we need to generate totally separate bundles for server and client components.
|
||||
|
||||
But it's not just a simple matter of running two separate bundling scripts. The true "entrypoints" of our application are the server components. Over the course of bundling our server components, we will discover some files containing the `"use client"` directive; these files then become the entrypoints for our "client build", which will require a totally separate build configuration from the server build.
|
||||
|
||||
The goal of this plugin is to hide the complexty of this multi-stage build from the user.
|
||||
|
||||
## Usage
|
||||
|
||||
To use this plugin:
|
||||
|
||||
```ts
|
||||
import ServerComponentsPlugin from "bun-plugin-server-components";
|
||||
|
||||
await Bun.build({
|
||||
entrypoints: ["./index.tsx"], // server component files
|
||||
plugins: [
|
||||
ServerComponentsPlugin({
|
||||
// plugin configuration
|
||||
}),
|
||||
],
|
||||
// other configuration
|
||||
});
|
||||
```
|
||||
|
||||
The `"entrypoints"` you pass into `Bun.build()` should be your _server components_. Bun's bundler will automatically detect any files containing the `"use client"` directive, and will use those files as entrypoints for the "client build" and "SSR build". The bundler configuration for these builds can be provided `client` and `ssr` keys respectively.
|
||||
|
||||
```ts
|
||||
import ServerComponentsPlugin from "bun-plugin-server-components";
|
||||
|
||||
await Bun.build({
|
||||
entrypoints: ["./index.tsx"], // server component files
|
||||
outdir: "./build",
|
||||
manifest: true,
|
||||
plugins: [ServerComponentsPlugin({
|
||||
client: {
|
||||
entrypoints: [], // optional - additional client entrypoints
|
||||
outdir: "./build/client", // default: inherits from the main build
|
||||
target: "browser",
|
||||
plugins: [/* */],
|
||||
}
|
||||
ssr: {
|
||||
entrypoints: [], // optional - additional SSR entrypoints
|
||||
outdir: "./build/client", // default: inherits from the main build
|
||||
target: "bun", // this is default
|
||||
plugins: [/* */],
|
||||
}
|
||||
})],
|
||||
});
|
||||
```
|
||||
|
||||
The result of `Bun.build()` will contain additional manifests for the SSR and client builds.
|
||||
|
||||
```ts
|
||||
const result = await Bun.build({
|
||||
// config
|
||||
plugins: [
|
||||
ServerComponentsPlugin({
|
||||
/* config */
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
// standard manifest
|
||||
// for the top-level (server components) build
|
||||
result.manifest;
|
||||
|
||||
// manifest for client build
|
||||
result.clientManifest;
|
||||
|
||||
// manifest for client build
|
||||
result.ssrManifest;
|
||||
```
|
||||
|
||||
Once the build is complete, use the manifests to implement your RSC server.
|
||||
BIN
packages/bun-plugin-server-components/bun.lockb
Executable file
BIN
packages/bun-plugin-server-components/bun.lockb
Executable file
Binary file not shown.
10
packages/bun-plugin-server-components/index.ts
Normal file
10
packages/bun-plugin-server-components/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { BunPlugin, BuildConfig } from "bun";
|
||||
|
||||
function Plugin(config: { client?: BuildConfig; ssr?: BuildConfig }): BunPlugin {
|
||||
return {
|
||||
name: "bun-plugin-server-components",
|
||||
SECRET_SERVER_COMPONENTS_INTERNALS: config,
|
||||
} as any;
|
||||
}
|
||||
|
||||
export default Plugin;
|
||||
28
packages/bun-plugin-server-components/package.json
Normal file
28
packages/bun-plugin-server-components/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "bun-plugin-server-components",
|
||||
"version": "0.0.1-alpha.0",
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"types": "index.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./index.ts",
|
||||
"require": "./index.ts",
|
||||
"default": "./index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"files": [
|
||||
"index.ts",
|
||||
"tsconfig.json",
|
||||
"package.json",
|
||||
"modules.d.ts"
|
||||
],
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^4.0.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"bun-types": "canary",
|
||||
"js-yaml": "^4.1.0"
|
||||
}
|
||||
}
|
||||
23
packages/bun-plugin-server-components/tsconfig.json
Normal file
23
packages/bun-plugin-server-components/tsconfig.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleDetection": "force",
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"composite": true,
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react-jsx",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
},
|
||||
"include": ["**/*.ts", "modules.d.ts"]
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user