Compare commits

...

161 Commits

Author SHA1 Message Date
Ashcon Partovi
88063eaad5 Fix? 2024-09-24 17:39:37 -07:00
Ashcon Partovi
da2d1e12ed Testing 2024-09-24 17:20:21 -07:00
Ashcon Partovi
6b54dbfa07 Test old 2024-09-24 16:45:04 -07:00
Ashcon Partovi
1dfa557ca4 Test changes 2024-09-24 16:18:23 -07:00
Ashcon Partovi
29d1b4db74 Fix linking 2024-09-24 16:13:37 -07:00
Ashcon Partovi
85edb39a2f Fix linking 2024-09-24 15:58:50 -07:00
Ashcon Partovi
f0384f39b7 Fix command 2024-09-24 15:50:16 -07:00
Ashcon Partovi
2e1b19b9fd Fix option 2024-09-24 15:47:57 -07:00
Ashcon Partovi
53ce1ff6c1 Fix 2024-09-24 15:23:03 -07:00
Ashcon Partovi
eee9b51df3 Fix 2024-09-24 15:14:25 -07:00
Ashcon Partovi
f0036cc6c1 Fix target names 2024-09-24 15:05:48 -07:00
Ashcon Partovi
77a25c0188 Fix target names 2024-09-24 15:03:24 -07:00
Ashcon Partovi
a3777b8c22 Fix alias 2024-09-24 15:01:34 -07:00
Ashcon Partovi
0d9d7a3436 Fix 2024-09-24 14:58:54 -07:00
Ashcon Partovi
d5e7846eaf Fix 2024-09-24 14:49:18 -07:00
Ashcon Partovi
582a53e26e Random ID 2024-09-23 16:24:57 -07:00
Ashcon Partovi
57d9cfc24d Fixes 2024-09-23 16:19:34 -07:00
Ashcon Partovi
31dc58fa79 Typo 2024-09-23 13:34:33 -07:00
Ashcon Partovi
03bb9fd9b5 Fix 2024-09-23 13:31:12 -07:00
Ashcon Partovi
f270f235c8 Fix 2024-09-23 13:30:05 -07:00
Ashcon Partovi
8d1b5856d3 Fixes 2024-09-23 13:22:34 -07:00
Ashcon Partovi
bf488d0b19 Fixes 2024-09-23 13:21:13 -07:00
Ashcon Partovi
9dc0672840 Fixes 2024-09-23 12:59:10 -07:00
Ashcon Partovi
b1d0cb0ea3 Maybe fix 2024-09-23 12:44:54 -07:00
Ashcon Partovi
155ba7ebdf Debug logs 2024-09-23 12:41:46 -07:00
Ashcon Partovi
3757a3e30f Maybe fix 2024-09-23 12:00:57 -07:00
Ashcon Partovi
4b443db0d8 Maybe fix 2024-09-23 11:59:20 -07:00
Ashcon Partovi
d74ae08946 Test 2024-09-23 11:54:56 -07:00
Ashcon Partovi
a7a5ed2fba Update ci 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7d7c9877a4 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
1cd43f5bae WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
56b6ed6d97 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
85dd8ef0d4 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
6cb0de3921 WIP 2024-09-20 18:58:02 -07:00
Ashcon Partovi
2c1dcb5a1d Extra if check 2024-09-20 18:58:02 -07:00
Ashcon Partovi
d3f3900da7 Maybe fix webkit 2024-09-20 18:58:02 -07:00
Ashcon Partovi
ef18731db1 Fix format 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7fb15e5a03 Ensure fresh 2024-09-20 18:58:02 -07:00
Ashcon Partovi
2b017cd0ad Fix 2024-09-20 18:58:02 -07:00
Ashcon Partovi
9f857fa418 Run clang-format 2024-09-20 18:58:02 -07:00
Ashcon Partovi
1cde69d0f1 Better webkit download 2024-09-20 18:58:02 -07:00
Ashcon Partovi
800e378b6e Run scripts 2024-09-20 18:58:02 -07:00
Ashcon Partovi
dfe8fb50d9 Build 2024-09-20 18:58:02 -07:00
Ashcon Partovi
0f6cfc0b16 Changes 2024-09-20 18:58:02 -07:00
Ashcon Partovi
019cfb7927 Changes 2024-09-20 18:58:02 -07:00
Ashcon Partovi
7887689fd0 Fixes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
888d8301ca Fix dependency 2024-09-20 18:58:01 -07:00
Ashcon Partovi
704c169e04 changes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
c16e34078a Script changes 2024-09-20 18:58:01 -07:00
Ashcon Partovi
bc9e022c86 Changes 2024-09-20 18:58:00 -07:00
Ashcon Partovi
a88b8130b9 Fix 2024-09-20 18:57:38 -07:00
Ashcon Partovi
2139e8442a Fix 2024-09-20 18:57:38 -07:00
Ashcon Partovi
f50a80a7c1 Linting in buildkite 2024-09-20 18:57:38 -07:00
Ashcon Partovi
fabb18208b Revert "Upload features.json"
This reverts commit 4f02152690.
2024-09-20 18:57:20 -07:00
Ashcon Partovi
4f02152690 Upload features.json 2024-09-20 16:51:16 -07:00
Jarred Sumner
64f4831059 Clarify WASI not WASM 2024-09-20 16:41:49 -07:00
Jarred Sumner
f9a8bed5c2 Make require.cache inspectable (#14072) 2024-09-20 15:27:10 -07:00
190n
08a77267da Keep event loop alive when refConcurrently has been called (#14068) 2024-09-20 14:57:55 -07:00
Jarred Sumner
73c553b25a Update ffi.d.ts 2024-09-20 00:07:26 -07:00
Jarred Sumner
6d43b36622 Allow TCP connections for BUN_INSPECT_NOTIFY (#14056) 2024-09-19 23:55:06 -07:00
Jarred Sumner
8dfa2abb53 Update nav.ts 2024-09-19 23:26:05 -07:00
Ciro Spaciari
d80d9f450c fix(node:http) improve agent support (#13780)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-19 23:04:36 -07:00
Jarred Sumner
ab07cf444d Bump 2024-09-19 21:52:39 -07:00
Jarred Sumner
f263436911 Experiment: Add buffer type and inline pointer (#14036) 2024-09-19 21:26:50 -07:00
Dylan Conway
e938791f77 fix(Bun.build): handle non-object plugins (#14050) 2024-09-19 19:37:28 -07:00
Dylan Conway
cff7b9843d fix 14037 (#14047) 2024-09-19 15:25:38 -07:00
Kevin Gibbons
260a0d16eb docs: Add new methods to binary-data.md (#14044) 2024-09-19 13:36:08 -07:00
Dylan Conway
47e4b826fa fix snapshot regression (#14031) 2024-09-19 13:27:42 -07:00
Jarred Sumner
6415296e96 Support napi inside of bun:ffi (#14028) 2024-09-19 03:19:08 -07:00
dave caruso
866a6d9180 fix(bundler): disable moving identifiers (#14033) 2024-09-19 03:18:16 -07:00
Jarred Sumner
181b8722e2 Enable cc test (#14026) 2024-09-18 21:55:49 -07:00
Jarred Sumner
572bcf0097 Fixes #14014 (#14023) 2024-09-18 19:06:33 -07:00
Dylan Conway
cf4e9cb69e disable most DOMJIT (#14005) 2024-09-17 21:43:38 -07:00
Jarred Sumner
6d98bccd8b TinyCC: -framework support, __attribute__(deprecated(string)) in enum, fix dlsym issue (#13993)
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
2024-09-17 15:50:02 -07:00
Dylan Conway
c74ec5ab18 compare major 2024-09-17 10:54:46 -07:00
Dylan Conway
3d68a9483f fix cloning dependencies 2024-09-16 12:18:53 -07:00
Jarred Sumner
b66d622c56 Bump WebKit (#13970) 2024-09-15 04:37:23 -04:00
190n
163e76ef96 Fix memory corruption in napi_open_escapable_handle_scope (#13955)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-15 01:39:18 -04:00
Jarred Sumner
14c63229a1 Revert "various node:buffer fixes" (#13971) 2024-09-14 23:41:33 -04:00
Jarred Sumner
f4391e7023 Support compiling and running C from JavaScript (#13403) 2024-09-14 04:57:44 -04:00
snwy
b9a5e4410f forward IPC to child process if running package script (#13934)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-14 04:40:00 -04:00
Meghan Denny
3c2e798eab various node:buffer fixes (#13757)
Co-authored-by: nektro <nektro@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-14 04:09:20 -04:00
Mattias Leino
a60d5211ca Add documentation for using bun with Testing Library (#13960) 2024-09-14 02:24:10 -04:00
Meghan Denny
ac53310fe9 misc node:zlib fixes [v2] (#13958) 2024-09-14 02:01:04 -04:00
Jarred Sumner
d9d4cff303 Micro-optimize path.resolve(), path.resolve("") (#13930) 2024-09-14 01:42:49 -04:00
Dylan Conway
5af782344f fix(watch): use case insensitive path comparison (#13909)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-14 01:41:33 -04:00
Dylan Conway
7ef0f04acd fix #13942 (#13943) 2024-09-14 01:22:28 -04:00
Meghan Denny
8b1c53dd36 Fix debug builds on macOS arm64 (#13952)
Co-authored-by: Ashcon Partovi <ashcon@partovi.net>
2024-09-13 16:01:17 -07:00
Ashcon Partovi
44841d8924 Fix clang-cl flag: /O0 -> /Od 2024-09-13 16:00:16 -07:00
Dylan Conway
3c0327df3a debug libraries 2024-09-13 15:58:22 -07:00
Dylan Conway
e5e8861fde debug icu 2024-09-13 15:57:58 -07:00
Dylan Conway
620b7b101e update webkit (#13931) 2024-09-13 02:43:22 -07:00
Jarred Sumner
34e4447aea Update some paths 2024-09-13 00:40:49 -07:00
190n
3aef88842e Make setInterval leak test not flaky (#13929) 2024-09-12 18:57:06 -07:00
Ashcon Partovi
76191bed44 Various fixes for CMake (#13928) 2024-09-12 18:08:59 -07:00
190n
b146449ed5 Increase timeouts for shell-hang.test.ts (#13932) 2024-09-12 17:23:33 -07:00
dave caruso
c2c2048072 framework api: init / work in progress (#13215)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-12 16:44:03 -07:00
Jarred Sumner
ff6f8bd2d1 Update path-resolve.mjs 2024-09-12 15:00:52 -07:00
Ciro Spaciari
b1ca81a10d fix(node:net, node:tls) add named pipe support on node:net and node:tls modules (#13838) 2024-09-12 14:06:45 -07:00
Jarred Sumner
d9b851e426 Don't panic when a package.json manifest registry api name doesn't match the local name (#13907) 2024-09-12 14:05:45 -07:00
Jarred Sumner
872c7f0d91 Why is path slow (#13908) 2024-09-12 14:05:16 -07:00
Jarred Sumner
0a6594395c Add a couple uv symbols (#13808)
Co-authored-by: Ben Grant <ben@bun.sh>
2024-09-12 00:13:49 -07:00
snwy
043dfa4cc9 fix .env loader printing to stderr when running bun bun.lockb (#13905)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-12 00:10:03 -07:00
Jarred Sumner
173f465fbe ✂️ dead code 2024-09-11 22:04:32 -07:00
Jarred Sumner
51adc273a6 Add message on crash with old CPU (#13886) 2024-09-11 20:14:17 -07:00
190n
522493afa8 Attempt to fix spawn-streaming-stdin.test.ts on Windows (#13860) 2024-09-11 20:14:10 -07:00
Jarred Sumner
c48997050d Avoid creating a Napi handle scope within a finalizer (#13870)
Co-authored-by: Ben Grant <ben@bun.sh>
2024-09-11 20:05:44 -07:00
Jarred Sumner
2064876a7d Fix crash in socket.upgradeTLS (#13884) 2024-09-11 20:05:06 -07:00
snwy
c3197948c4 fixes --conditions for bun test (#13902) 2024-09-11 18:04:21 -07:00
Ashcon Partovi
f5b7a6708d Move dependencies from src/deps/ to vendor/ (#13901) 2024-09-11 17:46:03 -07:00
190n
b33d6b1416 Fix ReadFileUV not reading to the end of a non-regular file on Windows (#13900) 2024-09-11 17:33:01 -07:00
190n
f6841a06c5 Make NAPI garbage collection tests faster (#13898) 2024-09-11 16:59:03 -07:00
Dylan Conway
749632f125 fix(spawn): update cwd before searching for executable to run (#13845)
Co-authored-by: dylan-conway <dylan-conway@users.noreply.github.com>
2024-09-11 16:58:24 -07:00
Jarred Sumner
de9557b19e Fix edgecase with "os" and "cpu" in bun install (#13848)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-11 16:47:38 -07:00
Jarred Sumner
ed8e6115bb Fix using decimal numbers for file descriptors (#13881) 2024-09-11 15:52:53 -07:00
Jarred Sumner
0378e5a277 Update launch.json 2024-09-11 15:41:41 -07:00
Jarred Sumner
3689978b98 Update clangd 2024-09-11 15:14:59 -07:00
Ashcon Partovi
3939e16664 Fix build.mjs (#13893) 2024-09-11 09:45:42 -07:00
Ashcon Partovi
03285f2490 Reapply "Update build.mjs"
This reverts commit 03d7d9aadd.
2024-09-11 08:25:24 -07:00
Ashcon Partovi
19ef3eecd0 Reapply "Make configure faster with local WebKit build"
This reverts commit a832954c94.
2024-09-11 08:25:05 -07:00
Ashcon Partovi
d39e422b20 Reapply "Convert build scripts to CMake (#13427)"
This reverts commit 374bb15db6.
2024-09-11 08:24:50 -07:00
Dylan Conway
3e904303ac fix hot/hot.test.ts, hot/watch.test.ts, and watch/watch.test.ts (#13876)
Co-authored-by: dylan-conway <dylan-conway@users.noreply.github.com>
2024-09-11 01:24:46 -07:00
Jarred Sumner
97baeb80f0 Move EventLoopTask into a separate file because it causes clangd to crash (#13875) 2024-09-11 00:24:48 -07:00
Dylan Conway
4a58a97fa0 fix sleep tests in bun-install-registry.test.ts (#13874) 2024-09-10 22:28:57 -07:00
Dylan Conway
7e705b9d40 fix expo.test.ts (#13872) 2024-09-10 20:52:29 -07:00
Jarred Sumner
1f1e4a08d8 Update nodejs-apis.md 2024-09-10 20:40:34 -07:00
Jarred Sumner
58c74e1a75 Update nodejs-apis.md 2024-09-10 20:35:35 -07:00
Jarred Sumner
d483535693 Update nodejs-apis.md 2024-09-10 20:32:00 -07:00
Dylan Conway
374bb15db6 Revert "Convert build scripts to CMake (#13427)"
This reverts commit 354df17d16.
2024-09-10 19:57:19 -07:00
Dylan Conway
a832954c94 Revert "Make configure faster with local WebKit build"
This reverts commit 1694ca0e89.
2024-09-10 19:56:37 -07:00
Dylan Conway
03d7d9aadd Revert "Update build.mjs"
This reverts commit 24bb8d95b0.
2024-09-10 19:56:36 -07:00
Dylan Conway
ff9b003a9b Revert "Fix permissions on Zig download"
This reverts commit fb5ebe5ceb.
2024-09-10 19:56:34 -07:00
Jarred Sumner
ac17735cac Retry after chmod when cp fails 2024-09-10 19:30:13 -07:00
Ashcon Partovi
fb5ebe5ceb Fix permissions on Zig download 2024-09-10 19:01:09 -07:00
Jarred Sumner
24bb8d95b0 Update build.mjs 2024-09-10 18:54:52 -07:00
Ashcon Partovi
1694ca0e89 Make configure faster with local WebKit build 2024-09-10 17:40:12 -07:00
Ashcon Partovi
354df17d16 Convert build scripts to CMake (#13427) 2024-09-10 17:01:40 -07:00
Jarred Sumner
8d7d58606b Add generator for $ERR_* as fake private globals (#13843)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-10 16:07:22 -07:00
Jarred Sumner
d7f9346f67 Fix broken link 2024-09-10 15:22:08 -07:00
Jarred Sumner
80cb9e77bc Use absolute links in docs 2024-09-10 15:11:16 -07:00
Lev
036e030342 Add the missing 'linked' option to --sourcemap in bun build --help (#13855) 2024-09-10 04:08:52 -07:00
190n
2071507a1b Fix flaky process.cpuUsage tests (#13842) 2024-09-10 02:38:40 -07:00
Jarred Sumner
c7b874447f Add missing timers.promises (#13834)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-09 17:17:52 -07:00
190n
282b92d6e1 Fix issues with NAPI tests (#13831)
Co-authored-by: 190n <190n@users.noreply.github.com>
2024-09-09 17:08:40 -07:00
Ciro Spaciari
2b50554596 fix(node:http) always set headersSent to true after end (#13794)
Co-authored-by: cirospaciari <cirospaciari@users.noreply.github.com>
2024-09-09 17:08:17 -07:00
Jarred Sumner
8f5d78f498 Fix default value for zlib options (#13800) 2024-09-09 17:06:41 -07:00
Jarred Sumner
ee2d666e8e Add missing perf_hooks constants (#13833)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-09 16:54:09 -07:00
Jarred Sumner
3e8a50ba57 workerData should default to null instead of undefined (#13835)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-09 16:48:12 -07:00
Jarred Sumner
945175961c Set process._exiting to false by default (#13832)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-09 16:45:24 -07:00
dave caruso
d38f937d3d fix(transpiler): remove react element inlining (#13694)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-09 15:03:13 -07:00
Jarred Sumner
07e4b5f3d3 Update run-lint-cpp.yml 2024-09-09 14:32:55 -07:00
Wilmer Paulino
a0939ca4f1 Switch asymmetric encryption implementation to BoringSSL (#13786) 2024-09-08 03:19:23 -07:00
Danny Kirkham
09cbb51c81 Fix typo in http.md (#13793) 2024-09-08 00:56:31 -07:00
Dylan Conway
50d2f76075 fix(pack): don't automatically include CHANGELOG when files is populated (#13789) 2024-09-08 00:56:21 -07:00
github-actions[bot]
09fb2d1db0 Bump to 1.1.27 (#13805)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-08 00:48:15 -07:00
Dylan Conway
267afa2934 implement bun pm pack (#13723)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: dylan-conway <dylan-conway@users.noreply.github.com>
2024-09-07 03:55:09 -07:00
Jarred Sumner
08103aa7ae Fix 2 memory leaks in zlib from #11770 (#13787) 2024-09-07 02:12:09 -07:00
190n
084734db64 Implement napi_handle_scope and napi_escapable_handle_scope (#13756) 2024-09-07 00:55:19 -07:00
Meghan Denny
de5809b45a windows: fix sometimes crash when FDImpl.uv() is called on stdio (#13719)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Dave Caruso <me@paperdave.net>
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-09-06 21:00:55 -07:00
Jarred Sumner
f0a4b9f96f Copy fix from #13756 into separate PR (#13783)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-09-06 20:16:20 -07:00
Meghan Denny
8cd515f533 node:zlib: move deflate and gzip into native code (#11770)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-06 18:49:19 -07:00
691 changed files with 30531 additions and 57708 deletions

View File

@@ -1,63 +0,0 @@
## CI
How does CI work?
### Building
Bun is built on macOS, Linux, and Windows. The process is split into the following steps, the first 3 of which are able to run in parallel:
#### 1. `build-deps`
Builds the static libaries in `src/deps` and outputs a directory: `build/bun-deps`.
- on Windows, this runs the script: [`scripts/all-dependencies.ps1`](scripts/all-dependencies.ps1)
- on macOS and Linux, this runs the script: [`scripts/all-dependencies.sh`](scripts/all-dependencies.sh)
#### 2. `build-zig`
Builds the Zig object file: `build/bun-zig.o`. Since `zig build` supports cross-compiling, this step is run on macOS aarch64 since we have observed it to be the fastest.
- on macOS and Linux, this runs the script: [`scripts/build-bun-zig.sh`](scripts/build-bun-zig.sh)
#### 3. `build-cpp`
Builds the C++ object file: `build/bun-cpp-objects.a`.
- on Windows, this runs the script: [`scripts/build-bun-cpp.ps1`](scripts/build-bun-cpp.ps1)
- on macOS and Linux, this runs the script: [`scripts/build-bun-cpp.sh`](scripts/build-bun-cpp.sh)
#### 4. `link` / `build-bun`
After the `build-deps`, `build-zig`, and `build-cpp` steps have completed, this step links the Zig object file and C++ object file into a single binary: `bun-<os>-<arch>.zip`.
- on Windows, this runs the script: [`scripts/buildkite-link-bun.ps1`](scripts/buildkite-link-bun.ps1)
- on macOS and Linux, this runs the script: [`scripts/buildkite-link-bun.sh`](scripts/buildkite-link-bun.sh)
To speed up the build, thare are two options:
- `--fast`: This disables the LTO (link-time optimization) step.
- without `--fast`: This runs the LTO step, which is the default. The binaries that are release to Github are always built with LTO.
### Testing
### FAQ
> How do I add a new CI agent?
> How do I add/modify system dependencies?
> How do I SSH into a CI agent?
### Known issues
These are things that we know about, but haven't fixed or optimized yet.
- There is no `scripts/build-bun-zig.ps1` for Windows.
- The `build-deps` step does not cache in CI, so it re-builds each time (though it does use ccache). It attempts to check the `BUN_DEPS_CACHE_DIR` environment variable, but for some reason it doesn't work.
- Windows and Linux machines sometimes take up to 1-2 minutes to start tests. This is because robobun is listening for when the job is scheduled to provision the VM. Instead, it can start provisioning during the link step, or keep a pool of idle VMs around (but it's unclear how more expensive this is).
- There are a limited number of macOS VMs. This is because they are expensive and manually provisioned, mostly through MacStadium. If wait times are too long we can just provision more, or buy some.
- To prevent idle machines, robobun periodically checks for idle machines and terminates them. Before doing this, it checks to see if the machine is connected as an agent to Buildkite. However, sometimes the machine picks up a job in-between this time, and the job is terminated.

View File

@@ -6,36 +6,20 @@
#
# Changes to this file will be automatically uploaded on the next run
# for a particular commit.
#
# Future tests machines to be added:
# - macOS 12
# - Windows Server 2016 & 2019
# - Amazon Linux 2 & 2023
# - CentOS / RHEL / Fedora / other Linux distros
# - Docker containers
# - Rasberry Pi?
steps:
# macOS aarch64
- 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:
- "./.buildkite/scripts/build-deps.sh"
- key: "darwin-aarch64-build-zig"
label: ":darwin: aarch64 - build-zig"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh darwin aarch64"
- "bun run build:ci --target vendor"
- key: "darwin-aarch64-build-cpp"
label: ":darwin: aarch64 - build-cpp"
@@ -43,21 +27,32 @@ steps:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
env:
BUN_CPP_ONLY: "ON"
command:
- "./.buildkite/scripts/build-cpp.sh"
- "bun run build:ci --target bun"
- key: "darwin-aarch64-build-zig"
label: ":darwin: aarch64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain darwin-aarch64"
- key: "darwin-aarch64-build-bun"
label: ":darwin: aarch64 - build-bun"
depends_on:
- "darwin-aarch64-build-deps"
- "darwin-aarch64-build-zig"
- "darwin-aarch64-build-cpp"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
depends_on:
- "darwin-aarch64-build-vendor"
- "darwin-aarch64-build-cpp"
- "darwin-aarch64-build-zig"
env:
BUN_LINK_ONLY: "ON"
command:
- "./.buildkite/scripts/build-bun.sh"
- "bun run build:ci --target bun"
- key: "darwin-aarch64-test-macos-14"
label: ":darwin: 14 aarch64 - test-bun"
@@ -119,23 +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:
- "./.buildkite/scripts/build-deps.sh"
- key: "darwin-x64-build-zig"
label: ":darwin: x64 - build-zig"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh darwin x64"
- "bun run build:ci --target vendor"
- key: "darwin-x64-build-cpp"
label: ":darwin: x64 - build-cpp"
@@ -143,26 +129,37 @@ steps:
queue: "build-darwin"
os: "darwin"
arch: "x64"
env:
BUN_CPP_ONLY: "ON"
command:
- "./.buildkite/scripts/build-cpp.sh"
- "bun run build:ci --target bun"
- key: "darwin-x64-build-zig"
label: ":darwin: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain darwin-x64"
- key: "darwin-x64-build-bun"
label: ":darwin: x64 - build-bun"
depends_on:
- "darwin-x64-build-deps"
- "darwin-x64-build-zig"
- "darwin-x64-build-cpp"
agents:
queue: "build-darwin"
os: "darwin"
arch: "x64"
depends_on:
- "darwin-x64-build-vendor"
- "darwin-x64-build-cpp"
- "darwin-x64-build-zig"
env:
BUN_LINK_ONLY: "ON"
command:
- "./.buildkite/scripts/build-bun.sh"
- "bun run build:ci --target bun"
- key: "darwin-x64-test-macos-14"
label: ":darwin: 14 x64 - test-bun"
if: "build.branch != 'main'"
parallelism: 2
parallelism: 3
soft_fail:
- exit_status: 2
retry:
@@ -190,7 +187,7 @@ steps:
- key: "darwin-x64-test-macos-13"
label: ":darwin: 13 x64 - test-bun"
if: "build.branch != 'main'"
parallelism: 2
parallelism: 3
soft_fail:
- exit_status: 2
retry:
@@ -215,158 +212,18 @@ steps:
command:
- "./scripts/runner.node.mjs --step darwin-x64-build-bun"
# Linux aarch64
- key: "linux-aarch64"
group: ":linux: aarch64"
steps:
- key: "linux-aarch64-build-deps"
label: ":linux: aarch64 - build-deps"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-deps.sh"
- key: "linux-aarch64-build-zig"
label: ":linux: aarch64 - build-zig"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh linux aarch64"
- key: "linux-aarch64-build-cpp"
label: ":linux: aarch64 - build-cpp"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-cpp.sh"
- key: "linux-aarch64-build-bun"
label: ":linux: aarch64 - build-bun"
depends_on:
- "linux-aarch64-build-deps"
- "linux-aarch64-build-zig"
- "linux-aarch64-build-cpp"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-bun.sh"
- key: "linux-aarch64-test-debian-12"
label: ":debian: 12 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "debian"
release: "12"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
- key: "linux-aarch64-test-ubuntu-2204"
label: ":ubuntu: 22.04 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "ubuntu"
release: "22.04"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
- key: "linux-aarch64-test-ubuntu-2004"
label: ":ubuntu: 20.04 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "ubuntu"
release: "20.04"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
# Linux x64
- 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:
- "./.buildkite/scripts/build-deps.sh"
- key: "linux-x64-build-zig"
label: ":linux: x64 - build-zig"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh linux x64"
- "bun run build:ci --target vendor"
- key: "linux-x64-build-cpp"
label: ":linux: x64 - build-cpp"
@@ -374,26 +231,37 @@ steps:
queue: "build-linux"
os: "linux"
arch: "x64"
env:
BUN_CPP_ONLY: "ON"
command:
- "./.buildkite/scripts/build-cpp.sh"
- "bun run build:ci --target bun"
- key: "linux-x64-build-zig"
label: ":linux: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain linux-x64"
- key: "linux-x64-build-bun"
label: ":linux: x64 - build-bun"
depends_on:
- "linux-x64-build-deps"
- "linux-x64-build-zig"
- "linux-x64-build-cpp"
agents:
queue: "build-linux"
os: "linux"
arch: "x64"
depends_on:
- "linux-x64-build-vendor"
- "linux-x64-build-cpp"
- "linux-x64-build-zig"
env:
BUN_LINK_ONLY: "ON"
command:
- "./.buildkite/scripts/build-bun.sh"
- "bun run build:ci --target bun"
- key: "linux-x64-test-debian-12"
label: ":debian: 12 x64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -422,7 +290,7 @@ steps:
- key: "linux-x64-test-ubuntu-2204"
label: ":ubuntu: 22.04 x64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -451,7 +319,7 @@ steps:
- key: "linux-x64-test-ubuntu-2004"
label: ":ubuntu: 20.04 x64 - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -481,23 +349,16 @@ 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"
arch: "x64"
env:
ENABLE_BASELINE: "ON"
command:
- "./.buildkite/scripts/build-deps.sh"
- key: "linux-x64-baseline-build-zig"
label: ":linux: x64-baseline - build-zig"
agents:
queue: "build-darwin"
os: "darwin"
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh linux x64"
- "bun run build:ci --target vendor"
- key: "linux-x64-baseline-build-cpp"
label: ":linux: x64-baseline - build-cpp"
@@ -505,26 +366,41 @@ steps:
queue: "build-linux"
os: "linux"
arch: "x64"
env:
ENABLE_BASELINE: "ON"
BUN_CPP_ONLY: "ON"
command:
- "./.buildkite/scripts/build-cpp.sh"
- "bun run build:ci --target bun"
- key: "linux-x64-baseline-build-zig"
label: ":linux: x64-baseline - build-zig"
agents:
queue: "build-zig"
env:
ENABLE_BASELINE: "ON"
command:
- "bun run build:ci --target bun-zig --toolchain linux-x64-baseline"
- key: "linux-x64-baseline-build-bun"
label: ":linux: x64-baseline - build-bun"
depends_on:
- "linux-x64-baseline-build-deps"
- "linux-x64-baseline-build-zig"
- "linux-x64-baseline-build-cpp"
agents:
queue: "build-linux"
os: "linux"
arch: "x64"
depends_on:
- "linux-x64-baseline-build-vendor"
- "linux-x64-baseline-build-cpp"
- "linux-x64-baseline-build-zig"
env:
ENABLE_BASELINE: "ON"
BUN_LINK_ONLY: "ON"
command:
- "./.buildkite/scripts/build-bun.sh"
- "bun run build:ci --target bun"
- key: "linux-x64-baseline-test-debian-12"
label: ":debian: 12 x64-baseline - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -553,7 +429,7 @@ steps:
- key: "linux-x64-baseline-test-ubuntu-2204"
label: ":ubuntu: 22.04 x64-baseline - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -582,7 +458,7 @@ steps:
- key: "linux-x64-baseline-test-ubuntu-2004"
label: ":ubuntu: 20.04 x64-baseline - test-bun"
if: "build.branch != 'main'"
parallelism: 5
parallelism: 10
soft_fail:
- exit_status: 2
retry:
@@ -608,31 +484,151 @@ steps:
command:
- "./scripts/runner.node.mjs --step linux-x64-baseline-build-bun"
# Linux aarch64
- key: "linux-aarch64"
group: ":linux: aarch64"
steps:
- key: "linux-aarch64-build-vendor"
label: ":linux: aarch64 - build-vendor"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
command:
- "bun run build:ci --target vendor"
- key: "linux-aarch64-build-cpp"
label: ":linux: aarch64 - build-cpp"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
env:
BUN_CPP_ONLY: "ON"
command:
- "bun run build:ci --target bun"
- key: "linux-aarch64-build-zig"
label: ":linux: aarch64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain linux-aarch64"
- key: "linux-aarch64-build-bun"
label: ":linux: aarch64 - build-bun"
agents:
queue: "build-linux"
os: "linux"
arch: "aarch64"
depends_on:
- "linux-aarch64-build-vendor"
- "linux-aarch64-build-cpp"
- "linux-aarch64-build-zig"
env:
BUN_LINK_ONLY: "ON"
command:
- "bun run build:ci --target bun"
- key: "linux-aarch64-test-debian-12"
label: ":debian: 12 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 10
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "debian"
release: "12"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
- key: "linux-aarch64-test-ubuntu-2204"
label: ":ubuntu: 22.04 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 10
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "ubuntu"
release: "22.04"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
- key: "linux-aarch64-test-ubuntu-2004"
label: ":ubuntu: 20.04 aarch64 - test-bun"
if: "build.branch != 'main'"
parallelism: 10
soft_fail:
- exit_status: 2
retry:
automatic:
- exit_status: 1
limit: 1
- exit_status: -1
limit: 3
- exit_status: 255
limit: 3
- signal_reason: agent_stop
limit: 3
- signal: SIGTERM
limit: 3
depends_on:
- "linux-aarch64-build-bun"
agents:
robobun: "true"
os: "linux"
arch: "aarch64"
distro: "ubuntu"
release: "20.04"
command:
- "./scripts/runner.node.mjs --step linux-aarch64-build-bun"
# Windows x64
- 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"
artifact_paths:
- "build\\bun-deps\\*.lib"
env:
CCACHE_DISABLE: "1"
command:
- ".\\scripts\\all-dependencies.ps1"
- key: "windows-x64-build-zig"
label: ":windows: x64 - build-zig"
agents:
queue: "build-darwin"
os: "darwin" # cross-compile on Linux or Darwin
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh windows x64"
- "bun run build:ci --target vendor"
- key: "windows-x64-build-cpp"
label: ":windows: x64 - build-cpp"
@@ -640,33 +636,32 @@ steps:
queue: "build-windows"
os: "windows"
arch: "x64"
artifact_paths:
# HACK: See scripts/build-bun-cpp.ps1
# - "build\\bun-cpp-objects.a"
- "build\\bun-cpp-objects.a.*"
env:
CCACHE_DISABLE: "1"
BUN_CPP_ONLY: "ON"
command:
- ".\\scripts\\build-bun-cpp.ps1"
- "bun run build:ci --target bun"
- key: "windows-x64-build-zig"
label: ":windows: x64 - build-zig"
agents:
queue: "build-zig"
command:
- "bun run build:ci --target bun-zig --toolchain windows-x64"
- key: "windows-x64-build-bun"
label: ":windows: x64 - build-bun"
depends_on:
- "windows-x64-build-deps"
- "windows-x64-build-zig"
- "windows-x64-build-cpp"
agents:
queue: "build-windows"
os: "windows"
arch: "x64"
artifact_paths:
- "bun-windows-x64.zip"
- "bun-windows-x64-profile.zip"
- "features.json"
depends_on:
- "windows-x64-build-vendor"
- "windows-x64-build-cpp"
- "windows-x64-build-zig"
env:
CCACHE_DISABLE: "1"
BUN_LINK_ONLY: "ON"
command:
- ".\\scripts\\buildkite-link-bun.ps1"
- "bun run build:ci --target bun"
- key: "windows-x64-test-bun"
label: ":windows: x64 - test-bun"
@@ -697,28 +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"
artifact_paths:
- "build\\bun-deps\\*.lib"
env:
CCACHE_DISABLE: "1"
USE_BASELINE_BUILD: "1"
ENABLE_BASELINE: "ON"
command:
- ".\\scripts\\all-dependencies.ps1"
- key: "windows-x64-baseline-build-zig"
label: ":windows: x64-baseline - build-zig"
agents:
queue: "build-darwin"
os: "darwin" # cross-compile on Linux or Darwin
arch: "aarch64"
command:
- "./.buildkite/scripts/build-zig.sh windows x64"
- "bun run build:ci --target vendor"
- key: "windows-x64-baseline-build-cpp"
label: ":windows: x64-baseline - build-cpp"
@@ -726,35 +709,36 @@ steps:
queue: "build-windows"
os: "windows"
arch: "x64"
artifact_paths:
# HACK: See scripts/build-bun-cpp.ps1
# - "build\\bun-cpp-objects.a"
- "build\\bun-cpp-objects.a.*"
env:
CCACHE_DISABLE: "1"
USE_BASELINE_BUILD: "1"
ENABLE_BASELINE: "ON"
BUN_CPP_ONLY: "ON"
command:
- ".\\scripts\\build-bun-cpp.ps1"
- "bun run build:ci --target bun"
- key: "windows-x64-baseline-build-zig"
label: ":windows: x64-baseline - build-zig"
agents:
queue: "build-zig"
env:
ENABLE_BASELINE: "ON"
command:
- "bun run build:ci --target bun-zig --toolchain windows-x64-baseline"
- key: "windows-x64-baseline-build-bun"
label: ":windows: x64-baseline - build-bun"
depends_on:
- "windows-x64-baseline-build-deps"
- "windows-x64-baseline-build-zig"
- "windows-x64-baseline-build-cpp"
agents:
queue: "build-windows"
os: "windows"
arch: "x64"
artifact_paths:
- "bun-windows-x64-baseline.zip"
- "bun-windows-x64-baseline-profile.zip"
- "features.json"
depends_on:
- "windows-x64-baseline-build-vendor"
- "windows-x64-baseline-build-cpp"
- "windows-x64-baseline-build-zig"
env:
CCACHE_DISABLE: "1"
USE_BASELINE_BUILD: "1"
ENABLE_BASELINE: "ON"
BUN_LINK_ONLY: "ON"
command:
- ".\\scripts\\buildkite-link-bun.ps1 -Baseline $$True"
- "bun run build:ci --target bun"
- key: "windows-x64-baseline-test-bun"
label: ":windows: x64-baseline - test-bun"

View File

@@ -1,62 +0,0 @@
#!/bin/bash
set -eo pipefail
source "$(dirname "$0")/env.sh"
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
cwd="$(pwd)"
mkdir -p build
source "$(dirname "$0")/download-artifact.sh" "build/bun-deps/**" --step "$BUILDKITE_GROUP_KEY-build-deps"
source "$(dirname "$0")/download-artifact.sh" "build/bun-zig.o" --step "$BUILDKITE_GROUP_KEY-build-zig"
source "$(dirname "$0")/download-artifact.sh" "build/bun-cpp-objects.a" --step "$BUILDKITE_GROUP_KEY-build-cpp" --split
cd build
run_command cmake .. "${CMAKE_FLAGS[@]}" \
-GNinja \
-DBUN_LINK_ONLY="1" \
-DNO_CONFIGURE_DEPENDS="1" \
-DBUN_ZIG_OBJ_DIR="$cwd/build" \
-DBUN_CPP_ARCHIVE="$cwd/build/bun-cpp-objects.a" \
-DBUN_DEPS_OUT_DIR="$cwd/build/bun-deps" \
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-DCPU_TARGET="$CPU_TARGET" \
-DUSE_LTO="$USE_LTO" \
-DUSE_DEBUG_JSC="$USE_DEBUG_JSC" \
-DCANARY="$CANARY" \
-DGIT_SHA="$GIT_SHA"
run_command ninja -v -j "$CPUS"
run_command ls
tag="bun-$BUILDKITE_GROUP_KEY"
if [ "$USE_LTO" == "OFF" ]; then
# Remove OS check when LTO is enabled on macOS again
if [[ "$tag" == *"darwin"* ]]; then
tag="$tag-nolto"
fi
fi
for name in bun bun-profile; do
dir="$tag"
if [ "$name" == "bun-profile" ]; then
dir="$tag-profile"
fi
run_command chmod +x "$name"
run_command "./$name" --revision
run_command mkdir -p "$dir"
run_command mv "$name" "$dir/$name"
run_command zip -r "$dir.zip" "$dir"
source "$cwd/.buildkite/scripts/upload-artifact.sh" "$dir.zip"
# temporary disable this so CI can run
# this is failing because $name is now in $dir/$name and if changed to $dir/$name we get ENOENT reading "bun:internal-for-testing"
# if [ "$name" == "bun-profile" ]; then
# export BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING="1"
# run_command "./$name" -e "require('fs').writeFileSync('./features.json', JSON.stringify(require('bun:internal-for-testing').crash_handler.getFeatureData()))"
# source "$cwd/.buildkite/scripts/upload-artifact.sh" "features.json"
# fi
done

View File

@@ -1,37 +0,0 @@
#!/bin/bash
set -eo pipefail
export FORCE_UPDATE_SUBMODULES=1
# env.sh calls update_submodules.sh
source "$(dirname "$0")/env.sh"
{ set +x; } 2>/dev/null
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
mkdir -p build
cd build
mkdir -p tmp_modules tmp_functions js codegen
run_command cmake .. "${CMAKE_FLAGS[@]}" \
-GNinja \
-DBUN_CPP_ONLY="1" \
-DNO_CONFIGURE_DEPENDS="1" \
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-DCPU_TARGET="$CPU_TARGET" \
-DUSE_LTO="$USE_LTO" \
-DUSE_DEBUG_JSC="$USE_DEBUG_JSC" \
-DCANARY="$CANARY" \
-DGIT_SHA="$GIT_SHA"
chmod +x compile-cpp-only.sh
source compile-cpp-only.sh -v -j "$CPUS"
{ set +x; } 2>/dev/null
cd ..
source "$(dirname "$0")/upload-artifact.sh" "build/bun-cpp-objects.a" --split

View File

@@ -1,22 +0,0 @@
#!/bin/bash
set -eo pipefail
source "$(dirname "$0")/env.sh"
source "$(realpath $(dirname "$0")/../../scripts/all-dependencies.sh)"
artifacts=(
libcrypto.a libssl.a libdecrepit.a
libcares.a
libarchive.a
liblolhtml.a
libmimalloc.a libmimalloc.o
libtcc.a
libz.a
libzstd.a
libdeflate.a
liblshpack.a
)
for artifact in "${artifacts[@]}"; do
source "$(dirname "$0")/upload-artifact.sh" "build/bun-deps/$artifact"
done

View File

@@ -1,40 +0,0 @@
#!/bin/bash
set -eo pipefail
source "$(dirname "$0")/env.sh"
function assert_bun() {
if ! command -v bun &>/dev/null; then
echo "error: bun is not installed" 1>&2
exit 1
fi
}
function assert_make() {
if ! command -v make &>/dev/null; then
echo "error: make is not installed" 1>&2
exit 1
fi
}
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
function build_node_fallbacks() {
local cwd="src/node-fallbacks"
run_command bun install --cwd "$cwd" --frozen-lockfile
run_command bun run --cwd "$cwd" build
}
function build_old_js() {
run_command bun install --frozen-lockfile
run_command make runtime_js fallback_decoder bun_error
}
assert_bun
assert_make
build_node_fallbacks
build_old_js

View File

@@ -1,101 +0,0 @@
#!/bin/bash
set -euo pipefail
export CMAKE_FLAGS=""
source "$(dirname "$0")/env.sh"
if [[ -n "$CMAKE_FLAGS" ]]; then
echo "CMAKE_FLAGS should not be empty"
exit 1
fi
function assert_target() {
local arch="${2-$(uname -m)}"
case "$(echo "$arch" | tr '[:upper:]' '[:lower:]')" in
x64 | x86_64 | amd64)
export ZIG_ARCH="x86_64"
if [[ "$BUILDKITE_STEP_KEY" == *"baseline"* ]]; then
export ZIG_CPU_TARGET="nehalem"
else
export ZIG_CPU_TARGET="haswell"
fi
;;
aarch64 | arm64)
export ZIG_ARCH="aarch64"
export ZIG_CPU_TARGET="native"
;;
*)
echo "error: Unsupported architecture: $arch" 1>&2
exit 1
;;
esac
local os="${1-$(uname -s)}"
case "$(echo "$os" | tr '[:upper:]' '[:lower:]')" in
linux)
export ZIG_OS="linux"
export ZIG_TARGET="$ZIG_ARCH-linux-gnu"
;;
darwin)
export ZIG_OS="macos"
export ZIG_TARGET="$ZIG_ARCH-macos-none"
;;
windows)
export ZIG_OS="windows"
export ZIG_TARGET="$ZIG_ARCH-windows-msvc"
;;
*)
echo "error: Unsupported operating system: $os" 1>&2
exit 1
;;
esac
}
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
assert_target "$@"
# Since the zig build depends on files from the zig submodule,
# make sure to update the submodule before building.
run_command git submodule update --init --recursive --progress --depth=1 --checkout src/deps/zig
# TODO: Move these to be part of the CMake build
source "$(dirname "$0")/build-old-js.sh"
cwd="$(pwd)"
mkdir -p build
cd build
# in buildkite this script to compile for windows is run on a macos machine
# so the cmake windows detection for this logic is not ran
ZIG_OPTIMIZE="ReleaseFast"
if [[ "$ZIG_OS" == "windows" ]]; then
ZIG_OPTIMIZE="ReleaseSafe"
fi
run_command cmake .. "${CMAKE_FLAGS[@]}" \
-GNinja \
-DNO_CONFIGURE_DEPENDS="1" \
-DNO_CODEGEN="0" \
-DWEBKIT_DIR="omit" \
-DBUN_ZIG_OBJ_DIR="$cwd/build" \
-DZIG_LIB_DIR="$cwd/src/deps/zig/lib" \
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
-DARCH="$ZIG_ARCH" \
-DCPU_TARGET="$ZIG_CPU_TARGET" \
-DZIG_TARGET="$ZIG_TARGET" \
-DUSE_LTO="$USE_LTO" \
-DUSE_DEBUG_JSC="$USE_DEBUG_JSC" \
-DCANARY="$CANARY" \
-DZIG_OPTIMIZE="$ZIG_OPTIMIZE" \
-DGIT_SHA="$GIT_SHA"
export ONLY_ZIG="1"
run_command ninja "$cwd/build/bun-zig.o" -v -j "$CPUS"
cd ..
source "$(dirname "$0")/upload-artifact.sh" "build/bun-zig.o"

View File

@@ -1,47 +0,0 @@
param (
[Parameter(Mandatory=$true)]
[string[]] $Paths,
[switch] $Split
)
$ErrorActionPreference = "Stop"
function Assert-Buildkite-Agent() {
if (-not (Get-Command "buildkite-agent" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find buildkite-agent, please install it: https://buildkite.com/docs/agent/v3/install"
exit 1
}
}
function Assert-Join-File() {
if (-not (Get-Command "Join-File" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find Join-File, please install it: https://www.powershellgallery.com/packages/FileSplitter/1.3"
exit 1
}
}
function Download-Buildkite-Artifact() {
param (
[Parameter(Mandatory=$true)]
[string] $Path,
)
if ($Split) {
& buildkite-agent artifact download "$Path.*" --debug --debug-http
Join-File -Path "$(Resolve-Path .)\$Path" -Verbose -DeletePartFiles
} else {
& buildkite-agent artifact download "$Path" --debug --debug-http
}
if (-not (Test-Path $Path)) {
Write-Error "Could not find artifact: $Path"
exit 1
}
}
Assert-Buildkite-Agent
if ($Split) {
Assert-Join-File
}
foreach ($Path in $Paths) {
Download-Buildkite-Artifact $Path
}

View File

@@ -1,59 +0,0 @@
#!/bin/bash
set -euo pipefail
function assert_buildkite_agent() {
if ! command -v buildkite-agent &>/dev/null; then
echo "error: Cannot find buildkite-agent, please install it:"
echo "https://buildkite.com/docs/agent/v3/install"
exit 1
fi
}
function download_buildkite_artifact() {
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
echo "error: No path provided for artifact download"
exit 1
fi
local path="$1"
shift
local split="0"
local args=()
while [ $# -gt 0 ]; do
case "$1" in
--split)
split="1"
shift
;;
*)
args+=("$1")
shift
;;
esac
done
if [ "$split" == "1" ]; then
run_command buildkite-agent artifact download "$path.*" . "${args[@]:-}"
run_command cat "$path".?? >"$path"
run_command rm -f "$path".??
else
run_command buildkite-agent artifact download "$path" . "${args[@]:-}"
fi
if [[ "$path" != *"*"* ]] && [ ! -f "$path" ]; then
echo "error: Could not find artifact: $path"
exit 1
fi
}
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
assert_buildkite_agent
download_buildkite_artifact "$@"

View File

@@ -1,146 +0,0 @@
#!/bin/bash
set -euo pipefail
BUILDKITE_REPO=${BUILDKITE_REPO:-}
BUILDKITE_CLEAN_CHECKOUT=${BUILDKITE_CLEAN_CHECKOUT:-}
BUILDKITE_BRANCH=${BUILDKITE_BRANCH:-}
CCACHE_DIR=${CCACHE_DIR:-}
SCCACHE_DIR=${SCCACHE_DIR:-}
ZIG_LOCAL_CACHE_DIR=${ZIG_LOCAL_CACHE_DIR:-}
ZIG_GLOBAL_CACHE_DIR=${ZIG_GLOBAL_CACHE_DIR:-}
BUN_DEPS_CACHE_DIR=${BUN_DEPS_CACHE_DIR:-}
BUN_DEPS_CACHE_DIR=${BUN_DEPS_CACHE_DIR:-}
BUILDKITE_STEP_KEY=${BUILDKITE_STEP_KEY:-}
ROOT_DIR="$(realpath "$(dirname "$0")/../../")"
# Fail if we cannot find the root directory
if [ ! -d "$ROOT_DIR" ]; then
echo "error: Cannot find root directory: '$ROOT_DIR'" 1>&2
exit 1
fi
function assert_os() {
local os="$(uname -s)"
case "$os" in
Linux)
echo "linux"
;;
Darwin)
echo "darwin"
;;
*)
echo "error: Unsupported operating system: $os" 1>&2
exit 1
;;
esac
}
function assert_arch() {
local arch="$(uname -m)"
case "$arch" in
aarch64 | arm64)
echo "aarch64"
;;
x86_64 | amd64)
echo "x64"
;;
*)
echo "error: Unknown architecture: $arch" 1>&2
exit 1
;;
esac
}
function assert_build() {
if [ -z "$BUILDKITE_REPO" ]; then
echo "error: Cannot find repository for this build"
exit 1
fi
if [ -z "$BUILDKITE_COMMIT" ]; then
echo "error: Cannot find commit for this build"
exit 1
fi
if [ -z "$BUILDKITE_STEP_KEY" ]; then
echo "error: Cannot find step key for this build"
exit 1
fi
if [ -n "$BUILDKITE_GROUP_KEY" ] && [[ "$BUILDKITE_STEP_KEY" != "$BUILDKITE_GROUP_KEY"* ]]; then
echo "error: Build step '$BUILDKITE_STEP_KEY' does not start with group key '$BUILDKITE_GROUP_KEY'"
exit 1
fi
# Skip os and arch checks for Zig, since it's cross-compiled on macOS
if [[ "$BUILDKITE_STEP_KEY" != *"zig"* ]]; then
local os="$(assert_os)"
if [[ "$BUILDKITE_STEP_KEY" != *"$os"* ]]; then
echo "error: Build step '$BUILDKITE_STEP_KEY' does not match operating system '$os'"
exit 1
fi
local arch="$(assert_arch)"
if [[ "$BUILDKITE_STEP_KEY" != *"$arch"* ]]; then
echo "error: Build step '$BUILDKITE_STEP_KEY' does not match architecture '$arch'"
exit 1
fi
fi
}
function assert_buildkite_agent() {
if (! command -v buildkite-agent &>/dev/null); then
echo "error: Cannot find buildkite-agent, please install it:"
echo "https://buildkite.com/docs/agent/v3/install"
exit 1
fi
}
function export_environment() {
source "${ROOT_DIR}/scripts/env.sh"
source "${ROOT_DIR}/scripts/update-submodules.sh"
{ set +x; } 2>/dev/null
export GIT_SHA="$BUILDKITE_COMMIT"
if [ "$BUILDKITE_CLEAN_CHECKOUT" == "true" ] || [ "$BUILDKITE_BRANCH" == "main" ]; then
local tmpdir="$(mktemp -d 2>/dev/null || mktemp -d -t 'new')"
export CCACHE_DIR="$tmpdir/.cache/ccache"
export SCCACHE_DIR="$tmpdir/.cache/sccache"
export ZIG_LOCAL_CACHE_DIR="$tmpdir/.cache/zig-cache"
export ZIG_GLOBAL_CACHE_DIR="$tmpdir/.cache/zig-cache"
export BUN_DEPS_CACHE_DIR="$tmpdir/.cache/bun-deps"
export CCACHE_RECACHE="1"
else
export CCACHE_DIR="$HOME/.cache/ccache/$BUILDKITE_STEP_KEY"
export SCCACHE_DIR="$HOME/.cache/sccache/$BUILDKITE_STEP_KEY"
export ZIG_LOCAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY"
export ZIG_GLOBAL_CACHE_DIR="$HOME/.cache/zig-cache/$BUILDKITE_STEP_KEY"
export BUN_DEPS_CACHE_DIR="$HOME/.cache/bun-deps/$BUILDKITE_STEP_KEY"
fi
if [ "$(assert_os)" == "linux" ]; then
export USE_LTO="ON"
fi
if [ "$(assert_arch)" == "aarch64" ]; then
export CPU_TARGET="native"
elif [[ "$BUILDKITE_STEP_KEY" == *"baseline"* ]]; then
export CPU_TARGET="nehalem"
else
export CPU_TARGET="haswell"
fi
if $(buildkite-agent meta-data exists release &>/dev/null); then
export CMAKE_BUILD_TYPE="$(buildkite-agent meta-data get release)"
else
export CMAKE_BUILD_TYPE="Release"
fi
if $(buildkite-agent meta-data exists canary &>/dev/null); then
export CANARY="$(buildkite-agent meta-data get canary)"
else
export CANARY="1"
fi
if $(buildkite-agent meta-data exists assertions &>/dev/null); then
export USE_DEBUG_JSC="$(buildkite-agent meta-data get assertions)"
else
export USE_DEBUG_JSC="OFF"
fi
}
assert_build
assert_buildkite_agent
export_environment

View File

@@ -1,47 +0,0 @@
param (
[Parameter(Mandatory=$true)]
[string[]] $Paths,
[switch] $Split
)
$ErrorActionPreference = "Stop"
function Assert-Buildkite-Agent() {
if (-not (Get-Command "buildkite-agent" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find buildkite-agent, please install it: https://buildkite.com/docs/agent/v3/install"
exit 1
}
}
function Assert-Split-File() {
if (-not (Get-Command "Split-File" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find Split-File, please install it: https://www.powershellgallery.com/packages/FileSplitter/1.3"
exit 1
}
}
function Upload-Buildkite-Artifact() {
param (
[Parameter(Mandatory=$true)]
[string] $Path,
)
if (-not (Test-Path $Path)) {
Write-Error "Could not find artifact: $Path"
exit 1
}
if ($Split) {
Remove-Item -Path "$Path.*" -Force
Split-File -Path (Resolve-Path $Path) -PartSizeBytes "50MB" -Verbose
$Path = "$Path.*"
}
& buildkite-agent artifact upload "$Path" --debug --debug-http
}
Assert-Buildkite-Agent
if ($Split) {
Assert-Split-File
}
foreach ($Path in $Paths) {
Upload-Buildkite-Artifact $Path
}

View File

@@ -1,71 +0,0 @@
#!/bin/bash
set -euo pipefail
function assert_buildkite_agent() {
if ! command -v buildkite-agent &>/dev/null; then
echo "error: Cannot find buildkite-agent, please install it:"
echo "https://buildkite.com/docs/agent/v3/install"
exit 1
fi
}
function assert_split() {
if ! command -v split &>/dev/null; then
echo "error: Cannot find split, please install it:"
echo "https://www.gnu.org/software/coreutils/split"
exit 1
fi
}
function upload_buildkite_artifact() {
if [ -z "${1:-}" ]; then
return
fi
local path="$1"
shift
local split="0"
local args=() # Initialize args as an empty array
while true; do
if [ -z "${1:-}" ]; then
break
fi
case "$1" in
--split)
split="1"
shift
;;
*)
args+=("$1")
shift
;;
esac
done
if [ ! -f "$path" ]; then
echo "error: Could not find artifact: $path"
exit 1
fi
if [ "$split" == "1" ]; then
run_command rm -f "$path."*
run_command split -b 50MB -d "$path" "$path."
if [ "${args[@]:-}" != "" ]; then
run_command buildkite-agent artifact upload "$path.*" "${args[@]}"
else
run_command buildkite-agent artifact upload "$path.*"
fi
elif [ "${args[@]:-}" != "" ]; then
run_command buildkite-agent artifact upload "$path" "${args[@]:-}"
else
run_command buildkite-agent artifact upload "$path"
fi
}
function run_command() {
set -x
"$@"
{ set +x; } 2>/dev/null
}
assert_buildkite_agent
upload_buildkite_artifact "$@"

9
.clang-tidy Normal file
View File

@@ -0,0 +1,9 @@
WarningsAsErrors: "*"
FormatStyle: webkit
Checks: >
-*,
clang-analyzer-*,
-clang-analyzer-optin.core.EnumCastOutOfRange
-clang-analyzer-webkit.UncountedLambdaCapturesChecker
-clang-analyzer-optin.core.EnumCastOutOfRange
-clang-analyzer-webkit.RefCntblBaseVirtualDtor

View File

@@ -1,3 +1,5 @@
Index:
Background: Skip # Disable slow background indexing of these files.
CompileFlags:
CompilationDatabase: build/debug

4
.gitattributes vendored
View File

@@ -44,8 +44,8 @@ test/**/* linguist-documentation
bench/**/* linguist-documentation
examples/**/* linguist-documentation
src/deps/*.c linguist-vendored
src/deps/brotli/** linguist-vendored
vendor/*.c linguist-vendored
vendor/brotli/** linguist-vendored
test/js/node/test/fixtures linguist-vendored
test/js/node/test/common linguist-vendored

View File

@@ -13,12 +13,12 @@ on:
run-id:
type: string
description: The workflow ID to download artifacts (skips the build step)
pull_request:
paths:
- ".github/workflows/lint-cpp.yml"
- "**/*.cpp"
- "src/deps/**/*"
- "CMakeLists.txt"
# pull_request:
# paths:
# - ".github/workflows/lint-cpp.yml"
# - "**/*.cpp"
# - "vendor/**/*"
# - "CMakeLists.txt"
jobs:
lint-cpp:

View File

@@ -65,17 +65,17 @@ jobs:
echo "did_fail=$(cat did_fail.txt)" >> $GITHUB_OUTPUT
- name: Upload format.log
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: format.log
path: format.log
- name: Upload PR
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: pr-number.txt
path: pr-number.txt
- name: Upload PR
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: did_fail.txt
path: did_fail.txt

32
.gitignore vendored
View File

@@ -49,7 +49,6 @@
/build-*/
/bun-webkit
/kcov-out
/src/deps/libuv
/test-report.json
/test-report.md
/test.js
@@ -117,11 +116,6 @@ sign.json
src/bun.js/bindings-obj
src/bun.js/bindings/GeneratedJS2Native.zig
src/bun.js/debug-bindings-obj
src/deps/c-ares/build
src/deps/libiconv
src/deps/openssl
src/deps/PLCrashReporter/
src/deps/s2n-tls
src/deps/zig-clap/.gitattributes
src/deps/zig-clap/.github
src/deps/zig-clap/example
@@ -146,3 +140,29 @@ zig-out
test/node.js/upstream
.zig-cache
scripts/env.local
*.generated.ts
# Temporary files
/tmp
# Dependencies
/vendor
# Dependencies (before CMake)
# These can be removed in the far future
/src/bun.js/WebKit
/src/deps/WebKit
/src/deps/boringssl
/src/deps/brotli
/src/deps/c*ares
/src/deps/lol*html
/src/deps/libarchive
/src/deps/libdeflate
/src/deps/libuv
/src/deps/ls*hpack
/src/deps/mimalloc
/src/deps/picohttpparser
/src/deps/tinycc
/src/deps/zstd
/src/deps/zlib
/src/deps/zig

88
.gitmodules vendored
View File

@@ -1,88 +0,0 @@
[submodule "src/javascript/jsc/WebKit"]
path = src/bun.js/WebKit
url = https://github.com/oven-sh/WebKit.git
ignore = dirty
depth = 1
update = none
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/picohttpparser"]
path = src/deps/picohttpparser
url = https://github.com/h2o/picohttpparser.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/mimalloc"]
path = src/deps/mimalloc
url = https://github.com/Jarred-Sumner/mimalloc.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/zlib"]
path = src/deps/zlib
url = https://github.com/cloudflare/zlib.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/libarchive"]
path = src/deps/libarchive
url = https://github.com/libarchive/libarchive.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/boringssl"]
path = src/deps/boringssl
url = https://github.com/oven-sh/boringssl.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/lol-html"]
path = src/deps/lol-html
url = https://github.com/cloudflare/lol-html
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/tinycc"]
path = src/deps/tinycc
url = https://github.com/Jarred-Sumner/tinycc.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/c-ares"]
path = src/deps/c-ares
url = https://github.com/c-ares/c-ares.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/zstd"]
path = src/deps/zstd
url = https://github.com/facebook/zstd.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/ls-hpack"]
path = src/deps/ls-hpack
url = https://github.com/litespeedtech/ls-hpack.git
ignore = dirty
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "zig"]
path = src/deps/zig
url = https://github.com/oven-sh/zig
depth = 1
shallow = true
fetchRecurseSubmodules = false
[submodule "src/deps/libdeflate"]
path = src/deps/libdeflate
url = https://github.com/ebiggers/libdeflate
ignore = "dirty"

View File

@@ -1,4 +1,4 @@
command script import src/deps/zig/tools/lldb_pretty_printers.py
command script import src/bun.js/WebKit/Tools/lldb/lldb_webkit.py
command script import vendor/zig/tools/lldb_pretty_printers.py
command script import vendor/WebKit/Tools/lldb/lldb_webkit.py
# type summary add --summary-string "${var} | inner=${var[0-30]}, source=${var[33-64]}, tag=${var[31-32]}" "unsigned long"

View File

@@ -1,5 +1,5 @@
src/bun.js/WebKit
src/deps
vendor
test/snapshots
test/js/deno
test/node.js

View File

@@ -3,18 +3,18 @@
{
"name": "Debug",
"forcedInclude": ["${workspaceFolder}/src/bun.js/bindings/root.h"],
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"compileCommands": "${workspaceFolder}/build/debug/compile_commands.json",
"includePath": [
"${workspaceFolder}/build/bun-webkit/include",
"${workspaceFolder}/build/codegen",
"${workspaceFolder}/build/debug/codegen",
"${workspaceFolder}/src/bun.js/bindings/",
"${workspaceFolder}/src/bun.js/bindings/webcore/",
"${workspaceFolder}/src/bun.js/bindings/sqlite/",
"${workspaceFolder}/src/bun.js/bindings/webcrypto/",
"${workspaceFolder}/src/bun.js/modules/",
"${workspaceFolder}/src/js/builtins/",
"${workspaceFolder}/src/deps/boringssl/include/",
"${workspaceFolder}/src/deps",
"${workspaceFolder}/vendor/boringssl/include/",
"${workspaceFolder}/vendor",
"${workspaceFolder}/src/napi/*",
"${workspaceFolder}/packages/bun-usockets/src",
"${workspaceFolder}/packages/",
@@ -26,8 +26,8 @@
"${workspaceFolder}/src/napi/*",
"${workspaceFolder}/src/js/builtins/*",
"${workspaceFolder}/src/bun.js/modules/*",
"${workspaceFolder}/src/deps/*",
"${workspaceFolder}/src/deps/boringssl/include/*",
"${workspaceFolder}/vendor/*",
"${workspaceFolder}/vendor/boringssl/include/*",
"${workspaceFolder}/packages/bun-usockets/*",
"${workspaceFolder}/packages/bun-uws/*",
"${workspaceFolder}/src/napi/*",
@@ -55,12 +55,12 @@
"name": "BunWithJSCDebug",
"forcedInclude": ["${workspaceFolder}/src/bun.js/bindings/root.h"],
"includePath": [
"${workspaceFolder}/build/codegen",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/ICU/Headers/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/JavaScriptCore/PrivateHeaders/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/WTF/Headers",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/bmalloc/Headers/",
"${workspaceFolder}/build/debug/codegen",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/ICU/Headers/",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/PrivateHeaders/",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/WTF/Headers",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/bmalloc/Headers/",
"${workspaceFolder}/src/bun.js/bindings/",
"${workspaceFolder}/src/bun.js/bindings/webcore/",
"${workspaceFolder}/src/bun.js/bindings/sqlite/",
@@ -68,19 +68,19 @@
"${workspaceFolder}/src/bun.js/modules/",
"${workspaceFolder}/src/js/builtins/",
"${workspaceFolder}/src/js/out",
"${workspaceFolder}/src/deps/boringssl/include/",
"${workspaceFolder}/src/deps",
"${workspaceFolder}/vendor/boringssl/include/",
"${workspaceFolder}/vendor",
"${workspaceFolder}/src/napi/*",
"${workspaceFolder}/packages/bun-usockets/src",
"${workspaceFolder}/packages/",
],
"browse": {
"path": [
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/ICU/Headers/",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/JavaScriptCore/PrivateHeaders/**",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/WTF/Headers/**",
"${workspaceFolder}/src/bun.js/WebKit/WebKitBuild/Debug/bmalloc/Headers/**",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/ICU/Headers/",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/JavaScriptCore/PrivateHeaders/**",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/WTF/Headers/**",
"${workspaceFolder}/vendor/WebKit/WebKitBuild/Debug/bmalloc/Headers/**",
"${workspaceFolder}/src/bun.js/bindings/*",
"${workspaceFolder}/src/bun.js/bindings/*",
"${workspaceFolder}/src/napi/*",
@@ -90,8 +90,8 @@
"${workspaceFolder}/src/js/builtins/*",
"${workspaceFolder}/src/js/out/*",
"${workspaceFolder}/src/bun.js/modules/*",
"${workspaceFolder}/src/deps",
"${workspaceFolder}/src/deps/boringssl/include/",
"${workspaceFolder}/vendor",
"${workspaceFolder}/vendor/boringssl/include/",
"${workspaceFolder}/packages/bun-usockets/",
"${workspaceFolder}/packages/bun-uws/",
"${workspaceFolder}/src/napi",

98
.vscode/launch.json generated vendored
View File

@@ -12,7 +12,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -27,7 +27,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] --only",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "--only", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -48,7 +48,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] (fast)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -63,7 +63,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] (verbose)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -78,7 +78,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] --watch",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "--watch", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -93,7 +93,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] --hot",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "--hot", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -108,7 +108,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] --inspect",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -129,7 +129,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [file] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -151,7 +151,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -165,7 +165,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] (fast)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -179,7 +179,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] (verbose)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -193,7 +193,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] --watch",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "--watch", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -207,7 +207,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] --hot",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "--hot", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -221,7 +221,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] --inspect",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -241,7 +241,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"env": {
@@ -262,7 +262,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -277,7 +277,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] (fast)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -292,7 +292,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] (verbose)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -307,7 +307,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] --watch",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "--watch", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -322,7 +322,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] --hot",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "--hot", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -337,7 +337,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] --inspect",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -358,7 +358,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [...] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -380,7 +380,7 @@
"type": "lldb",
"request": "launch",
"name": "bun exec [...]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["exec", "${input:testName}"],
"cwd": "${workspaceFolder}",
"env": {
@@ -395,7 +395,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [*]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -409,7 +409,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [*] (fast)",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -423,7 +423,7 @@
"type": "lldb",
"request": "launch",
"name": "bun test [*] --inspect",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"env": {
@@ -443,7 +443,7 @@
"type": "lldb",
"request": "launch",
"name": "bun install [folder]",
"program": "${workspaceFolder}/build/bun-debug",
"program": "${workspaceFolder}/build/debug/bun-debug",
"args": ["install"],
"cwd": "${fileDirname}",
"env": {
@@ -475,7 +475,7 @@
},
"request": "launch",
"name": "Windows: bun test [file]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -504,7 +504,7 @@
},
"request": "launch",
"name": "Windows: bun test --only [file]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "--only", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -533,7 +533,7 @@
},
"request": "launch",
"name": "Windows: bun test [file] (fast)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -562,7 +562,7 @@
},
"request": "launch",
"name": "Windows: bun test [file] (verbose)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -591,7 +591,7 @@
},
"request": "launch",
"name": "Windows: bun test [file] --inspect",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -629,7 +629,7 @@
},
"request": "launch",
"name": "Windows: bun test [file] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${file}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -668,7 +668,7 @@
},
"request": "launch",
"name": "Windows: bun run [file]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"environment": [
@@ -697,7 +697,7 @@
},
"request": "launch",
"name": "Windows: bun install",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["install"],
"cwd": "${fileDirname}",
"environment": [
@@ -722,7 +722,7 @@
},
"request": "launch",
"name": "Windows: bun run [file] (verbose)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"environment": [
@@ -747,7 +747,7 @@
},
"request": "launch",
"name": "Windows: bun run [file] --inspect",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"environment": [
@@ -781,7 +781,7 @@
},
"request": "launch",
"name": "Windows: bun run [file] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["run", "${fileBasename}"],
"cwd": "${fileDirname}",
"environment": [
@@ -816,7 +816,7 @@
},
"request": "launch",
"name": "Windows: bun test [...]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -845,7 +845,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] (fast)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -874,7 +874,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] (verbose)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -903,7 +903,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] --watch",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "--watch", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -932,7 +932,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] --hot",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "--hot", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -961,7 +961,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] --inspect",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -999,7 +999,7 @@
},
"request": "launch",
"name": "Windows: bun test [...] --inspect-brk",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test", "${input:testName}"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -1038,7 +1038,7 @@
},
"request": "launch",
"name": "Windows: bun exec [...]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["exec", "${input:testName}"],
"cwd": "${workspaceFolder}",
"environment": [
@@ -1064,7 +1064,7 @@
},
"request": "launch",
"name": "Windows: bun test [*]",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -1089,7 +1089,7 @@
},
"request": "launch",
"name": "Windows: bun test [*] (fast)",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"environment": [
@@ -1118,7 +1118,7 @@
},
"request": "launch",
"name": "Windows: bun test [*] --inspect",
"program": "${workspaceFolder}/build/bun-debug.exe",
"program": "${workspaceFolder}/build/debug/bun-debug.exe",
"args": ["test"],
"cwd": "${workspaceFolder}/test",
"environment": [

View File

@@ -12,8 +12,7 @@
"search.exclude": {
"node_modules": true,
".git": true,
"src/bun.js/WebKit": true,
"src/deps/*/**": true,
"vendor/*/**": true,
"test/node.js/upstream": true,
// This will fill up your whole search history.
"test/js/node/test/fixtures": true,
@@ -30,13 +29,13 @@
// Zig
"zig.initialSetupDone": true,
"zig.buildOption": "build",
"zig.zls.zigLibPath": "${workspaceFolder}/src/deps/zig/lib",
"zig.buildArgs": ["-Dgenerated-code=./build/codegen"],
"zig.zls.zigLibPath": "${workspaceFolder}/vendor/zig/lib",
"zig.buildArgs": ["-Dgenerated-code=./build/debug/codegen"],
"zig.zls.buildOnSaveStep": "check",
// "zig.zls.enableBuildOnSave": true,
// "zig.buildOnSave": true,
"zig.buildFilePath": "${workspaceFolder}/build.zig",
"zig.path": "${workspaceFolder}/.cache/zig/zig.exe",
"zig.path": "${workspaceFolder}/vendor/zig/zig.exe",
"zig.formattingProvider": "zls",
"zig.zls.enableInlayHints": false,
"[zig]": {

52
.vscode/tasks.json vendored
View File

@@ -1,52 +0,0 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "process",
"label": "Install Dependencies",
"command": "scripts/all-dependencies.sh",
"windows": {
"command": "scripts/all-dependencies.ps1",
},
"icon": {
"id": "arrow-down",
},
"options": {
"cwd": "${workspaceFolder}",
},
},
{
"type": "process",
"label": "Setup Environment",
"dependsOn": ["Install Dependencies"],
"command": "scripts/setup.sh",
"windows": {
"command": "scripts/setup.ps1",
},
"icon": {
"id": "check",
},
"options": {
"cwd": "${workspaceFolder}",
},
},
{
"type": "process",
"label": "Build Bun",
"dependsOn": ["Setup Environment"],
"command": "bun",
"args": ["run", "build"],
"icon": {
"id": "gear",
},
"options": {
"cwd": "${workspaceFolder}",
},
"isBuildCommand": true,
"runOptions": {
"instanceLimit": 1,
"reevaluateOnRerun": true,
},
},
],
}

File diff suppressed because it is too large Load Diff

View File

@@ -163,8 +163,8 @@ Several code generation scripts are used during Bun's build process. These are r
In particular, these are:
- `./src/codegen/generate-jssink.ts` -- Generates `build/codegen/JSSink.cpp`, `build/codegen/JSSink.h` which implement various classes for interfacing with `ReadableStream`. This is internally how `FileSink`, `ArrayBufferSink`, `"type": "direct"` streams and other code related to streams works.
- `./src/codegen/generate-classes.ts` -- Generates `build/codegen/ZigGeneratedClasses*`, which generates Zig & C++ bindings for JavaScriptCore classes implemented in Zig. In `**/*.classes.ts` files, we define the interfaces for various classes, methods, prototypes, getters/setters etc which the code generator reads to generate boilerplate code implementing the JavaScript objects in C++ and wiring them up to Zig
- `./src/codegen/generate-jssink.ts` -- Generates `build/debug/codegen/JSSink.cpp`, `build/debug/codegen/JSSink.h` which implement various classes for interfacing with `ReadableStream`. This is internally how `FileSink`, `ArrayBufferSink`, `"type": "direct"` streams and other code related to streams works.
- `./src/codegen/generate-classes.ts` -- Generates `build/debug/codegen/ZigGeneratedClasses*`, which generates Zig & C++ bindings for JavaScriptCore classes implemented in Zig. In `**/*.classes.ts` files, we define the interfaces for various classes, methods, prototypes, getters/setters etc which the code generator reads to generate boilerplate code implementing the JavaScript objects in C++ and wiring them up to Zig
- `./src/codegen/bundle-modules.ts` -- Bundles built-in modules like `node:fs`, `bun:ffi` into files we can include in the final binary. In development, these can be reloaded without rebuilding Zig (you still need to run `bun run build`, but it re-reads the transpiled files from disk afterwards). In release builds, these are embedded into the binary.
- `./src/codegen/bundle-functions.ts` -- Bundles globally-accessible functions implemented in JavaScript/TypeScript like `ReadableStream`, `WritableStream`, and a handful more. These are used similarly to the builtin modules, but the output more closely aligns with what WebKit/Safari does for Safari's built-in functions so that we can copy-paste the implementations from WebKit as a starting point.

View File

@@ -1,645 +0,0 @@
# This Dockerfile is used by CI workflows to build Bun. It is not intended as a development
# environment, or to be used as a base image for other projects.
#
# You likely want this image instead: https://hub.docker.com/r/oven/bun
#
# TODO: move this file to reduce confusion
ARG DEBIAN_FRONTEND=noninteractive
ARG GITHUB_WORKSPACE=/build
ARG WEBKIT_DIR=${GITHUB_WORKSPACE}/bun-webkit
ARG BUN_RELEASE_DIR=${GITHUB_WORKSPACE}/bun-release
ARG BUN_DEPS_OUT_DIR=${GITHUB_WORKSPACE}/bun-deps
ARG BUN_DIR=${GITHUB_WORKSPACE}/bun
ARG CPU_TARGET=native
ARG ARCH=x86_64
ARG BUILD_MACHINE_ARCH=x86_64
ARG BUILDARCH=amd64
ARG TRIPLET=${ARCH}-linux-gnu
ARG GIT_SHA=""
ARG BUN_VERSION="bun-v1.1.4"
ARG BUN_DOWNLOAD_URL_BASE="https://pub-5e11e972747a44bf9aaf9394f185a982.r2.dev/releases/${BUN_VERSION}"
ARG CANARY=0
ARG ASSERTIONS=OFF
ARG ZIG_OPTIMIZE=ReleaseFast
ARG CMAKE_BUILD_TYPE=Release
ARG NODE_VERSION="20"
ARG LLVM_VERSION="16"
ARG ZIG_VERSION="0.13.0"
ARG ZIG_VERSION_SHORT="0.13.0"
ARG SCCACHE_BUCKET
ARG SCCACHE_REGION
ARG SCCACHE_S3_USE_SSL
ARG SCCACHE_ENDPOINT
ARG AWS_ACCESS_KEY_ID
ARG AWS_SECRET_ACCESS_KEY
FROM bitnami/minideb:bullseye as bun-base
ARG BUN_DOWNLOAD_URL_BASE
ARG DEBIAN_FRONTEND
ARG BUN_VERSION
ARG NODE_VERSION
ARG LLVM_VERSION
ARG BUILD_MACHINE_ARCH
ARG BUN_DIR
ARG BUN_DEPS_OUT_DIR
ARG CPU_TARGET
ENV CI 1
ENV CPU_TARGET=${CPU_TARGET}
ENV BUILDARCH=${BUILDARCH}
ENV BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR}
ENV USE_LTO 1
ENV LC_CTYPE=en_US.UTF-8
ENV LC_ALL=en_US.UTF-8
ENV SCCACHE_BUCKET=${SCCACHE_BUCKET}
ENV SCCACHE_REGION=${SCCACHE_REGION}
ENV SCCACHE_S3_USE_SSL=${SCCACHE_S3_USE_SSL}
ENV SCCACHE_ENDPOINT=${SCCACHE_ENDPOINT}
ENV AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
ENV AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
RUN install_packages \
ca-certificates \
curl \
gnupg \
&& echo "deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-${LLVM_VERSION} main" > /etc/apt/sources.list.d/llvm.list \
&& echo "deb-src https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-${LLVM_VERSION} main" >> /etc/apt/sources.list.d/llvm.list \
&& curl -fsSL "https://apt.llvm.org/llvm-snapshot.gpg.key" | apt-key add - \
&& echo "deb https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& curl -fsSL "https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key" | apt-key add - \
&& echo "deb https://apt.kitware.com/ubuntu/ focal main" > /etc/apt/sources.list.d/kitware.list \
&& curl -fsSL "https://apt.kitware.com/keys/kitware-archive-latest.asc" | apt-key add - \
&& install_packages \
wget \
bash \
software-properties-common \
build-essential \
autoconf \
automake \
libtool \
pkg-config \
clang-${LLVM_VERSION} \
lld-${LLVM_VERSION} \
lldb-${LLVM_VERSION} \
clangd-${LLVM_VERSION} \
libc++-${LLVM_VERSION}-dev \
libc++abi-${LLVM_VERSION}-dev \
llvm-${LLVM_VERSION}-runtime \
llvm-${LLVM_VERSION}-dev \
make \
cmake \
ninja-build \
file \
libc-dev \
libxml2 \
libxml2-dev \
xz-utils \
git \
tar \
rsync \
gzip \
unzip \
perl \
python3 \
ruby \
ruby-dev \
golang \
nodejs && \
for f in /usr/lib/llvm-${LLVM_VERSION}/bin/*; do ln -sf "$f" /usr/bin; done \
&& ln -sf /usr/bin/clang-${LLVM_VERSION} /usr/bin/clang \
&& ln -sf /usr/bin/clang++-${LLVM_VERSION} /usr/bin/clang++ \
&& ln -sf /usr/bin/lld-${LLVM_VERSION} /usr/bin/lld \
&& ln -sf /usr/bin/lldb-${LLVM_VERSION} /usr/bin/lldb \
&& ln -sf /usr/bin/clangd-${LLVM_VERSION} /usr/bin/clangd \
&& ln -sf /usr/bin/llvm-ar-${LLVM_VERSION} /usr/bin/llvm-ar \
&& ln -sf /usr/bin/ld.lld /usr/bin/ld \
&& ln -sf /usr/bin/llvm-ranlib-${LLVM_VERSION} /usr/bin/ranlib \
&& ln -sf /usr/bin/clang /usr/bin/cc \
&& ln -sf /usr/bin/clang /usr/bin/c89 \
&& ln -sf /usr/bin/clang /usr/bin/c99 \
&& ln -sf /usr/bin/clang++ /usr/bin/c++ \
&& ln -sf /usr/bin/clang++ /usr/bin/g++ \
&& ln -sf /usr/bin/llvm-ar /usr/bin/ar \
&& ln -sf /usr/bin/clang /usr/bin/gcc \
&& arch="$(dpkg --print-architecture)" \
&& case "${arch##*-}" in \
amd64) variant="x64";; \
arm64) variant="aarch64";; \
*) echo "unsupported architecture: $arch"; exit 1 ;; \
esac \
&& wget "${BUN_DOWNLOAD_URL_BASE}/bun-linux-${variant}.zip" \
&& unzip bun-linux-${variant}.zip \
&& mv bun-linux-${variant}/bun /usr/bin/bun \
&& ln -s /usr/bin/bun /usr/bin/bunx \
&& rm -rf bun-linux-${variant} bun-linux-${variant}.zip \
&& mkdir -p ${BUN_DIR} ${BUN_DEPS_OUT_DIR}
# && if [ -n "${SCCACHE_BUCKET}" ]; then \
# echo "Setting up sccache" \
# && wget https://github.com/mozilla/sccache/releases/download/v0.5.4/sccache-v0.5.4-${BUILD_MACHINE_ARCH}-unknown-linux-musl.tar.gz \
# && tar xf sccache-v0.5.4-${BUILD_MACHINE_ARCH}-unknown-linux-musl.tar.gz \
# && mv sccache-v0.5.4-${BUILD_MACHINE_ARCH}-unknown-linux-musl/sccache /usr/bin/sccache \
# && rm -rf sccache-v0.5.4-${BUILD_MACHINE_ARCH}-unknown-linux-musl.tar.gz sccache-v0.5.4-${BUILD_MACHINE_ARCH}-unknown-linux-musl \
FROM bun-base as bun-base-with-zig
ARG ZIG_VERSION
ARG ZIG_VERSION_SHORT
ARG BUILD_MACHINE_ARCH
ARG ZIG_FOLDERNAME=zig-linux-${BUILD_MACHINE_ARCH}-${ZIG_VERSION}
ARG ZIG_FILENAME=${ZIG_FOLDERNAME}.tar.xz
ARG ZIG_URL="https://ziglang.org/builds/${ZIG_FILENAME}"
ARG ZIG_LOCAL_CACHE_DIR=/zig-cache
ENV ZIG_LOCAL_CACHE_DIR=${ZIG_LOCAL_CACHE_DIR}
WORKDIR $GITHUB_WORKSPACE
ADD $ZIG_URL .
RUN tar xf ${ZIG_FILENAME} \
&& mv ${ZIG_FOLDERNAME}/lib /usr/lib/zig \
&& mv ${ZIG_FOLDERNAME}/zig /usr/bin/zig \
&& rm -rf ${ZIG_FILENAME} ${ZIG_FOLDERNAME}
FROM bun-base as c-ares
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/c-ares ${BUN_DIR}/src/deps/c-ares
COPY scripts ${BUN_DIR}/scripts
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-cares.sh \
&& rm -rf ${BUN_DIR}/src/deps/c-ares ${BUN_DIR}/Makefile ${BUN_DIR}/scripts
FROM bun-base as lolhtml
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/lol-html ${BUN_DIR}/src/deps/lol-html
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN --mount=type=cache,target=${CCACHE_DIR} \
export PATH=$PATH:$HOME/.cargo/bin \
&& cd ${BUN_DIR} \
&& make lolhtml \
&& rm -rf src/deps/lol-html Makefile
FROM bun-base as mimalloc
ARG BUN_DIR
ARG CPU_TARGET
ARG ASSERTIONS
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/mimalloc ${BUN_DIR}/src/deps/mimalloc
COPY scripts ${BUN_DIR}/scripts
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd ${BUN_DIR} \
&& bash ./scripts/build-mimalloc.sh \
&& rm -rf src/deps/mimalloc Makefile
FROM bun-base as mimalloc-debug
ARG BUN_DIR
ARG CPU_TARGET
ARG ASSERTIONS
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/mimalloc ${BUN_DIR}/src/deps/mimalloc
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd ${BUN_DIR} \
&& make mimalloc-debug \
&& rm -rf src/deps/mimalloc Makefile
FROM bun-base as zlib
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY Makefile ${BUN_DIR}/Makefile
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
COPY scripts ${BUN_DIR}/scripts
COPY src/deps/zlib ${BUN_DIR}/src/deps/zlib
COPY package.json bun.lockb Makefile .gitmodules ${BUN_DIR}/
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-zlib.sh && rm -rf src/deps/zlib scripts
FROM bun-base as libdeflate
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY Makefile ${BUN_DIR}/Makefile
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
COPY scripts ${BUN_DIR}/scripts
COPY src/deps/libdeflate ${BUN_DIR}/src/deps/libdeflate
COPY package.json bun.lockb Makefile .gitmodules ${BUN_DIR}/
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-libdeflate.sh && rm -rf src/deps/libdeflate scripts
FROM bun-base as libarchive
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN install_packages autoconf automake libtool pkg-config
COPY scripts ${BUN_DIR}/scripts
COPY src/deps/libarchive ${BUN_DIR}/src/deps/libarchive
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-libarchive.sh && rm -rf src/deps/libarchive .scripts
FROM bun-base as tinycc
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
RUN install_packages libtcc-dev && cp /usr/lib/$(uname -m)-linux-gnu/libtcc.a ${BUN_DEPS_OUT_DIR}
FROM bun-base as boringssl
RUN install_packages golang
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY scripts ${BUN_DIR}/scripts
COPY src/deps/boringssl ${BUN_DIR}/src/deps/boringssl
WORKDIR $BUN_DIR
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd ${BUN_DIR} \
&& bash ./scripts/build-boringssl.sh \
&& rm -rf src/deps/boringssl Makefile
FROM bun-base as zstd
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/zstd ${BUN_DIR}/src/deps/zstd
COPY scripts ${BUN_DIR}/scripts
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-zstd.sh \
&& rm -rf src/deps/zstd scripts
FROM bun-base as ls-hpack
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/ls-hpack ${BUN_DIR}/src/deps/ls-hpack
COPY scripts ${BUN_DIR}/scripts
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
cd $BUN_DIR \
&& bash ./scripts/build-lshpack.sh \
&& rm -rf src/deps/ls-hpack scripts
FROM bun-base-with-zig as bun-identifier-cache
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG CPU_TARGET
ARG BUN_DIR
ENV CPU_TARGET=${CPU_TARGET}
WORKDIR $BUN_DIR
COPY src/js_lexer/identifier_data.zig ${BUN_DIR}/src/js_lexer/identifier_data.zig
COPY src/js_lexer/identifier_cache.zig ${BUN_DIR}/src/js_lexer/identifier_cache.zig
RUN --mount=type=cache,target=${ZIG_LOCAL_CACHE_DIR} \
cd $BUN_DIR \
&& zig run src/js_lexer/identifier_data.zig
FROM bun-base as bun-node-fallbacks
ARG BUN_DIR
WORKDIR $BUN_DIR
COPY src/node-fallbacks ${BUN_DIR}/src/node-fallbacks
RUN cd $BUN_DIR/src/node-fallbacks \
&& bun install --frozen-lockfile \
&& bun run build \
&& rm -rf src/node-fallbacks/node_modules
FROM bun-base as bun-webkit
ARG BUILDARCH
ARG ASSERTIONS
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
RUN mkdir ${BUN_DIR}/bun-webkit \
&& WEBKIT_TAG=$(grep 'set(WEBKIT_TAG' "${BUN_DIR}/CMakeLists.txt" | awk '{print $2}' | cut -f 1 -d ')') \
&& WEBKIT_SUFFIX=$(if [ "${ASSERTIONS}" = "ON" ]; then echo "debug"; else echo "lto"; fi) \
&& WEBKIT_URL="https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_TAG}/bun-webkit-linux-${BUILDARCH}-${WEBKIT_SUFFIX}.tar.gz" \
&& echo "Downloading ${WEBKIT_URL}" \
&& curl -fsSL "${WEBKIT_URL}" | tar -xz -C ${BUN_DIR}/bun-webkit --strip-components=1
FROM bun-base as bun-cpp-objects
ARG CANARY
ARG ASSERTIONS
COPY --from=bun-webkit ${BUN_DIR}/bun-webkit ${BUN_DIR}/bun-webkit
COPY packages ${BUN_DIR}/packages
COPY src ${BUN_DIR}/src
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
COPY src/deps/boringssl/include ${BUN_DIR}/src/deps/boringssl/include
# for uWebSockets
COPY src/deps/libdeflate ${BUN_DIR}/src/deps/libdeflate
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
RUN --mount=type=cache,target=${CCACHE_DIR} mkdir ${BUN_DIR}/build \
&& cd ${BUN_DIR}/build \
&& mkdir -p tmp_modules tmp_functions js codegen \
&& cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DUSE_LTO=ON -DUSE_DEBUG_JSC=${ASSERTIONS} -DBUN_CPP_ONLY=1 -DWEBKIT_DIR=/build/bun/bun-webkit -DCANARY=${CANARY} -DZIG_COMPILER=system \
&& bash compile-cpp-only.sh -v
FROM bun-base-with-zig as bun-codegen-for-zig
COPY package.json bun.lockb Makefile .gitmodules ${BUN_DIR}/
COPY src/runtime ${BUN_DIR}/src/runtime
COPY src/runtime.js src/runtime.bun.js ${BUN_DIR}/src/
COPY packages/bun-error ${BUN_DIR}/packages/bun-error
COPY packages/bun-types ${BUN_DIR}/packages/bun-types
COPY src/fallback.ts ${BUN_DIR}/src/fallback.ts
COPY src/api ${BUN_DIR}/src/api
WORKDIR $BUN_DIR
# TODO: move away from Makefile entirely
RUN --mount=type=cache,target=${ZIG_LOCAL_CACHE_DIR} \
bun install --frozen-lockfile \
&& make runtime_js fallback_decoder bun_error \
&& rm -rf src/runtime src/fallback.ts node_modules bun.lockb package.json Makefile
FROM bun-base-with-zig as bun-compile-zig-obj
ARG ZIG_PATH
ARG TRIPLET
ARG GIT_SHA
ARG CPU_TARGET
ARG CANARY=0
ARG ASSERTIONS=OFF
ARG ZIG_OPTIMIZE=ReleaseFast
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
COPY *.zig package.json CMakeLists.txt ${BUN_DIR}/
COPY completions ${BUN_DIR}/completions
COPY packages ${BUN_DIR}/packages
COPY src ${BUN_DIR}/src
COPY --from=bun-identifier-cache ${BUN_DIR}/src/js_lexer/*.blob ${BUN_DIR}/src/js_lexer/
COPY --from=bun-node-fallbacks ${BUN_DIR}/src/node-fallbacks/out ${BUN_DIR}/src/node-fallbacks/out
COPY --from=bun-codegen-for-zig ${BUN_DIR}/src/*.out.js ${BUN_DIR}/src/*.out.refresh.js ${BUN_DIR}/src/
COPY --from=bun-codegen-for-zig ${BUN_DIR}/packages/bun-error/dist ${BUN_DIR}/packages/bun-error/dist
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=${CCACHE_DIR} \
--mount=type=cache,target=${ZIG_LOCAL_CACHE_DIR} \
mkdir -p build \
&& bun run $BUN_DIR/src/codegen/bundle-modules.ts --debug=OFF $BUN_DIR/build \
&& cd build \
&& cmake .. \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DUSE_LTO=ON \
-DZIG_OPTIMIZE="${ZIG_OPTIMIZE}" \
-DCPU_TARGET="${CPU_TARGET}" \
-DZIG_TARGET="${TRIPLET}" \
-DWEBKIT_DIR="omit" \
-DNO_CONFIGURE_DEPENDS=1 \
-DNO_CODEGEN=1 \
-DBUN_ZIG_OBJ_DIR="/tmp" \
-DCANARY="${CANARY}" \
-DZIG_COMPILER=system \
-DZIG_LIB_DIR=$BUN_DIR/src/deps/zig/lib \
&& ONLY_ZIG=1 ninja "/tmp/bun-zig.o" -v
FROM scratch as build_release_obj
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY --from=bun-compile-zig-obj /tmp/bun-zig.o /
FROM bun-base as bun-link
ARG CPU_TARGET
ARG CANARY
ARG ASSERTIONS
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
ARG ZIG_LOCAL_CACHE_DIR=/zig-cache
ENV ZIG_LOCAL_CACHE_DIR=${ZIG_LOCAL_CACHE_DIR}
WORKDIR $BUN_DIR
RUN mkdir -p build bun-webkit
# lol
COPY src/bun.js/bindings/sqlite/sqlite3.c ${BUN_DIR}/src/bun.js/bindings/sqlite/sqlite3.c
COPY src/deps/brotli ${BUN_DIR}/src/deps/brotli
COPY src/symbols.dyn src/linker.lds ${BUN_DIR}/src/
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
COPY --from=zlib ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=libdeflate ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=libarchive ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=boringssl ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=lolhtml ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=mimalloc ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=zstd ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=tinycc ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=c-ares ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=ls-hpack ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=bun-compile-zig-obj /tmp/bun-zig.o ${BUN_DIR}/build/bun-zig.o
COPY --from=bun-cpp-objects ${BUN_DIR}/build/*.a ${BUN_DIR}/build/
COPY --from=bun-cpp-objects ${BUN_DIR}/build/*.o ${BUN_DIR}/build/
COPY --from=bun-cpp-objects ${BUN_DIR}/bun-webkit/lib ${BUN_DIR}/bun-webkit/lib
WORKDIR $BUN_DIR/build
RUN --mount=type=cache,target=${CCACHE_DIR} \
--mount=type=cache,target=${ZIG_LOCAL_CACHE_DIR} \
cmake .. \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUN_LINK_ONLY=1 \
-DBUN_ZIG_OBJ_DIR="${BUN_DIR}/build" \
-DUSE_LTO=ON \
-DUSE_DEBUG_JSC=${ASSERTIONS} \
-DBUN_CPP_ARCHIVE="${BUN_DIR}/build/bun-cpp-objects.a" \
-DWEBKIT_DIR="${BUN_DIR}/bun-webkit" \
-DBUN_DEPS_OUT_DIR="${BUN_DEPS_OUT_DIR}" \
-DCPU_TARGET="${CPU_TARGET}" \
-DNO_CONFIGURE_DEPENDS=1 \
-DCANARY="${CANARY}" \
-DZIG_COMPILER=system \
&& ninja -v \
&& ./bun --revision \
&& mkdir -p /build/out \
&& mv bun bun-profile /build/out \
&& rm -rf ${BUN_DIR} ${BUN_DEPS_OUT_DIR}
FROM scratch as artifact
COPY --from=bun-link /build/out /
FROM bun-base as bun-link-assertions
ARG CPU_TARGET
ARG CANARY
ARG ASSERTIONS
ENV CPU_TARGET=${CPU_TARGET}
ARG CCACHE_DIR=/ccache
ENV CCACHE_DIR=${CCACHE_DIR}
ARG ZIG_LOCAL_CACHE_DIR=/zig-cache
ENV ZIG_LOCAL_CACHE_DIR=${ZIG_LOCAL_CACHE_DIR}
WORKDIR $BUN_DIR
RUN mkdir -p build bun-webkit
# lol
COPY src/bun.js/bindings/sqlite/sqlite3.c ${BUN_DIR}/src/bun.js/bindings/sqlite/sqlite3.c
COPY src/symbols.dyn src/linker.lds ${BUN_DIR}/src/
COPY CMakeLists.txt ${BUN_DIR}/CMakeLists.txt
COPY --from=zlib ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=libarchive ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=boringssl ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=lolhtml ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=mimalloc-debug ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=zstd ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=tinycc ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=c-ares ${BUN_DEPS_OUT_DIR}/* ${BUN_DEPS_OUT_DIR}/
COPY --from=bun-compile-zig-obj /tmp/bun-zig.o ${BUN_DIR}/build/bun-zig.o
COPY --from=bun-cpp-objects ${BUN_DIR}/build/bun-cpp-objects.a ${BUN_DIR}/build/bun-cpp-objects.a
COPY --from=bun-cpp-objects ${BUN_DIR}/bun-webkit/lib ${BUN_DIR}/bun-webkit/lib
WORKDIR $BUN_DIR/build
RUN --mount=type=cache,target=${CCACHE_DIR} \
--mount=type=cache,target=${ZIG_LOCAL_CACHE_DIR} \
cmake .. \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DBUN_LINK_ONLY=1 \
-DBUN_ZIG_OBJ_DIR="${BUN_DIR}/build" \
-DUSE_DEBUG_JSC=ON \
-DBUN_CPP_ARCHIVE="${BUN_DIR}/build/bun-cpp-objects.a" \
-DWEBKIT_DIR="${BUN_DIR}/bun-webkit" \
-DBUN_DEPS_OUT_DIR="${BUN_DEPS_OUT_DIR}" \
-DCPU_TARGET="${CPU_TARGET}" \
-DNO_CONFIGURE_DEPENDS=1 \
-DCANARY="${CANARY}" \
-DZIG_COMPILER=system \
-DUSE_LTO=ON \
&& ninja -v \
&& ./bun --revision \
&& mkdir -p /build/out \
&& mv bun bun-profile /build/out \
&& rm -rf ${BUN_DIR} ${BUN_DEPS_OUT_DIR}
FROM scratch as artifact-assertions
COPY --from=bun-link-assertions /build/out /

2
LATEST
View File

@@ -1 +1 @@
1.1.26
1.1.27

View File

@@ -1,3 +1,10 @@
# ------------------------------------------------------------
# WARNING
# ------------------------------------------------------------
# This file is very old and will be removed soon!
# You can build Bun using `cmake` or `bun run build`
# ------------------------------------------------------------
SHELL := $(shell which bash) # Use bash syntax to be consistent
OS_NAME := $(shell uname -s | tr '[:upper:]' '[:lower:]')
@@ -928,7 +935,7 @@ bun-codesign-release-local-debug:
.PHONY: jsc
jsc: jsc-build jsc-copy-headers jsc-bindings
.PHONY: jsc-debug
jsc-debug: jsc-build-debug jsc-copy-headers-debug
jsc-debug: jsc-build-debug
.PHONY: jsc-build
jsc-build: $(JSC_BUILD_STEPS)
.PHONY: jsc-build-debug
@@ -1389,10 +1396,10 @@ jsc-build-linux-compile-build-debug:
jsc-build-mac: jsc-force-fastjit jsc-build-mac-compile jsc-build-copy
jsc-build-mac-debug: jsc-force-fastjit jsc-build-mac-compile-debug jsc-build-copy-debug
jsc-build-mac-debug: jsc-force-fastjit jsc-build-mac-compile-debug
jsc-build-linux: jsc-build-linux-compile-config jsc-build-linux-compile-build jsc-build-copy
jsc-build-linux-debug: jsc-build-linux-compile-config-debug jsc-build-linux-compile-build-debug jsc-build-copy-debug
jsc-build-linux-debug: jsc-build-linux-compile-config-debug jsc-build-linux-compile-build-debug
jsc-build-copy:
cp $(WEBKIT_RELEASE_DIR)/lib/libJavaScriptCore.a $(BUN_DEPS_OUT_DIR)/libJavaScriptCore.a

View File

@@ -0,0 +1,24 @@
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(214));
bench("RSA_PKCS1_OAEP_PADDING round-trip", () => {
const ciphertext = crypto.publicEncrypt(keyPair.publicKey, plaintext);
crypto.privateDecrypt(keyPair.privateKey, ciphertext);
});
await run();

View File

@@ -0,0 +1,22 @@
import { bench, run } from "mitata";
import { posix } from "path";
const pathConfigurations = [
"",
".",
"./",
["", ""].join("|"),
["./abc.js"].join("|"),
["foo/bar", "/tmp/file/", "..", "a/../subfile"].join("|"),
["a/b/c/", "../../.."].join("|"),
];
pathConfigurations.forEach(paths => {
const args = paths.split("|");
bench(`resolve(${args.map(a => JSON.stringify(a)).join(", ")})`, () => {
globalThis.abc = posix.resolve(...args);
});
});
await run();

View File

@@ -0,0 +1,7 @@
import { bench, run } from "mitata";
bench("process.cwd()", () => {
process.cwd();
});
await run();

View File

@@ -44,10 +44,21 @@ const BunBuildOptions = struct {
version: Version,
canary_revision: ?u32,
sha: []const u8,
/// enable debug logs in release builds
enable_logs: bool = false,
tracy_callstack_depth: u16,
reported_nodejs_version: Version,
/// To make iterating on some '@embedFile's faster, we load them at runtime
/// 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/kit/runtime.ts (bundled)
/// - src/bun.js/api/FFI.h
///
/// A similar technique is used in C++ code for JavaScript builtins
force_embed_code: bool = false,
/// `./build/codegen` or equivalent
generated_code_dir: []const u8,
no_llvm: bool,
@@ -59,6 +70,10 @@ const BunBuildOptions = struct {
!Target.x86.featureSetHas(this.target.result.cpu.features, .avx2);
}
pub fn shouldEmbedCode(opts: *const BunBuildOptions) bool {
return opts.optimize != .Debug or opts.force_embed_code;
}
pub fn buildOptionsModule(this: *BunBuildOptions, b: *Build) *Module {
if (this.cached_options_module) |mod| {
return mod;
@@ -66,6 +81,12 @@ const BunBuildOptions = struct {
var opts = b.addOptions();
opts.addOption([]const u8, "base_path", b.pathFromRoot("."));
opts.addOption([]const u8, "codegen_path", std.fs.path.resolve(b.graph.arena, &.{
b.build_root.path.?,
this.generated_code_dir,
}) catch @panic("OOM"));
opts.addOption(bool, "embed_code", this.shouldEmbedCode());
opts.addOption(u32, "canary_revision", this.canary_revision orelse 0);
opts.addOption(bool, "is_canary", this.canary_revision != null);
opts.addOption(Version, "version", this.version);
@@ -132,7 +153,14 @@ pub fn getCpuModel(os: OperatingSystem, arch: Arch) ?Target.Query.CpuModel {
pub fn build(b: *Build) !void {
std.log.info("zig compiler v{s}", .{builtin.zig_version_string});
b.zig_lib_dir = b.zig_lib_dir orelse b.path("src/deps/zig/lib");
b.zig_lib_dir = b.zig_lib_dir orelse b.path("vendor/zig/lib");
// TODO: Upgrade path for 0.14.0
// b.graph.zig_lib_directory = brk: {
// 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}) };
// };
var target_query = b.standardTargetOptionsQueryOnly(.{});
const optimize = b.standardOptimizeOption(.{});
@@ -169,9 +197,10 @@ pub fn build(b: *Build) !void {
const generated_code_dir = b.pathFromRoot(
b.option([]const u8, "generated-code", "Set the generated code directory") orelse
"build/codegen",
"build/debug/codegen",
);
const bun_version = b.option([]const u8, "version", "Value of `Bun.version`") orelse "0.0.0";
const force_embed_js_code = b.option(bool, "force_embed_js_code", "Always embed JavaScript builtins") orelse false;
b.reference_trace = ref_trace: {
const trace = b.option(u32, "reference-trace", "Set the reference trace") orelse 16;
@@ -190,6 +219,7 @@ pub fn build(b: *Build) !void {
.arch = arch,
.generated_code_dir = generated_code_dir,
.force_embed_code = force_embed_js_code,
.no_llvm = no_llvm,
.version = try Version.parse(bun_version),
@@ -439,23 +469,22 @@ fn addInternalPackages(b: *Build, obj: *Compile, opts: *BunBuildOptions) void {
.root_source_file = b.path(async_path),
});
const zig_generated_classes_path = b.pathJoin(&.{ opts.generated_code_dir, "ZigGeneratedClasses.zig" });
validateGeneratedPath(zig_generated_classes_path);
obj.root_module.addAnonymousImport("ZigGeneratedClasses", .{
.root_source_file = .{ .cwd_relative = zig_generated_classes_path },
});
const resolved_source_tag_path = b.pathJoin(&.{ opts.generated_code_dir, "ResolvedSourceTag.zig" });
validateGeneratedPath(resolved_source_tag_path);
obj.root_module.addAnonymousImport("ResolvedSourceTag", .{
.root_source_file = .{ .cwd_relative = resolved_source_tag_path },
});
const error_code_path = b.pathJoin(&.{ opts.generated_code_dir, "ErrorCode.zig" });
validateGeneratedPath(error_code_path);
obj.root_module.addAnonymousImport("ErrorCode", .{
.root_source_file = .{ .cwd_relative = error_code_path },
});
// Generated code exposed as individual modules.
inline for (.{
.{ .file = "ZigGeneratedClasses.zig", .import = "ZigGeneratedClasses" },
.{ .file = "ResolvedSourceTag.zig", .import = "ResolvedSourceTag" },
.{ .file = "ErrorCode.zig", .import = "ErrorCode" },
.{ .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 });
validateGeneratedPath(path);
obj.root_module.addAnonymousImport(entry.import, .{
.root_source_file = .{ .cwd_relative = path },
});
}
}
if (os == .windows) {
obj.root_module.addAnonymousImport("bun_shim_impl.exe", .{

311
cmake/CompilerFlags.cmake Normal file
View File

@@ -0,0 +1,311 @@
# clang: https://clang.llvm.org/docs/CommandGuide/clang.html
# clang-cl: https://clang.llvm.org/docs/UsersManual.html#id11
macro(setb variable)
if(${variable})
set(${variable} ON)
else()
set(${variable} OFF)
endif()
endmacro()
set(bvariables WIN32 APPLE UNIX LINUX)
foreach(bvariable ${bvariables})
setb(${bvariable})
endforeach()
# --- CPU target ---
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 "amd64|AMD64|x86_64|X86_64|x64|X64")
if(ENABLE_BASELINE)
register_compiler_flags(-march=nehalem)
else()
register_compiler_flags(-march=haswell)
endif()
else()
unsupported(CMAKE_SYSTEM_PROCESSOR)
endif()
# --- MSVC runtime ---
if(WIN32)
register_compiler_flags(
DESCRIPTION "Use static MSVC runtime"
/MTd ${DEBUG}
/MT ${RELEASE}
/U_DLL
)
endif()
# --- Optimization level ---
if(DEBUG)
register_compiler_flags(
DESCRIPTION "Disable optimization"
/Od ${WIN32}
-O0 ${UNIX}
)
elseif(ENABLE_SMOL)
register_compiler_flags(
DESCRIPTION "Optimize for size"
/Os ${WIN32}
-Os ${UNIX}
)
else()
register_compiler_flags(
DESCRIPTION "Optimize for speed"
/O2 ${WIN32} # TODO: change to /0t (same as -O3) to match macOS and Linux?
-O3 ${UNIX}
)
endif()
# --- Debug level ---
if(WIN32)
register_compiler_flags(
DESCRIPTION "Enable debug symbols (.pdb)"
/Z7
)
elseif(APPLE)
register_compiler_flags(
DESCRIPTION "Enable debug symbols (.dSYM)"
-gdwarf-4
)
endif()
if(UNIX)
register_compiler_flags(
DESCRIPTION "Enable debug symbols"
-g3 ${DEBUG}
-g1 ${RELEASE}
)
register_compiler_flags(
DESCRIPTION "Optimize debug symbols for LLDB"
-glldb
)
endif()
# TODO: consider other debug options
# -fdebug-macro # Emit debug info for macros
# -fstandalone-debug # Emit debug info for non-system libraries
# -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}
/EHsc ${WIN32} # (s- disables C++, c- disables C)
)
register_compiler_flags(
LANGUAGE CXX
DESCRIPTION "Disable C++ static destructors"
-Xclang ${WIN32}
-fno-c++-static-destructors
)
register_compiler_flags(
DESCRIPTION "Disable runtime type information (RTTI)"
/GR- ${WIN32}
-fno-rtti ${UNIX}
)
register_compiler_flags(
DESCRIPTION "Keep frame pointers"
/Oy- ${WIN32}
-fno-omit-frame-pointer ${UNIX}
-mno-omit-leaf-frame-pointer ${UNIX}
)
if(UNIX)
register_compiler_flags(
DESCRIPTION "Set C/C++ visibility to hidden"
-fvisibility=hidden
-fvisibility-inlines-hidden
)
register_compiler_flags(
DESCRIPTION "Disable unwind tables"
-fno-unwind-tables
-fno-asynchronous-unwind-tables
)
endif()
register_compiler_flags(
DESCRIPTION "Place each function in its own section"
-ffunction-sections ${UNIX}
/Gy ${WIN32}
)
register_compiler_flags(
DESCRIPTION "Place each data item in its own section"
-fdata-sections ${UNIX}
/Gw ${WIN32}
)
# 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))
register_compiler_flags(
DESCRIPTION "Emit an address-significance table"
-faddrsig
)
endif()
if(WIN32)
register_compiler_flags(
DESCRIPTION "Enable string pooling"
/GF
)
register_compiler_flags(
DESCRIPTION "Assume thread-local variables are defined in the executable"
/GA
)
endif()
# --- Linker flags ---
if(LINUX)
register_linker_flags(
DESCRIPTION "Disable relocation read-only (RELRO)"
-Wl,-z,norelro
)
endif()
# --- Assertions ---
# 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"
-fno-delete-null-pointer-checks
)
register_compiler_definitions(
DESCRIPTION "Enable libc++ assertions"
_LIBCPP_ENABLE_ASSERTIONS=1
_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE ${RELEASE}
_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG ${DEBUG}
)
register_compiler_definitions(
DESCRIPTION "Enable fortified sources"
_FORTIFY_SOURCE=3
)
if(LINUX)
register_compiler_definitions(
DESCRIPTION "Enable glibc++ assertions"
_GLIBCXX_ASSERTIONS=1
)
endif()
else()
register_compiler_definitions(
DESCRIPTION "Disable debug assertions"
NDEBUG=1
)
register_compiler_definitions(
DESCRIPTION "Disable libc++ assertions"
_LIBCPP_ENABLE_ASSERTIONS=0
_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_NONE
)
if(LINUX)
register_compiler_definitions(
DESCRIPTION "Disable glibc++ assertions"
_GLIBCXX_ASSERTIONS=0
)
endif()
endif()
# --- Diagnostics ---
if(UNIX)
register_compiler_flags(
DESCRIPTION "Enable color diagnostics"
-fdiagnostics-color=always
)
endif()
register_compiler_flags(
DESCRIPTION "Set C/C++ error limit"
-ferror-limit=${ERROR_LIMIT}
)
# --- LTO ---
if(ENABLE_LTO)
register_compiler_flags(
DESCRIPTION "Enable link-time optimization (LTO)"
-flto=full ${UNIX}
-flto ${WIN32}
)
if(UNIX)
register_compiler_flags(
LANGUAGE CXX
DESCRIPTION "Enable virtual tables"
-fforce-emit-vtables
-fwhole-program-vtables
)
register_linker_flags(
DESCRIPTION "Enable link-time optimization (LTO)"
-flto=full
-fwhole-program-vtables
-fforce-emit-vtables
)
endif()
endif()
# --- Remapping ---
if(UNIX)
register_compiler_flags(
DESCRIPTION "Remap source files"
-ffile-prefix-map=${CWD}=.
-ffile-prefix-map=${VENDOR_PATH}=vendor
-ffile-prefix-map=${CACHE_PATH}=cache
)
endif()
# --- Features ---
# Valgrind cannot handle SSE4.2 instructions
# This is needed for picohttpparser
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.
# https://github.com/ninja-build/ninja/issues/2280
if(WIN32 AND NOT CMAKE_CL_SHOWINCLUDES_PREFIX)
set(CMAKE_CL_SHOWINCLUDES_PREFIX "Note: including file:")
endif()
# WebKit uses -std=gnu++20 on non-macOS non-Windows.
# If we do not set this, it will crash at startup on the first memory allocation.
if(NOT WIN32 AND NOT APPLE)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
endif()

1246
cmake/Globals.cmake Normal file

File diff suppressed because it is too large Load Diff

146
cmake/Options.cmake Normal file
View File

@@ -0,0 +1,146 @@
if(NOT CMAKE_SYSTEM_NAME OR NOT CMAKE_SYSTEM_PROCESSOR)
message(FATAL_ERROR "CMake included this file before project() was called")
endif()
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)
if(BUILDKITE)
optionx(BUILDKITE_COMMIT STRING "The commit hash")
optionx(BUILDKITE_MESSAGE STRING "The commit message")
endif()
optionx(CMAKE_BUILD_TYPE "Debug|Release|RelWithDebInfo|MinSizeRel" "The build type to use" REQUIRED)
if(CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo|MinSizeRel")
setx(RELEASE ON)
else()
setx(RELEASE OFF)
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo")
setx(DEBUG ON)
else()
setx(DEBUG OFF)
endif()
if(CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
setx(ENABLE_SMOL ON)
endif()
if(APPLE)
setx(OS "darwin")
elseif(WIN32)
setx(OS "windows")
elseif(LINUX)
setx(OS "linux")
else()
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}")
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm")
setx(ARCH "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|x64|AMD64")
setx(ARCH "x64")
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
if(ARCH STREQUAL "x64")
optionx(ENABLE_BASELINE BOOL "If baseline features should be used for older CPUs (e.g. disables AVX, AVX2)" DEFAULT OFF)
endif()
optionx(ENABLE_LOGS BOOL "If debug logs should be enabled" DEFAULT ${DEBUG})
optionx(ENABLE_ASSERTIONS BOOL "If debug assertions should be enabled" DEFAULT ${DEBUG})
if(BUILDKITE_MESSAGE AND BUILDKITE_MESSAGE MATCHES "\\[release build\\]")
message(STATUS "Switched to release build, since commit message contains: \"[release build]\"")
set(DEFAULT_CANARY OFF)
else()
set(DEFAULT_CANARY ON)
endif()
optionx(ENABLE_CANARY BOOL "If canary features should be enabled" DEFAULT ${DEFAULT_CANARY})
if(ENABLE_CANARY AND BUILDKITE)
execute_process(
COMMAND buildkite-agent meta-data get "canary"
OUTPUT_VARIABLE DEFAULT_CANARY_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
elseif(ENABLE_CANARY)
set(DEFAULT_CANARY_REVISION "1")
else()
set(DEFAULT_CANARY_REVISION "0")
endif()
optionx(CANARY_REVISION STRING "The canary revision of the build" DEFAULT ${DEFAULT_CANARY_REVISION})
if(RELEASE AND LINUX)
set(DEFAULT_LTO ON)
else()
set(DEFAULT_LTO OFF)
endif()
optionx(ENABLE_LTO BOOL "If LTO (link-time optimization) should be used" DEFAULT ${DEFAULT_LTO})
if(LINUX)
optionx(ENABLE_VALGRIND BOOL "If Valgrind support should be enabled" DEFAULT OFF)
endif()
if(USE_VALGRIND AND NOT USE_BASELINE)
message(WARNING "If valgrind is enabled, baseline must also be enabled")
setx(USE_BASELINE ON)
endif()
if(BUILDKITE_COMMIT)
set(DEFAULT_REVISION ${BUILDKITE_COMMIT})
else()
execute_process(
COMMAND git rev-parse HEAD
WORKING_DIRECTORY ${CWD}
OUTPUT_VARIABLE DEFAULT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(NOT DEFAULT_REVISION)
set(DEFAULT_REVISION "unknown")
endif()
endif()
optionx(REVISION STRING "The git revision of the build" DEFAULT ${DEFAULT_REVISION})
# Used in process.version, process.versions.node, napi, and elsewhere
optionx(NODEJS_VERSION STRING "The version of Node.js to report" DEFAULT "22.6.0")
# Used in process.versions.modules and compared while loading V8 modules
optionx(NODEJS_ABI_VERSION STRING "The ABI version of Node.js to report" DEFAULT "127")
if(APPLE)
set(DEFAULT_STATIC_SQLITE OFF)
else()
set(DEFAULT_STATIC_SQLITE ON)
endif()
optionx(USE_STATIC_SQLITE BOOL "If SQLite should be statically linked" DEFAULT ${DEFAULT_STATIC_SQLITE})
set(DEFAULT_STATIC_LIBATOMIC ON)
if(CMAKE_HOST_LINUX AND NOT WIN32 AND NOT APPLE)
execute_process(
COMMAND grep -w "NAME" /etc/os-release
OUTPUT_VARIABLE LINUX_DISTRO
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(LINUX_DISTRO MATCHES "NAME=\"(Arch|Manjaro|Artix) Linux\"|NAME=\"openSUSE Tumbleweed\"")
set(DEFAULT_STATIC_LIBATOMIC OFF)
endif()
endif()
optionx(USE_STATIC_LIBATOMIC BOOL "If libatomic should be statically linked" DEFAULT ${DEFAULT_STATIC_LIBATOMIC})
optionx(ERROR_LIMIT STRING "Maximum number of errors to show when compiling C++ code" DEFAULT "100")

11
cmake/Policies.cmake Normal file
View File

@@ -0,0 +1,11 @@
# Let the MSVC runtime be set using CMAKE_MSVC_RUNTIME_LIBRARY, instead of automatically.
# Since CMake 3.15.
cmake_policy(SET CMP0091 NEW)
# If INTERPROCEDURAL_OPTIMIZATION is enabled and not supported by the compiler, throw an error.
# Since CMake 3.9.
cmake_policy(SET CMP0069 NEW)
# Use CMAKE_{C,CXX}_STANDARD when evaluating try_compile().
# Since CMake 3.8.
cmake_policy(SET CMP0067 NEW)

View File

@@ -0,0 +1,35 @@
find_command(
VARIABLE
CLANG_FORMAT_PROGRAM
COMMAND
clang-format
REQUIRED
OFF
)
register_command(
TARGET
clang-format-check
COMMENT
"Running clang-format"
COMMAND
${CLANG_FORMAT_PROGRAM}
-Werror
--dry-run
--verbose
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
)
register_command(
TARGET
clang-format
COMMENT
"Fixing clang-format"
COMMAND
${CLANG_FORMAT_PROGRAM}
-i # edits files in-place
--verbose
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
)

View File

@@ -0,0 +1,79 @@
# 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})
find_command(
VARIABLE
GIT_PROGRAM
COMMAND
git
REQUIRED
OFF
)
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(
TARGET
clang-tidy
COMMENT
"Running clang-tidy"
COMMAND
${CLANG_TIDY_COMMAND}
CWD
${BUILD_PATH}
)

View File

@@ -0,0 +1,33 @@
# https://cppcheck.sourceforge.io/
find_command(
VARIABLE
CPPCHECK_EXECUTABLE
COMMAND
cppcheck
REQUIRED
OFF
)
set(CPPCHECK_COMMAND ${CPPCHECK_EXECUTABLE}
--cppcheck-build-dir=${BUILD_PATH}/cppcheck
--project=${BUILD_PATH}/compile_commands.json
--clang=${CMAKE_CXX_COMPILER}
--std=c++${CMAKE_CXX_STANDARD}
--report-progress
--showtime=summary
)
register_command(
TARGET
cppcheck
COMMENT
"Running cppcheck"
COMMAND
${CMAKE_COMMAND} -E make_directory cppcheck
&& ${CPPCHECK_COMMAND}
CWD
${BUILD_PATH}
TARGETS
${bun}
)

View File

@@ -0,0 +1,22 @@
find_command(
VARIABLE
CPPLINT_PROGRAM
COMMAND
cpplint
REQUIRED
OFF
)
register_command(
TARGET
cpplint
COMMENT
"Running cpplint"
COMMAND
${CPPLINT_PROGRAM}
${BUN_CPP_SOURCES}
CWD
${BUILD_PATH}
TARGETS
${bun}
)

View File

@@ -0,0 +1,67 @@
# IWYU = "Include What You Use"
# https://include-what-you-use.org/
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)
register_repository(
NAME
iwyu
REPOSITORY
include-what-you-use/include-what-you-use
BRANCH
clang_${LLVM_VERSION_MAJOR}
PATH
${IWYU_SOURCE_PATH}
)
register_command(
TARGET
build-iwyu
COMMENT
"Building iwyu"
COMMAND
${CMAKE_COMMAND}
-B${IWYU_BUILD_PATH}
-G${CMAKE_GENERATOR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}
-DIWYU_LLVM_ROOT_PATH=${LLVM_PREFIX}
&& ${CMAKE_COMMAND}
--build ${IWYU_BUILD_PATH}
CWD
${IWYU_SOURCE_PATH}
TARGETS
clone-iwyu
)
find_command(
VARIABLE
PYTHON_EXECUTABLE
COMMAND
python3
python
VERSION
>=3.0.0
REQUIRED
OFF
)
register_command(
TARGET
iwyu
COMMENT
"Running iwyu"
COMMAND
${CMAKE_COMMAND}
-E env IWYU_BINARY=${IWYU_PROGRAM}
${PYTHON_EXECUTABLE}
${IWYU_SOURCE_PATH}/iwyu_tool.py
-p ${BUILD_PATH}
CWD
${BUILD_PATH}
TARGETS
build-iwyu
${bun}
)

View File

@@ -0,0 +1,22 @@
register_command(
TARGET
zig-format-check
COMMENT
"Checking zig fmt"
COMMAND
${ZIG_EXECUTABLE}
fmt
--check
${BUN_ZIG_SOURCES}
)
register_command(
TARGET
zig-format
COMMENT
"Running zig fmt"
COMMAND
${ZIG_EXECUTABLE}
fmt
${BUN_ZIG_SOURCES}
)

View File

@@ -0,0 +1,131 @@
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
message(STATUS "Running script: ${SCRIPT_NAME}")
if(NOT DOWNLOAD_URL OR NOT DOWNLOAD_PATH)
message(FATAL_ERROR "DOWNLOAD_URL and DOWNLOAD_PATH are required")
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(TMP_PATH $ENV{TEMP})
else()
set(TMP_PATH $ENV{TMPDIR})
endif()
if(NOT TMP_PATH)
set(TMP_PATH ${CMAKE_BINARY_DIR}/tmp)
endif()
string(REGEX REPLACE "/+$" "" TMP_PATH ${TMP_PATH})
string(REGEX REPLACE "[^a-zA-Z0-9]" "-" DOWNLOAD_ID ${DOWNLOAD_URL})
string(RANDOM LENGTH 8 RANDOM_ID)
set(DOWNLOAD_TMP_PATH ${TMP_PATH}/${DOWNLOAD_ID}-${RANDOM_ID})
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_PATH}/tmp)
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
if(DOWNLOAD_ACCEPT_HEADER)
set(DOWNLOAD_ACCEPT_HEADER "Accept: ${DOWNLOAD_ACCEPT_HEADER}")
else()
set(DOWNLOAD_ACCEPT_HEADER "Accept: */*")
endif()
foreach(i RANGE 10)
set(DOWNLOAD_TMP_FILE_${i} ${DOWNLOAD_TMP_FILE}.${i})
if(i EQUAL 0)
message(STATUS "Downloading ${DOWNLOAD_URL}...")
else()
message(STATUS "Downloading ${DOWNLOAD_URL}... (retry ${i})")
endif()
file(DOWNLOAD
${DOWNLOAD_URL}
${DOWNLOAD_TMP_FILE_${i}}
HTTPHEADER "User-Agent: cmake/${CMAKE_VERSION}"
HTTPHEADER ${DOWNLOAD_ACCEPT_HEADER}
STATUS DOWNLOAD_STATUS
INACTIVITY_TIMEOUT 60
TIMEOUT 180
SHOW_PROGRESS
)
list(GET DOWNLOAD_STATUS 0 DOWNLOAD_STATUS_CODE)
if(DOWNLOAD_STATUS_CODE EQUAL 0)
if(NOT EXISTS ${DOWNLOAD_TMP_FILE_${i}})
message(WARNING "Download failed: result is ok, but file does not exist: ${DOWNLOAD_TMP_FILE_${i}}")
continue()
endif()
file(RENAME ${DOWNLOAD_TMP_FILE_${i}} ${DOWNLOAD_TMP_FILE})
break()
endif()
list(GET DOWNLOAD_STATUS 1 DOWNLOAD_STATUS_TEXT)
file(REMOVE ${DOWNLOAD_TMP_FILE_${i}})
message(WARNING "Download failed: ${DOWNLOAD_STATUS_CODE} ${DOWNLOAD_STATUS_TEXT}")
endforeach()
if(NOT EXISTS ${DOWNLOAD_TMP_FILE})
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
message(FATAL_ERROR "Download failed after too many attempts: ${DOWNLOAD_URL}")
endif()
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_URL} NAME)
if(DOWNLOAD_FILENAME MATCHES "\\.(zip|tar|gz|xz)$")
message(STATUS "Extracting ${DOWNLOAD_FILENAME}...")
set(DOWNLOAD_TMP_EXTRACT ${DOWNLOAD_TMP_PATH}/extract)
file(ARCHIVE_EXTRACT
INPUT ${DOWNLOAD_TMP_FILE}
DESTINATION ${DOWNLOAD_TMP_EXTRACT}
TOUCH
)
file(REMOVE ${DOWNLOAD_TMP_FILE})
if(DOWNLOAD_FILTERS)
list(TRANSFORM DOWNLOAD_FILTERS PREPEND ${DOWNLOAD_TMP_EXTRACT}/ OUTPUT_VARIABLE DOWNLOAD_GLOBS)
else()
set(DOWNLOAD_GLOBS ${DOWNLOAD_TMP_EXTRACT}/*)
endif()
file(GLOB DOWNLOAD_TMP_EXTRACT_PATHS LIST_DIRECTORIES ON ${DOWNLOAD_GLOBS})
list(LENGTH DOWNLOAD_TMP_EXTRACT_PATHS DOWNLOAD_COUNT)
if(DOWNLOAD_COUNT EQUAL 0)
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
if(DOWNLOAD_FILTERS)
message(FATAL_ERROR "Extract failed: No files found matching ${DOWNLOAD_FILTERS}")
else()
message(FATAL_ERROR "Extract failed: No files found")
endif()
endif()
if(DOWNLOAD_FILTERS)
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_EXTRACT_PATHS})
elseif(DOWNLOAD_COUNT EQUAL 1)
list(GET DOWNLOAD_TMP_EXTRACT_PATHS 0 DOWNLOAD_TMP_FILE)
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_TMP_FILE} NAME)
message(STATUS "Hoisting ${DOWNLOAD_FILENAME}...")
else()
set(DOWNLOAD_TMP_FILE ${DOWNLOAD_TMP_EXTRACT})
endif()
endif()
if(DOWNLOAD_FILTERS)
foreach(file ${DOWNLOAD_TMP_FILE})
file(RENAME ${file} ${DOWNLOAD_PATH})
endforeach()
else()
file(REMOVE_RECURSE ${DOWNLOAD_PATH})
get_filename_component(DOWNLOAD_PARENT_PATH ${DOWNLOAD_PATH} DIRECTORY)
file(MAKE_DIRECTORY ${DOWNLOAD_PARENT_PATH})
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})

View File

@@ -0,0 +1,111 @@
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
message(STATUS "Running script: ${SCRIPT_NAME}")
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)
set(ZIG_OS "macos")
elseif(CMAKE_HOST_WIN32)
set(ZIG_OS "windows")
elseif(CMAKE_HOST_UNIX)
set(ZIG_OS "linux")
else()
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_HOST_SYSTEM_NAME}")
endif()
# In script mode, using -P, this variable is not set
if(NOT DEFINED CMAKE_HOST_SYSTEM_PROCESSOR)
cmake_host_system_information(RESULT CMAKE_HOST_SYSTEM_PROCESSOR QUERY OS_PLATFORM)
endif()
if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
set(ZIG_ARCH "aarch64")
elseif(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
set(ZIG_ARCH "x86_64")
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
set(ZIG_NAME zig-${ZIG_OS}-${ZIG_ARCH}-${ZIG_VERSION})
if(CMAKE_HOST_WIN32)
set(ZIG_EXE "zig.exe")
set(ZIG_FILENAME ${ZIG_NAME}.zip)
else()
set(ZIG_EXE "zig")
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(
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_URL=${ZIG_DOWNLOAD_URL}
-DDOWNLOAD_PATH=${ZIG_PATH}
-P ${CMAKE_CURRENT_LIST_DIR}/DownloadUrl.cmake
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE
ZIG_DOWNLOAD_ERROR
RESULT_VARIABLE
ZIG_DOWNLOAD_RESULT
)
if(NOT ZIG_DOWNLOAD_RESULT EQUAL 0)
message(FATAL_ERROR "Download failed: ${ZIG_DOWNLOAD_ERROR}")
endif()
if(NOT EXISTS ${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
# To workaround this, we create a `bun.exe` symlink on Unix.
if(NOT WIN32)
file(CREATE_LINK ${ZIG_PATH}/${ZIG_EXE} ${ZIG_PATH}/zig.exe SYMBOLIC)
endif()
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_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}")
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()
message(STATUS "Saved ${ZIG_EXE}")

View File

@@ -0,0 +1,85 @@
get_filename_component(SCRIPT_NAME ${CMAKE_CURRENT_LIST_FILE} NAME)
message(STATUS "Running script: ${SCRIPT_NAME}")
if(NOT GIT_PATH OR NOT GIT_REPOSITORY)
message(FATAL_ERROR "GIT_PATH and GIT_REPOSITORY are required")
endif()
if(GIT_COMMIT)
set(GIT_REF ${GIT_COMMIT})
elseif(GIT_TAG)
set(GIT_REF refs/tags/${GIT_TAG})
elseif(GIT_BRANCH)
set(GIT_REF refs/heads/${GIT_BRANCH})
else()
message(FATAL_ERROR "GIT_COMMIT, GIT_TAG, or GIT_BRANCH are required")
endif()
string(REGEX MATCH "([^/]+)$" GIT_ORIGINAL_NAME ${GIT_REPOSITORY})
if(NOT GIT_NAME)
set(GIT_NAME ${GIT_ORIGINAL_NAME})
endif()
set(GIT_DOWNLOAD_URL https://github.com/${GIT_REPOSITORY}/archive/${GIT_REF}.tar.gz)
message(STATUS "Cloning ${GIT_REPOSITORY} at ${GIT_REF}...")
execute_process(
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_URL=${GIT_DOWNLOAD_URL}
-DDOWNLOAD_PATH=${GIT_PATH}
-DDOWNLOAD_FILTERS=${GIT_FILTERS}
-P ${CMAKE_CURRENT_LIST_DIR}/DownloadUrl.cmake
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE
GIT_ERROR
RESULT_VARIABLE
GIT_RESULT
)
if(NOT GIT_RESULT EQUAL 0)
message(FATAL_ERROR "Clone failed: ${GIT_ERROR}")
endif()
file(GLOB_RECURSE GIT_PATCH_PATHS ${CMAKE_SOURCE_DIR}/patches/${GIT_NAME}/*)
list(LENGTH GIT_PATCH_PATHS GIT_PATCH_COUNT)
if(GIT_PATCH_COUNT GREATER 0)
find_program(GIT_PROGRAM git REQUIRED)
foreach(GIT_PATCH ${GIT_PATCH_PATHS})
get_filename_component(GIT_PATCH_NAME ${GIT_PATCH} NAME)
if(GIT_PATCH_NAME MATCHES "\\.patch$")
message(STATUS "Applying patch ${GIT_PATCH_NAME}...")
execute_process(
COMMAND
${GIT_PROGRAM}
apply
--ignore-whitespace
--ignore-space-change
--no-index
--verbose
${GIT_PATCH}
WORKING_DIRECTORY
${GIT_PATH}
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE
GIT_PATCH_ERROR
RESULT_VARIABLE
GIT_PATCH_RESULT
)
if(NOT GIT_PATCH_RESULT EQUAL 0 AND NOT GIT_PATCH_ERROR MATCHES "cleanly")
file(REMOVE_RECURSE ${GIT_PATH})
message(FATAL_ERROR "Failed to apply patch: ${GIT_PATCH_ERROR}")
endif()
else()
message(STATUS "Copying file ${GIT_PATCH_NAME}...")
file(COPY ${GIT_PATCH} DESTINATION ${GIT_PATH})
endif()
endforeach()
endif()
file(WRITE ${GIT_PATH}/.ref ${GIT_REF})
message(STATUS "Cloned ${GIT_REPOSITORY}")

View File

@@ -0,0 +1,31 @@
register_vendor_target(boringssl)
register_repository(
NAME
${boringssl}
REPOSITORY
oven-sh/boringssl
COMMIT
29a2cd359458c9384694b75456026e4b57e3e567
)
register_libraries(
TARGET ${boringssl}
crypto
ssl
decrepit
)
register_cmake_project(
TARGET
${boringssl}
CMAKE_TARGET
crypto
ssl
decrepit
)
register_cmake_definitions(
TARGET ${boringssl}
BUILD_SHARED_LIBS=OFF
)

View File

@@ -0,0 +1,43 @@
register_vendor_target(brotli)
register_repository(
NAME
${brotli}
REPOSITORY
google/brotli
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 "amd64|AMD64|x86_64|X86_64|x64|X64" AND NOT ENABLE_BASELINE)
register_compiler_flags(
TARGET ${brotli}
-fno-lto
)
endif()

1151
cmake/targets/BuildBun.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,32 @@
register_vendor_target(cares)
register_repository(
NAME
${cares}
REPOSITORY
c-ares/c-ares
COMMIT
d1722e6e8acaf10eb73fa995798a9cd421d9f85e
)
register_libraries(
TARGET ${cares}
PATH lib
cares
)
register_cmake_project(
TARGET
${cares}
CMAKE_TARGET
c-ares
)
register_cmake_definitions(
TARGET ${cares}
CARES_STATIC=ON
CARES_STATIC_PIC=ON
CARES_SHARED=OFF
CARES_BUILD_TOOLS=OFF
CMAKE_POSITION_INDEPENDENT_CODE=ON
)

View File

@@ -0,0 +1,61 @@
register_vendor_target(libarchive)
register_repository(
NAME
${libarchive}
REPOSITORY
libarchive/libarchive
COMMIT
898dc8319355b7e985f68a9819f182aaed61b53a
)
register_libraries(
TARGET ${libarchive}
PATH libarchive
archive
)
register_cmake_project(
TARGET
${libarchive}
CMAKE_TARGET
archive_static
)
register_cmake_definitions(
TARGET ${libarchive}
CMAKE_POSITION_INDEPENDENT_CODE=ON
BUILD_SHARED_LIBS=OFF
ENABLE_INSTALL=OFF
ENABLE_TEST=OFF
ENABLE_WERROR=OFF
ENABLE_BZIP2=OFF
ENABLE_CAT=OFF
ENABLE_EXPAT=OFF
ENABLE_ICONV=OFF
ENABLE_LIBB2=OFF
ENABLE_LibGCC=OFF
ENABLE_LIBXML2=OFF
ENABLE_LZ4=OFF
ENABLE_LZMA=OFF
ENABLE_LZO=OFF
ENABLE_MBEDTLS=OFF
ENABLE_NETTLE=OFF
ENABLE_OPENSSL=OFF
ENABLE_PCRE2POSIX=OFF
ENABLE_PCREPOSIX=OFF
ENABLE_ZSTD=OFF
ENABLE_ZLIB=OFF
HAVE_ZLIB_H=ON
)
# libarchive depends on zlib headers, otherwise it will
# spawn a processes to compress instead of using the library.
register_includes(
TARGET ${libarchive}
${VENDOR_PATH}/${zlib}
)
if(TARGET clone-${zlib})
add_dependencies(${libarchive} clone-${zlib})
endif()

View File

@@ -0,0 +1,30 @@
register_vendor_target(libdeflate)
register_repository(
NAME
${libdeflate}
REPOSITORY
ebiggers/libdeflate
COMMIT
dc76454a39e7e83b68c3704b6e3784654f8d5ac5
)
register_libraries(
TARGET ${libdeflate}
deflatestatic ${WIN32}
deflate ${UNIX}
)
register_cmake_project(
TARGET
${libdeflate}
CMAKE_TARGET
libdeflate_static
)
register_cmake_definitions(
TARGET ${libdeflate}
LIBDEFLATE_BUILD_STATIC_LIB=ON
LIBDEFLATE_BUILD_SHARED_LIB=OFF
LIBDEFLATE_BUILD_GZIP=OFF
)

View File

@@ -0,0 +1,39 @@
register_vendor_target(libuv)
register_repository(
NAME
${libuv}
REPOSITORY
libuv/libuv
COMMIT
da527d8d2a908b824def74382761566371439003
)
register_libraries(
TARGET ${libuv}
uv_a ${WIN32}
uv ${UNIX}
)
register_cmake_project(
TARGET
${libuv}
CMAKE_TARGET
uv_a
)
register_cmake_definitions(
TARGET ${libuv}
LIBUV_BUILD_SHARED=OFF
LIBUV_BUILD_TESTS=OFF
LIBUV_BUILD_BENCH=OFF
)
if(WIN32)
register_compiler_flags(
TARGET ${libuv}
/DWIN32
/D_WINDOWS
-Wno-int-conversion
)
endif()

View File

@@ -0,0 +1,50 @@
register_vendor_target(lolhtml)
register_repository(
NAME
${lolhtml}
REPOSITORY
cloudflare/lol-html
COMMIT
8d4c273ded322193d017042d1f48df2766b0f88b
)
if(DEBUG)
set(${lolhtml}_BUILD_TYPE debug)
else()
set(${lolhtml}_BUILD_TYPE release)
endif()
register_libraries(
TARGET ${lolhtml}
PATH ${${lolhtml}_BUILD_TYPE}
VARIABLE ${lolhtml}_LIBRARY
lolhtml
)
set(${lolhtml}_BUILD_COMMAND
${CARGO_EXECUTABLE}
build
--target-dir ${${lolhtml}_BUILD_PATH}
)
if(RELEASE)
list(APPEND ${lolhtml}_BUILD_COMMAND --release)
endif()
register_command(
TARGET
build-${lolhtml}
CWD
${${lolhtml}_CWD}/c-api
COMMAND
${${lolhtml}_BUILD_COMMAND}
ARTIFACTS
${${lolhtml}_LIBRARY}
)
if(TARGET clone-${lolhtml})
add_dependencies(build-${lolhtml} clone-${lolhtml})
endif()
add_dependencies(${lolhtml} build-${lolhtml})

View File

@@ -0,0 +1,42 @@
register_vendor_target(lshpack)
register_repository(
NAME
${lshpack}
REPOSITORY
litespeedtech/ls-hpack
COMMIT
3d0f1fc1d6e66a642e7a98c55deb38aa986eb4b0
)
register_libraries(
TARGET ${lshpack}
ls-hpack
)
register_cmake_project(
TARGET
${lshpack}
CMAKE_TARGET
ls-hpack
)
register_cmake_definitions(
TARGET ${lshpack}
SHARED=OFF
LSHPACK_XXH=ON
BUILD_TESTING=OFF
)
# FIXME: There are linking errors when built with non-Release
# Undefined symbols for architecture arm64:
# "___asan_handle_no_return", referenced from:
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
# _update_hash in libls-hpack.a(lshpack.c.o)
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
register_cmake_definitions(
TARGET ${lshpack}
CMAKE_BUILD_TYPE=Release
)
endif()

View File

@@ -0,0 +1,63 @@
register_vendor_target(mimalloc)
register_repository(
NAME
${mimalloc}
REPOSITORY
oven-sh/mimalloc
COMMIT
4c283af60cdae205df5a872530c77e2a6a307d43
)
# Workaround for linker issue on macOS and Linux x64
# https://github.com/microsoft/mimalloc/issues/512
if(APPLE OR (LINUX AND NOT DEBUG))
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_project(
TARGET
${mimalloc}
CMAKE_TARGETS
mimalloc-static
mimalloc-obj
)
register_cmake_definitions(
TARGET ${mimalloc}
MI_BUILD_STATIC=ON
MI_BUILD_OBJECT=ON
MI_BUILD_SHARED=OFF
MI_BUILD_TESTS=OFF
MI_USE_CXX=ON
MI_OVERRIDE=OFF
MI_OSX_ZONE=OFF
MI_OSX_INTERPOSE=OFF
MI_SKIP_COLLECT_ON_EXIT=ON
)
if(ENABLE_ASSERTIONS)
register_cmake_definitions(
TARGET ${mimalloc}
MI_DEBUG_FULL=ON
MI_SHOW_ERRORS=ON
)
if(ENABLE_VALGRIND)
register_cmake_definitions(
TARGET ${mimalloc}
MI_VALGRIND=ON
)
endif()
endif()

View File

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

View File

@@ -0,0 +1,13 @@
register_vendor_target(sqlite)
register_libraries(
TARGET ${sqlite}
sqlite3
)
register_cmake_project(
TARGET
${sqlite}
CWD
${CWD}/src/bun.js/bindings/sqlite
)

View File

@@ -0,0 +1,20 @@
register_vendor_target(tinycc)
register_repository(
NAME
${tinycc}
REPOSITORY
oven-sh/tinycc
COMMIT
29985a3b59898861442fa3b43f663fc1af2591d7
)
register_libraries(
TARGET ${tinycc}
tcc
)
register_cmake_project(
TARGET
${tinycc}
)

View File

@@ -0,0 +1,88 @@
optionx(WEBKIT_LOCAL BOOL "If a local version of WebKit should be used instead of downloading" DEFAULT OFF)
optionx(WEBKIT_VERSION STRING "The version of WebKit to use" DEFAULT "4a2db3254a9535949a5d5380eb58cf0f77c8e15a")
if(WEBKIT_LOCAL)
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
else()
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/webkit)
endif()
optionx(WEBKIT_PATH FILEPATH "The path to the WebKit directory" DEFAULT ${DEFAULT_WEBKIT_PATH})
set(WEBKIT_INCLUDE_PATH ${WEBKIT_PATH}/include)
set(WEBKIT_LIB_PATH ${WEBKIT_PATH}/lib)
register_vendor_target(webkit)
register_libraries(
TARGET ${webkit}
PATH ${WEBKIT_PATH}/lib
JavaScriptCore
WTF
bmalloc ${LINUX}
)
if(WIN32)
register_libraries(
TARGET ${webkit}
PATH ${WEBKIT_PATH}/lib
sicudt ${RELEASE}
sicudtd ${DEBUG}
sicuin ${RELEASE}
sicuind ${DEBUG}
sicuuc ${RELEASE}
sicuucd ${DEBUG}
)
endif()
if(WEBKIT_LOCAL)
# Must be built seperately, in the future this can be integrated into the build process
register_target(build-webkit)
else()
if(WIN32)
set(WEBKIT_OS "windows")
elseif(APPLE)
set(WEBKIT_OS "macos")
elseif(LINUX)
set(WEBKIT_OS "linux")
else()
unsupported(CMAKE_SYSTEM_NAME)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
set(WEBKIT_ARCH "arm64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|AMD64|x86_64|X86_64|x64|X64")
set(WEBKIT_ARCH "amd64")
else()
unsupported(CMAKE_SYSTEM_PROCESSOR)
endif()
if(DEBUG)
set(WEBKIT_SUFFIX "-debug")
elseif(ENABLE_LTO AND NOT WIN32)
set(WEBKIT_SUFFIX "-lto")
else()
set(WEBKIT_SUFFIX "")
endif()
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
set(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_NAME}.tar.gz)
get_libraries(${webkit} WEBKIT_LIBRARIES)
register_command(
TARGET
clone-${webkit}
COMMENT
"Downloading ${WEBKIT_NAME}"
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_PATH=${WEBKIT_PATH}
-DDOWNLOAD_URL=${WEBKIT_DOWNLOAD_URL}
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
OUTPUTS
${WEBKIT_PATH}/package.json
${WEBKIT_LIBRARIES}
)
register_outputs(TARGET clone-${webkit} ${WEBKIT_PATH})
endif()

View File

@@ -0,0 +1,38 @@
register_vendor_target(zlib)
register_repository(
NAME
${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)
register_compiler_flags(
TARGET ${zlib}
-fno-define-target-os-macros
)
endif()

View File

@@ -0,0 +1,34 @@
register_vendor_target(zstd)
register_repository(
NAME
${zstd}
REPOSITORY
facebook/zstd
COMMIT
794ea1b0afca0f020f4e57b6732332231fb23c70
)
register_libraries(
TARGET ${zstd}
PATH lib
zstd_static ${WIN32}
zstd ${UNIX}
)
register_cmake_project(
TARGET
${zstd}
CMAKE_TARGET
libzstd_static
CMAKE_PATH
build/cmake
)
register_cmake_definitions(
TARGET ${zstd}
ZSTD_BUILD_STATIC=ON
ZSTD_BUILD_PROGRAMS=OFF
ZSTD_BUILD_TESTS=OFF
ZSTD_BUILD_CONTRIB=OFF
)

View File

@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(CMAKE_OSX_ARCHITECTURES x86_64)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ENABLE_BASELINE ON)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,6 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(ENABLE_BASELINE ON)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_SYSTEM_PROCESSOR x64)
set(CMAKE_C_COMPILER_WORKS ON)
set(CMAKE_CXX_COMPILER_WORKS ON)

View File

@@ -0,0 +1,172 @@
if(NOT BUN_LINK_ONLY)
return()
endif()
optionx(BUILDKITE_ORGANIZATION_SLUG STRING "The organization slug to use on Buildkite" DEFAULT "bun")
optionx(BUILDKITE_PIPELINE_SLUG STRING "The pipeline slug to use on Buildkite" DEFAULT "bun")
optionx(BUILDKITE_BUILD_ID STRING "The build ID to use on Buildkite")
optionx(BUILDKITE_GROUP_ID STRING "The group ID to use on Buildkite")
if(ENABLE_BASELINE)
set(DEFAULT_BUILDKITE_GROUP_KEY ${OS}-${ARCH}-baseline)
else()
set(DEFAULT_BUILDKITE_GROUP_KEY ${OS}-${ARCH})
endif()
optionx(BUILDKITE_GROUP_KEY STRING "The group key to use on Buildkite" DEFAULT ${DEFAULT_BUILDKITE_GROUP_KEY})
if(BUILDKITE)
optionx(BUILDKITE_BUILD_ID_OVERRIDE STRING "The build ID to use on Buildkite")
if(BUILDKITE_BUILD_ID_OVERRIDE)
setx(BUILDKITE_BUILD_ID ${BUILDKITE_BUILD_ID_OVERRIDE})
endif()
endif()
set(BUILDKITE_PATH ${BUILD_PATH}/buildkite)
set(BUILDKITE_BUILDS_PATH ${BUILDKITE_PATH}/builds)
if(NOT BUILDKITE_BUILD_ID)
# TODO: find the latest build on the main branch that passed
return()
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}/${BUILDKITE_BUILD_ID})
file(
DOWNLOAD ${BUILDKITE_BUILD_URL}
HTTPHEADER "Accept: application/json"
TIMEOUT 15
STATUS BUILDKITE_BUILD_STATUS
${BUILDKITE_BUILD_PATH}/build.json
)
if(NOT BUILDKITE_BUILD_STATUS EQUAL 0)
message(FATAL_ERROR "No build found: ${BUILDKITE_BUILD_STATUS} ${BUILDKITE_BUILD_URL}")
return()
endif()
file(READ ${BUILDKITE_BUILD_PATH}/build.json BUILDKITE_BUILD)
string(JSON BUILDKITE_BUILD_UUID GET ${BUILDKITE_BUILD} id)
string(JSON BUILDKITE_JOBS GET ${BUILDKITE_BUILD} jobs)
string(JSON BUILDKITE_JOBS_COUNT LENGTH ${BUILDKITE_JOBS})
if(NOT BUILDKITE_JOBS_COUNT GREATER 0)
message(FATAL_ERROR "No jobs found: ${BUILDKITE_BUILD_URL}")
return()
endif()
set(BUILDKITE_JOBS_FAILED)
set(BUILDKITE_JOBS_NOT_FOUND)
set(BUILDKITE_JOBS_NO_ARTIFACTS)
set(BUILDKITE_JOBS_NO_MATCH)
set(BUILDKITE_JOBS_MATCH)
math(EXPR BUILDKITE_JOBS_MAX_INDEX "${BUILDKITE_JOBS_COUNT} - 1")
foreach(i RANGE ${BUILDKITE_JOBS_MAX_INDEX})
string(JSON BUILDKITE_JOB GET ${BUILDKITE_JOBS} ${i})
string(JSON BUILDKITE_JOB_ID GET ${BUILDKITE_JOB} id)
string(JSON BUILDKITE_JOB_PASSED GET ${BUILDKITE_JOB} passed)
string(JSON BUILDKITE_JOB_GROUP_ID GET ${BUILDKITE_JOB} group_uuid)
string(JSON BUILDKITE_JOB_GROUP_KEY GET ${BUILDKITE_JOB} group_identifier)
string(JSON BUILDKITE_JOB_NAME GET ${BUILDKITE_JOB} step_key)
if(NOT BUILDKITE_JOB_NAME)
string(JSON BUILDKITE_JOB_NAME GET ${BUILDKITE_JOB} name)
endif()
if(NOT BUILDKITE_JOB_PASSED)
list(APPEND BUILDKITE_JOBS_FAILED ${BUILDKITE_JOB_NAME})
continue()
endif()
if(NOT (BUILDKITE_GROUP_ID AND BUILDKITE_GROUP_ID STREQUAL BUILDKITE_JOB_GROUP_ID) AND
NOT (BUILDKITE_GROUP_KEY AND BUILDKITE_GROUP_KEY STREQUAL BUILDKITE_JOB_GROUP_KEY))
list(APPEND BUILDKITE_JOBS_NO_MATCH ${BUILDKITE_JOB_NAME})
continue()
endif()
set(BUILDKITE_ARTIFACTS_URL https://buildkite.com/organizations/${BUILDKITE_ORGANIZATION_SLUG}/pipelines/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_UUID}/jobs/${BUILDKITE_JOB_ID}/artifacts)
set(BUILDKITE_ARTIFACTS_PATH ${BUILDKITE_BUILD_PATH}/artifacts/${BUILDKITE_JOB_ID}.json)
file(
DOWNLOAD ${BUILDKITE_ARTIFACTS_URL}
HTTPHEADER "Accept: application/json"
TIMEOUT 15
STATUS BUILDKITE_ARTIFACTS_STATUS
${BUILDKITE_ARTIFACTS_PATH}
)
if(NOT BUILDKITE_ARTIFACTS_STATUS EQUAL 0)
list(APPEND BUILDKITE_JOBS_NOT_FOUND ${BUILDKITE_JOB_NAME})
continue()
endif()
file(READ ${BUILDKITE_ARTIFACTS_PATH} BUILDKITE_ARTIFACTS)
string(JSON BUILDKITE_ARTIFACTS_LENGTH LENGTH ${BUILDKITE_ARTIFACTS})
if(NOT BUILDKITE_ARTIFACTS_LENGTH GREATER 0)
list(APPEND BUILDKITE_JOBS_NO_ARTIFACTS ${BUILDKITE_JOB_NAME})
continue()
endif()
math(EXPR BUILDKITE_ARTIFACTS_MAX_INDEX "${BUILDKITE_ARTIFACTS_LENGTH} - 1")
foreach(i RANGE 0 ${BUILDKITE_ARTIFACTS_MAX_INDEX})
string(JSON BUILDKITE_ARTIFACT GET ${BUILDKITE_ARTIFACTS} ${i})
string(JSON BUILDKITE_ARTIFACT_ID GET ${BUILDKITE_ARTIFACT} id)
string(JSON BUILDKITE_ARTIFACT_PATH GET ${BUILDKITE_ARTIFACT} path)
if(NOT BUILDKITE_ARTIFACT_PATH MATCHES "\\.(o|a|lib|zip|tar|gz)")
continue()
endif()
if(BUILDKITE)
set(BUILDKITE_DOWNLOAD_COMMAND buildkite-agent artifact download ${BUILDKITE_ARTIFACT_PATH} . --build ${BUILDKITE_BUILD_UUID} --step ${BUILDKITE_JOB_ID})
else()
set(BUILDKITE_DOWNLOAD_COMMAND curl -L -o ${BUILDKITE_ARTIFACT_PATH} ${BUILDKITE_ARTIFACTS_URL}/${BUILDKITE_ARTIFACT_ID})
endif()
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()
list(APPEND BUILDKITE_JOBS_MATCH ${BUILDKITE_JOB_NAME})
endforeach()
if(BUILDKITE_JOBS_FAILED)
list(SORT BUILDKITE_JOBS_FAILED COMPARE STRING)
list(JOIN BUILDKITE_JOBS_FAILED " " BUILDKITE_JOBS_FAILED)
message(WARNING "The following jobs were found, but failed: ${BUILDKITE_JOBS_FAILED}")
endif()
if(BUILDKITE_JOBS_NOT_FOUND)
list(SORT BUILDKITE_JOBS_NOT_FOUND COMPARE STRING)
list(JOIN BUILDKITE_JOBS_NOT_FOUND " " BUILDKITE_JOBS_NOT_FOUND)
message(WARNING "The following jobs were found, but could not fetch their data: ${BUILDKITE_JOBS_NOT_FOUND}")
endif()
if(BUILDKITE_JOBS_NO_MATCH)
list(SORT BUILDKITE_JOBS_NO_MATCH COMPARE STRING)
list(JOIN BUILDKITE_JOBS_NO_MATCH " " BUILDKITE_JOBS_NO_MATCH)
message(WARNING "The following jobs were found, but did not match the group ID: ${BUILDKITE_JOBS_NO_MATCH}")
endif()
if(BUILDKITE_JOBS_NO_ARTIFACTS)
list(SORT BUILDKITE_JOBS_NO_ARTIFACTS COMPARE STRING)
list(JOIN BUILDKITE_JOBS_NO_ARTIFACTS " " BUILDKITE_JOBS_NO_ARTIFACTS)
message(WARNING "The following jobs were found, but had no artifacts: ${BUILDKITE_JOBS_NO_ARTIFACTS}")
endif()
if(BUILDKITE_JOBS_MATCH)
list(SORT BUILDKITE_JOBS_MATCH COMPARE STRING)
list(JOIN BUILDKITE_JOBS_MATCH " " BUILDKITE_JOBS_MATCH)
message(STATUS "The following jobs were found, and matched the group ID: ${BUILDKITE_JOBS_MATCH}")
endif()
if(NOT BUILDKITE_JOBS_FAILED AND NOT BUILDKITE_JOBS_NOT_FOUND AND NOT BUILDKITE_JOBS_NO_MATCH AND NOT BUILDKITE_JOBS_NO_ARTIFACTS AND NOT BUILDKITE_JOBS_MATCH)
message(FATAL_ERROR "Something went wrong with Buildkite?")
endif()

View File

@@ -0,0 +1,21 @@
find_command(
VARIABLE
BUN_EXECUTABLE
COMMAND
bun
PATHS
$ENV{HOME}/.bun/bin
VERSION
>=1.1.26
)
# If this is not set, some advanced features are not checked.
# https://github.com/oven-sh/bun/blob/cd7f6a1589db7f1e39dc4e3f4a17234afbe7826c/src/bun.js/javascript.zig#L1069-L1072
setenv(BUN_GARBAGE_COLLECTOR_LEVEL 1)
setenv(BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING 1)
setenv(BUN_DEBUG_QUIET_LOGS 1)
# FIXME: https://github.com/oven-sh/bun/issues/11250
if(NOT WIN32)
setenv(BUN_INSTALL_CACHE_DIR ${CACHE_PATH}/bun)
endif()

View File

@@ -0,0 +1,37 @@
optionx(ENABLE_CCACHE BOOL "If ccache should be enabled" DEFAULT ON)
if(NOT ENABLE_CCACHE OR CACHE_STRATEGY STREQUAL "none")
setenv(CCACHE_DISABLE 1)
return()
endif()
find_command(
VARIABLE
CCACHE_PROGRAM
COMMAND
ccache
REQUIRED
ON
)
setx(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
setx(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
setenv(CCACHE_DIR ${CACHE_PATH}/ccache)
setenv(CCACHE_BASEDIR ${CWD})
setenv(CCACHE_NOHASHDIR 1)
if(CACHE_STRATEGY STREQUAL "read-only")
setenv(CCACHE_READONLY 1)
elseif(CACHE_STRATEGY STREQUAL "write-only")
setenv(CCACHE_RECACHE 1)
endif()
setenv(CCACHE_FILECLONE 1)
setenv(CCACHE_STATSLOG ${BUILD_PATH}/ccache.log)
if(CI)
setenv(CCACHE_SLOPPINESS "pch_defines,time_macros,locale,clang_index_store,gcno_cwd,include_file_ctime,include_file_mtime")
else()
setenv(CCACHE_SLOPPINESS "pch_defines,time_macros,locale,random_seed,clang_index_store,gcno_cwd")
endif()

View File

@@ -0,0 +1,20 @@
if(CMAKE_HOST_WIN32)
setx(ESBUILD_EXECUTABLE ${CWD}/node_modules/.bin/esbuild.exe)
else()
setx(ESBUILD_EXECUTABLE ${CWD}/node_modules/.bin/esbuild)
endif()
if(CMAKE_COLOR_DIAGNOSTICS)
set(ESBUILD_ARGS --color)
endif()
register_command(
COMMAND
${BUN_EXECUTABLE}
install
--frozen-lockfile
SOURCES
${CWD}/package.json
OUTPUTS
${ESBUILD_EXECUTABLE}
)

View File

@@ -0,0 +1,63 @@
if(CMAKE_HOST_WIN32 OR CMAKE_HOST_APPLE)
set(DEFAULT_LLVM_VERSION "18.1.8")
else()
set(DEFAULT_LLVM_VERSION "16.0.6")
endif()
optionx(LLVM_VERSION STRING "The version of LLVM to use" DEFAULT ${DEFAULT_LLVM_VERSION})
parse_semver(${LLVM_VERSION} LLVM)
if(APPLE)
execute_process(
COMMAND brew --prefix llvm@${LLVM_VERSION_MAJOR}
OUTPUT_VARIABLE DEFAULT_LLVM_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
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()
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}
COMMAND ${COMMAND} ${COMMAND}-${LLVM_VERSION_MAJOR}
PATHS ${LLVM_PATH}
VERSION ${LLVM_VERSION}
)
endmacro()
macro(find_llvm_command_no_version VARIABLE COMMAND)
find_command(
VARIABLE ${VARIABLE}
COMMAND ${COMMAND} ${COMMAND}-${LLVM_VERSION_MAJOR}
PATHS ${LLVM_PATH}
REQUIRED ON
)
endmacro()
if(WIN32)
find_llvm_command(CMAKE_C_COMPILER clang-cl)
find_llvm_command(CMAKE_CXX_COMPILER clang-cl)
find_llvm_command_no_version(CMAKE_LINKER lld-link)
find_llvm_command_no_version(CMAKE_AR llvm-lib)
find_llvm_command_no_version(CMAKE_STRIP llvm-strip)
else()
find_llvm_command(CMAKE_C_COMPILER clang)
find_llvm_command(CMAKE_CXX_COMPILER clang++)
find_llvm_command(CMAKE_LINKER llvm-link)
find_llvm_command(CMAKE_AR llvm-ar)
find_llvm_command(CMAKE_STRIP llvm-strip)
find_llvm_command(CMAKE_RANLIB llvm-ranlib)
if(APPLE)
find_llvm_command(CMAKE_DSYMUTIL dsymutil)
endif()
endif()

View File

@@ -0,0 +1,54 @@
set(MIN_OSX_DEPLOYMENT_TARGET "13.0")
if(DEFINED ENV{CI})
set(DEFAULT_OSX_DEPLOYMENT_TARGET ${MIN_OSX_DEPLOYMENT_TARGET})
else()
execute_process(
COMMAND xcrun --sdk macosx --show-sdk-version
OUTPUT_VARIABLE CURRENT_OSX_DEPLOYMENT_TARGET
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE DEFAULT_OSX_DEPLOYMENT_TARGET_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
if(DEFAULT_OSX_DEPLOYMENT_TARGET_ERROR)
message(WARNING "Failed to find macOS SDK version, did you run `xcode-select --install`?")
message(FATAL_ERROR ${DEFAULT_OSX_DEPLOYMENT_TARGET_ERROR})
endif()
string(REGEX MATCH "^[0-9]*" DEFAULT_OSX_DEPLOYMENT_TARGET ${CURRENT_OSX_DEPLOYMENT_TARGET})
endif()
optionx(CMAKE_OSX_DEPLOYMENT_TARGET STRING "The macOS SDK version to target" DEFAULT ${DEFAULT_OSX_DEPLOYMENT_TARGET})
if(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS ${MIN_OSX_DEPLOYMENT_TARGET})
message(FATAL_ERROR "The target macOS SDK version, ${CMAKE_OSX_DEPLOYMENT_TARGET}, is older than the minimum supported version, ${MIN_OSX_DEPLOYMENT_TARGET}.")
endif()
execute_process(
COMMAND sw_vers -productVersion
OUTPUT_VARIABLE MACOS_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
if(MACOS_VERSION VERSION_LESS ${CMAKE_OSX_DEPLOYMENT_TARGET})
message(FATAL_ERROR "Your computer is running macOS ${MACOS_VERSION}, which is older than the target macOS SDK ${CMAKE_OSX_DEPLOYMENT_TARGET}. To fix this, either:\n"
" - Upgrade your computer to macOS ${CMAKE_OSX_DEPLOYMENT_TARGET} or newer\n"
" - Download a newer version of the macOS SDK from Apple: https://developer.apple.com/download/all/?q=xcode\n"
" - Set -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOS_VERSION}\n")
endif()
execute_process(
COMMAND xcrun --sdk macosx --show-sdk-path
OUTPUT_VARIABLE DEFAULT_CMAKE_OSX_SYSROOT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE DEFAULT_CMAKE_OSX_SYSROOT_ERROR
ERROR_STRIP_TRAILING_WHITESPACE
)
if(CMAKE_OSX_SYSROOT_ERROR)
message(WARNING "Failed to find macOS SDK path, did you run `xcode-select --install`?")
message(FATAL_ERROR ${CMAKE_OSX_SYSROOT_ERROR})
endif()
optionx(CMAKE_OSX_SYSROOT STRING "The macOS SDK path to target" DEFAULT ${DEFAULT_CMAKE_OSX_SYSROOT})

View File

@@ -0,0 +1,25 @@
find_command(
VARIABLE
CARGO_EXECUTABLE
COMMAND
cargo
PATHS
$ENV{HOME}/.cargo/bin
REQUIRED
OFF
)
if(EXISTS ${CARGO_EXECUTABLE})
return()
endif()
if(CMAKE_HOST_WIN32)
set(CARGO_INSTALL_COMMAND "choco install rust")
else()
set(CARGO_INSTALL_COMMAND "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh")
endif()
message(FATAL_ERROR "Command not found: cargo\n"
"Do you have Rust installed? To fix this, try running:\n"
" ${CARGO_INSTALL_COMMAND}\n"
)

View File

@@ -0,0 +1,75 @@
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(DEFAULT_ZIG_ARCH "aarch64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|x64|AMD64")
set(DEFAULT_ZIG_ARCH "x86_64")
else()
unsupported(CMAKE_SYSTEM_PROCESSOR)
endif()
if(APPLE)
set(DEFAULT_ZIG_TARGET ${DEFAULT_ZIG_ARCH}-macos-none)
elseif(WIN32)
set(DEFAULT_ZIG_TARGET ${DEFAULT_ZIG_ARCH}-windows-msvc)
elseif(LINUX)
set(DEFAULT_ZIG_TARGET ${DEFAULT_ZIG_ARCH}-linux-gnu)
else()
unsupported(CMAKE_SYSTEM_NAME)
endif()
optionx(ZIG_TARGET STRING "The zig target to use" DEFAULT ${DEFAULT_ZIG_TARGET})
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(DEFAULT_ZIG_OPTIMIZE "ReleaseFast")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(DEFAULT_ZIG_OPTIMIZE "ReleaseSafe")
elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
set(DEFAULT_ZIG_OPTIMIZE "ReleaseSmall")
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEFAULT_ZIG_OPTIMIZE "Debug")
else()
unsupported(CMAKE_BUILD_TYPE)
endif()
# Since Bun 1.1, Windows has been built using ReleaseSafe.
# This is because it caught more crashes, but we can reconsider this in the future
if(WIN32 AND DEFAULT_ZIG_OPTIMIZE STREQUAL "ReleaseFast")
set(DEFAULT_ZIG_OPTIMIZE "ReleaseSafe")
endif()
optionx(ZIG_OPTIMIZE "ReleaseFast|ReleaseSafe|ReleaseSmall|Debug" "The Zig optimize level to use" DEFAULT ${DEFAULT_ZIG_OPTIMIZE})
# To use LLVM bitcode from Zig, more work needs to be done. Currently, an install of
# LLVM 18.1.7 does not compatible with what bitcode Zig 0.13 outputs (has LLVM 18.1.7)
# Change to "bc" to experiment, "Invalid record" means it is not valid output.
optionx(ZIG_OBJECT_FORMAT "obj|bc" "Output file format for Zig object files" DEFAULT obj)
optionx(ZIG_LOCAL_CACHE_DIR FILEPATH "The path to local the zig cache directory" DEFAULT ${CACHE_PATH}/zig/local)
optionx(ZIG_GLOBAL_CACHE_DIR FILEPATH "The path to the global zig cache directory" DEFAULT ${CACHE_PATH}/zig/global)
setenv(ZIG_LOCAL_CACHE_DIR ${ZIG_LOCAL_CACHE_DIR})
setenv(ZIG_GLOBAL_CACHE_DIR ${ZIG_GLOBAL_CACHE_DIR})
setx(ZIG_PATH ${VENDOR_PATH}/zig)
if(WIN32)
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig.exe)
else()
setx(ZIG_EXECUTABLE ${ZIG_PATH}/zig)
endif()
set(CMAKE_ZIG_FLAGS
--cache-dir ${ZIG_LOCAL_CACHE_DIR}
--global-cache-dir ${ZIG_GLOBAL_CACHE_DIR}
--zig-lib-dir ${ZIG_PATH}/lib
)
register_command(
COMMENT
"Downloading zig"
COMMAND
${CMAKE_COMMAND}
-DZIG_PATH=${ZIG_PATH}
-P ${CWD}/cmake/scripts/DownloadZig.cmake
OUTPUTS
${ZIG_EXECUTABLE}
)

View File

@@ -382,6 +382,16 @@ Refer to the [MDN documentation](https://developer.mozilla.org/en-US/docs/Web/Ja
It's worth specifically highlighting `Uint8Array`, as it represents a classic "byte array"—a sequence of 8-bit unsigned integers between 0 and 255. This is the most common typed array you'll encounter in JavaScript.
In Bun, and someday in other JavaScript engines, it has methods available for converting between byte arrays and serialized representations of those arrays as base64 or hex strings.
```ts
new Uint8Array([1, 2, 3, 4, 5]).toBase64(); // "AQIDBA=="
Uint8Array.fromBase64("AQIDBA=="); // Uint8Array(4) [1, 2, 3, 4, 5]
new Uint8Array([255, 254, 253, 252, 251]).toHex(); // "fffefdfcfb=="
Uint8Array.fromHex("fffefdfcfb"); // Uint8Array(5) [255, 254, 253, 252, 251]
```
It is the return value of [`TextEncoder#encode`](https://developer.mozilla.org/en-US/docs/Web/API/TextEncoder), and the input type of [`TextDecoder#decode`](https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder), two utility classes designed to translate strings and various binary encodings, most notably `"utf-8"`.
```ts
@@ -442,6 +452,7 @@ The contents of a `Blob` can be asynchronously read in various formats.
```ts
await blob.text(); // => <html><body>hello</body></html>
await blob.bytes(); // => Uint8Array (copies contents)
await blob.arrayBuffer(); // => ArrayBuffer (copies contents)
await blob.stream(); // => ReadableStream
```
@@ -511,7 +522,7 @@ for await (const chunk of stream) {
}
```
For a more complete discussion of streams in Bun, see [API > Streams](/docs/api/streams).
For a more complete discussion of streams in Bun, see [API > Streams](https://bun.sh/docs/api/streams).
## Conversion
@@ -545,6 +556,7 @@ Buffer.from(buf, 0, 10);
#### To `string`
As UTF-8:
```ts
new TextDecoder().decode(buf);
```
@@ -625,6 +637,7 @@ Buffer.from(arr);
#### To `string`
As UTF-8:
```ts
new TextDecoder().decode(arr);
```
@@ -638,6 +651,7 @@ Array.from(arr);
#### To `Blob`
```ts
// only if arr is a view of its entire backing TypedArray
new Blob([arr.buffer], { type: "text/plain" });
```
@@ -701,6 +715,7 @@ Buffer.from(view.buffer, view.byteOffset, view.byteLength);
#### To `string`
As UTF-8:
```ts
new TextDecoder().decode(view);
```
@@ -772,9 +787,18 @@ new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
#### To `string`
As UTF-8:
```ts
buf.toString();
```
As base64:
```ts
buf.toString('base64');
```
As hex:
```ts
buf.toString('hex');
```
#### To `number[]`
@@ -834,7 +858,7 @@ await blob.arrayBuffer();
#### To `TypedArray`
```ts
new Uint8Array(await blob.arrayBuffer());
await blob.bytes();
```
#### To `DataView`
@@ -851,6 +875,7 @@ Buffer.from(await blob.arrayBuffer());
#### To `string`
As UTF-8:
```ts
await blob.text();
```
@@ -858,7 +883,7 @@ await blob.text();
#### To `number[]`
```ts
Array.from(new Uint8Array(await blob.arrayBuffer()));
Array.from(await blob.bytes());
```
#### To `ReadableStream`
@@ -936,9 +961,10 @@ Buffer.from(Bun.readableStreamToArrayBuffer(stream));
#### To `string`
As UTF-8:
```ts
// with Response
new Response(stream).text();
await new Response(stream).text();
// with Bun function
await Bun.readableStreamToText(stream);
@@ -948,8 +974,8 @@ await Bun.readableStreamToText(stream);
```ts
// with Response
const buf = await new Response(stream).arrayBuffer();
Array.from(new Uint8Array(buf));
const arr = await new Response(stream).bytes();
Array.from(arr);
// with Bun function
Array.from(new Uint8Array(Bun.readableStreamToArrayBuffer(stream)));

197
docs/api/cc.md Normal file
View File

@@ -0,0 +1,197 @@
`bun:ffi` has experimental support for compiling and running C from JavaScript with low overhead.
## Usage (cc in `bun:ffi`)
See the [introduction blog post](https://bun.sh/blog/compile-and-run-c-in-js) for more information.
JavaScript:
```ts#hello.js
import { cc } from "bun:ffi";
import source from "./hello.c" with { type: "file" };
const {
symbols: { hello },
} = cc({
source,
symbols: {
hello: {
args: [],
returns: "int",
},
},
});
console.log("What is the answer to the universe?", hello());
```
C source:
```c#hello.c
int hello() {
return 42;
}
```
When you run `hello.js`, it will print:
```sh
$ bun hello.js
What is the answer to the universe? 42
```
Under the hood, `cc` uses [TinyCC](https://bellard.org/tcc/) to compile the C code and then link it with the JavaScript runtime, efficiently converting types in-place.
### Primitive types
The same `FFIType` values in [`dlopen`](/docs/api/ffi) are supported in `cc`.
| `FFIType` | C Type | Aliases |
| ---------- | -------------- | --------------------------- |
| cstring | `char*` | |
| function | `(void*)(*)()` | `fn`, `callback` |
| ptr | `void*` | `pointer`, `void*`, `char*` |
| i8 | `int8_t` | `int8_t` |
| i16 | `int16_t` | `int16_t` |
| i32 | `int32_t` | `int32_t`, `int` |
| i64 | `int64_t` | `int64_t` |
| i64_fast | `int64_t` | |
| u8 | `uint8_t` | `uint8_t` |
| u16 | `uint16_t` | `uint16_t` |
| u32 | `uint32_t` | `uint32_t` |
| u64 | `uint64_t` | `uint64_t` |
| u64_fast | `uint64_t` | |
| f32 | `float` | `float` |
| f64 | `double` | `double` |
| bool | `bool` | |
| char | `char` | |
| napi_env | `napi_env` | |
| napi_value | `napi_value` | |
### Strings, objects, and non-primitive types
To make it easier to work with strings, objects, and other non-primitive types that don't map 1:1 to C types, `cc` supports N-API.
To pass or receive a JavaScript values without any type conversions from a C function, you can use `napi_value`.
You can also pass a `napi_env` to receive the N-API environment used to call the JavaScript function.
#### Returning a C string to JavaScript
For example, if you have a string in C, you can return it to JavaScript like this:
```ts#hello.js
import { cc } from "bun:ffi";
import source from "./hello.c" with { type: "file" };
const {
symbols: { hello },
} = cc({
source,
symbols: {
hello: {
args: ["napi_env"],
returns: "napi_value",
},
},
});
const result = hello();
```
And in C:
```c#hello.c
#include <node/node_api.h>
napi_value hello(napi_env env) {
napi_value result;
napi_create_string_utf8(env, "Hello, Napi!", NAPI_AUTO_LENGTH, &result);
return result;
}
```
You can also use this to return other types like objects and arrays:
```c#hello.c
#include <node/node_api.h>
napi_value hello(napi_env env) {
napi_value result;
napi_create_object(env, &result);
return result;
}
```
### `cc` Reference
#### `library: string[]`
The `library` array is used to specify the libraries that should be linked with the C code.
```ts
type Library = string[];
cc({
source: "hello.c",
library: ["sqlite3"],
});
```
#### `symbols`
The `symbols` object is used to specify the functions and variables that should be exposed to JavaScript.
```ts
type Symbols = {
[key: string]: {
args: FFIType[];
returns: FFIType;
};
};
```
#### `source`
The `source` is a file path to the C code that should be compiled and linked with the JavaScript runtime.
```ts
type Source = string | URL | BunFile;
cc({
source: "hello.c",
symbols: {
hello: {
args: [],
returns: "int",
},
},
});
```
#### `flags: string | string[]`
The `flags` is an optional array of strings that should be passed to the TinyCC compiler.
```ts
type Flags = string | string[];
```
These are flags like `-I` for include directories and `-D` for preprocessor definitions.
#### `defines: Record<string, string>`
The `defines` is an optional object that should be passed to the TinyCC compiler.
```ts
type Defines = Record<string, string>;
cc({
source: "hello.c",
defines: {
"NDEBUG": "1",
},
});
```
These are preprocessor definitions passed to the TinyCC compiler.

View File

@@ -241,7 +241,7 @@ dns.prefetch("bun.sh", 443);
By default, Bun caches and deduplicates DNS queries in-memory for up to 30 seconds. You can see the cache stats by calling `dns.getCacheStats()`:
To learn more about DNS caching in Bun, see the [DNS caching](/docs/api/dns) documentation.
To learn more about DNS caching in Bun, see the [DNS caching](https://bun.sh/docs/api/dns) documentation.
### Preconnect to a host

View File

@@ -1,6 +1,6 @@
Use the built-in `bun:ffi` module to efficiently call native libraries from JavaScript. It works with languages that support the C ABI (Zig, Rust, C/C++, C#, Nim, Kotlin, etc).
## Usage (`bun:ffi`)
## dlopen usage (`bun:ffi`)
To print the version number of `sqlite3`:
@@ -108,25 +108,30 @@ $ zig build-lib add.cpp -dynamic -lc -lc++
The following `FFIType` values are supported.
| `FFIType` | C Type | Aliases |
| --------- | -------------- | --------------------------- |
| cstring | `char*` | |
| function | `(void*)(*)()` | `fn`, `callback` |
| ptr | `void*` | `pointer`, `void*`, `char*` |
| i8 | `int8_t` | `int8_t` |
| i16 | `int16_t` | `int16_t` |
| i32 | `int32_t` | `int32_t`, `int` |
| i64 | `int64_t` | `int64_t` |
| i64_fast | `int64_t` | |
| u8 | `uint8_t` | `uint8_t` |
| u16 | `uint16_t` | `uint16_t` |
| u32 | `uint32_t` | `uint32_t` |
| u64 | `uint64_t` | `uint64_t` |
| u64_fast | `uint64_t` | |
| f32 | `float` | `float` |
| f64 | `double` | `double` |
| bool | `bool` | |
| char | `char` | |
| `FFIType` | C Type | Aliases |
| ---------- | -------------- | --------------------------- |
| buffer | `char*` | |
| cstring | `char*` | |
| function | `(void*)(*)()` | `fn`, `callback` |
| ptr | `void*` | `pointer`, `void*`, `char*` |
| i8 | `int8_t` | `int8_t` |
| i16 | `int16_t` | `int16_t` |
| i32 | `int32_t` | `int32_t`, `int` |
| i64 | `int64_t` | `int64_t` |
| i64_fast | `int64_t` | |
| u8 | `uint8_t` | `uint8_t` |
| u16 | `uint16_t` | `uint16_t` |
| u32 | `uint32_t` | `uint32_t` |
| u64 | `uint64_t` | `uint64_t` |
| u64_fast | `uint64_t` | |
| f32 | `float` | `float` |
| f64 | `double` | `double` |
| bool | `bool` | |
| char | `char` | |
| napi_env | `napi_env` | |
| napi_value | `napi_value` | |
Note: `buffer` arguments must be a `TypedArray` or `DataView`.
## Strings

View File

@@ -1,8 +1,8 @@
{% callout %}
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](https://bun.sh/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir` or `readdir`, you can use Bun's [nearly complete](/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir` or `readdir`, you can use Bun's [nearly complete](https://bun.sh/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
{% /callout %}

View File

@@ -34,7 +34,7 @@ Bun implements the following globals.
- [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer)
- Node.js
- See [Node.js > `Buffer`](/docs/runtime/nodejs-apis#node-buffer)
- See [Node.js > `Buffer`](https://bun.sh/docs/runtime/nodejs-apis#node-buffer)
---
@@ -172,7 +172,7 @@ Bun implements the following globals.
- [`global`](https://nodejs.org/api/globals.html#global)
- Node.js
- See [Node.js > `global`](/docs/runtime/nodejs-apis#global).
- See [Node.js > `global`](https://bun.sh/docs/runtime/nodejs-apis#global).
---
@@ -188,7 +188,7 @@ Bun implements the following globals.
---
- [`HTMLRewriter`](/docs/api/html-rewriter)
- [`HTMLRewriter`](https://bun.sh/docs/api/html-rewriter)
- Cloudflare
- &nbsp;
@@ -220,7 +220,7 @@ Bun implements the following globals.
- [`process`](https://nodejs.org/api/process.html)
- Node.js
- See [Node.js > `process`](/docs/runtime/nodejs-apis#node-process)
- See [Node.js > `process`](https://bun.sh/docs/runtime/nodejs-apis#node-process)
---

View File

@@ -1,7 +1,7 @@
The page primarily documents the Bun-native `Bun.serve` API. Bun also implements [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) and the Node.js [`http`](https://nodejs.org/api/http.html) and [`https`](https://nodejs.org/api/https.html) modules.
{% callout %}
These modules have been re-implemented to use Bun's fast internal HTTP infrastructure. Feel free to use these modules directly; frameworks like [Express](https://expressjs.com/) that depend on these modules should work out of the box. For granular compatibility information, see [Runtime > Node.js APIs](/docs/runtime/nodejs-apis).
These modules have been re-implemented to use Bun's fast internal HTTP infrastructure. Feel free to use these modules directly; frameworks like [Express](https://expressjs.com/) that depend on these modules should work out of the box. For granular compatibility information, see [Runtime > Node.js APIs](https://bun.sh/docs/runtime/nodejs-apis).
{% /callout %}
To start a high-performance HTTP server with a clean API, the recommended approach is [`Bun.serve`](#start-a-server-bun-serve).
@@ -87,7 +87,7 @@ Bun.serve({
// serve static text
"/": new Response("Hello World"),
// server a file by buffering it in memory
// serve a file by buffering it in memory
"/index.html": new Response(await Bun.file("./index.html").bytes(), {
headers: {
"Content-Type": "text/html",
@@ -475,7 +475,7 @@ Instead of passing the server options into `Bun.serve`, `export default` it. Thi
$ bun --hot server.ts
``` -->
<!-- It's possible to configure hot reloading while using the explicit `Bun.serve` API; for details refer to [Runtime > Hot reloading](/docs/runtime/hot). -->
<!-- It's possible to configure hot reloading while using the explicit `Bun.serve` API; for details refer to [Runtime > Hot reloading](https://bun.sh/docs/runtime/hot). -->
## Streaming files

View File

@@ -1 +1 @@
See the [`bun test`](/docs/cli/test) documentation.
See the [`bun test`](https://bun.sh/docs/cli/test) documentation.

View File

@@ -183,7 +183,7 @@ const currentFile = import.meta.url;
Bun.openInEditor(currentFile);
```
You can override this via the `debug.editor` setting in your [`bunfig.toml`](/docs/runtime/bunfig).
You can override this via the `debug.editor` setting in your [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig).
```toml-diff#bunfig.toml
+ [debug]

View File

@@ -146,7 +146,7 @@ $ bun build ./index.tsx --outdir ./out --watch
## Content types
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](/docs/runtime/loaders) for full documentation.
Like the Bun runtime, the bundler supports an array of file types out of the box. The following table breaks down the bundler's set of standard "loaders". Refer to [Bundler > File types](https://bun.sh/docs/runtime/loaders) for full documentation.
{% table %}
@@ -219,11 +219,11 @@ console.log(logo);
The exact behavior of the file loader is also impacted by [`naming`](#naming) and [`publicPath`](#publicpath).
{% /callout %}
Refer to the [Bundler > Loaders](/docs/bundler/loaders#file) page for more complete documentation on the file loader.
Refer to the [Bundler > Loaders](https://bun.sh/docs/bundler/loaders#file) page for more complete documentation on the file loader.
### Plugins
The behavior described in this table can be overridden or extended with [plugins](/docs/bundler/plugins). Refer to the [Bundler > Loaders](/docs/bundler/plugins) page for complete documentation.
The behavior described in this table can be overridden or extended with [plugins](https://bun.sh/docs/bundler/plugins). Refer to the [Bundler > Loaders](https://bun.sh/docs/bundler/plugins) page for complete documentation.
## API
@@ -490,7 +490,7 @@ n/a
{% /codetabs %}
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](/docs/bundler/plugins) for complete documentation.
Bun implements a universal plugin system for both Bun's runtime and bundler. Refer to the [plugin documentation](https://bun.sh/docs/bundler/plugins) for complete documentation.
<!-- ### `manifest`
@@ -1000,7 +1000,7 @@ A prefix to be appended to any import paths in bundled code.
In many cases, generated bundles will contain no `import` statements. After all, the goal of bundling is to combine all of the code into a single file. However there are a number of cases with the generated bundles will contain `import` statements.
- **Asset imports** — When importing an unrecognized file type like `*.svg`, the bundler defers to the [`file` loader](/docs/bundler/loaders#file), which copies the file into `outdir` as is. The import is converted into a variable
- **Asset imports** — When importing an unrecognized file type like `*.svg`, the bundler defers to the [`file` loader](https://bun.sh/docs/bundler/loaders#file), which copies the file into `outdir` as is. The import is converted into a variable
- **External modules** — Files and modules can be marked as [`external`](#external), in which case they will not be included in the bundle. Instead, the `import` statement will be left in the final bundle.
- **Chunking**. When [`splitting`](#splitting) is enabled, the bundler may generate separate "chunk" files that represent code that is shared among multiple entrypoints.
@@ -1148,7 +1148,7 @@ Each artifact also contains the following properties:
---
- `loader`
- The loader was used to interpret the file. See [Bundler > Loaders](/docs/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader.
- The loader was used to interpret the file. See [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) to see how Bun maps file extensions to the appropriate built-in loader.
---
@@ -1212,7 +1212,7 @@ $ bun build ./cli.tsx --outfile mycli --compile
$ ./mycli
```
Refer to [Bundler > Executables](/docs/bundler/executables) for complete documentation.
Refer to [Bundler > Executables](https://bun.sh/docs/bundler/executables) for complete documentation.
## Logs and errors

View File

@@ -2,7 +2,7 @@ The Bun bundler implements a set of default loaders out of the box. As a rule of
`.js` `.cjs` `.mjs` `.mts` `.cts` `.ts` `.tsx` `.jsx` `.toml` `.json` `.txt` `.wasm` `.node`
Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](/docs/bundler/plugins) that extend Bun with custom loaders.
Bun uses the file extension to determine which built-in _loader_ should be used to parse the file. Every loader has a name, such as `js`, `tsx`, or `json`. These names are used when building [plugins](https://bun.sh/docs/bundler/plugins) that extend Bun with custom loaders.
## Built-in loaders
@@ -182,7 +182,7 @@ In the bundler, `.node` files are handled using the [`file`](#file) loader.
**SQLite loader**. `with { "type": "sqlite" }` import attribute
In the runtime and bundler, SQLite databases can be directly imported. This will load the database using [`bun:sqlite`](/docs/api/sqlite).
In the runtime and bundler, SQLite databases can be directly imported. This will load the database using [`bun:sqlite`](https://bun.sh/docs/api/sqlite).
```ts
import db from "./my.db" with { type: "sqlite" };
@@ -199,7 +199,7 @@ You can change this behavior with the `"embed"` attribute:
import db from "./my.db" with { type: "sqlite", embed: "true" };
```
When using a [standalone executable](/docs/bundler/executables), the database is embedded into the single-file executable.
When using a [standalone executable](https://bun.sh/docs/bundler/executables), the database is embedded into the single-file executable.
Otherwise, the database to embed is copied into the `outdir` with a hashed filename.
@@ -207,7 +207,7 @@ Otherwise, the database to embed is copied into the `outdir` with a hashed filen
**Bun Shell loader**. Default for `.sh` files
This loader is used to parse [Bun Shell](/docs/runtime/shell) scripts. It's only supported when starting Bun itself, so it's not available in the bundler or in the runtime.
This loader is used to parse [Bun Shell](https://bun.sh/docs/runtime/shell) scripts. It's only supported when starting Bun itself, so it's not available in the bundler or in the runtime.
```sh
$ bun run ./script.sh
@@ -263,7 +263,7 @@ If a value is specified for `publicPath`, the import will use value as a prefix
{% /table %}
{% callout %}
The location and file name of the copied file is determined by the value of [`naming.asset`](/docs/bundler#naming).
The location and file name of the copied file is determined by the value of [`naming.asset`](https://bun.sh/docs/bundler#naming).
{% /callout %}
This loader is copied into the `outdir` as-is. The name of the copied file is determined using the value of `naming.asset`.

View File

@@ -2,7 +2,7 @@ Bun provides a universal plugin API that can be used to extend both the _runtime
Plugins intercept imports and perform custom loading logic: reading files, transpiling code, etc. They can be used to add support for additional file types, like `.scss` or `.yaml`. In the context of Bun's bundler, plugins can be used to implement framework-level features like CSS extraction, macros, and client-server code co-location.
For more complete documentation of the Plugin API, see [Runtime > Plugins](/docs/runtime/plugins).
For more complete documentation of the Plugin API, see [Runtime > Plugins](https://bun.sh/docs/runtime/plugins).
## Usage

View File

@@ -2,7 +2,7 @@ Bun's bundler API is inspired heavily by [esbuild](https://esbuild.github.io/).
There are a few behavioral differences to note.
- **Bundling by default**. Unlike esbuild, Bun _always bundles by default_. This is why the `--bundle` flag isn't necessary in the Bun example. To transpile each file individually, use [`Bun.Transpiler`](/docs/api/transpiler).
- **Bundling by default**. Unlike esbuild, Bun _always bundles by default_. This is why the `--bundle` flag isn't necessary in the Bun example. To transpile each file individually, use [`Bun.Transpiler`](https://bun.sh/docs/api/transpiler).
- **It's just a bundler**. Unlike esbuild, Bun's bundler does not include a built-in development server or file watcher. It's just a bundler. The bundler is intended for use in conjunction with `Bun.serve` and other runtime APIs to achieve the same effect. As such, all options relating to HTTP/file watching are not applicable.
## Performance
@@ -65,7 +65,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `--loader:.ext=loader`
- `--loader .ext:loader`
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
The syntax for `--loader` is slightly different.
@@ -475,7 +475,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `bundle`
- n/a
- Always `true`. Use [`Bun.Transpiler`](/docs/api/transpiler) to transpile without bundling.
- Always `true`. Use [`Bun.Transpiler`](https://bun.sh/docs/api/transpiler) to transpile without bundling.
---
@@ -636,7 +636,7 @@ In Bun's CLI, simple boolean flags like `--minify` do not accept an argument. Ot
- `loader`
- `loader`
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
- Bun supports a different set of built-in loaders than esbuild; see [Bundler > Loaders](https://bun.sh/docs/bundler/loaders) for a complete reference. The esbuild loaders `dataurl`, `binary`, `base64`, `copy`, and `empty` are not yet implemented.
---
@@ -892,7 +892,7 @@ const myPlugin: BunPlugin = {
};
```
The `builder` object provides some methods for hooking into parts of the bundling process. Bun implements `onResolve` and `onLoad`; it does not yet implement the esbuild hooks `onStart`, `onEnd`, and `onDispose`, and `resolve` utilities. `initialOptions` is partially implemented, being read-only and only having a subset of esbuild's options; use [`config`](/docs/bundler/plugins) (same thing but with Bun's `BuildConfig` format) instead.
The `builder` object provides some methods for hooking into parts of the bundling process. Bun implements `onResolve` and `onLoad`; it does not yet implement the esbuild hooks `onStart`, `onEnd`, and `onDispose`, and `resolve` utilities. `initialOptions` is partially implemented, being read-only and only having a subset of esbuild's options; use [`config`](https://bun.sh/docs/bundler/plugins) (same thing but with Bun's `BuildConfig` format) instead.
```ts
import type { BunPlugin } from "bun";

View File

@@ -4,7 +4,7 @@
Template a new Bun project with `bun create`. This is a flexible command that can be used to create a new project with a `create-<template>` npm package, a GitHub repo, or a local template.
If you're looking to create a brand new empty project, use [`bun init`](/docs/cli/init).
If you're looking to create a brand new empty project, use [`bun init`](https://bun.sh/docs/cli/init).
## From `npm`

View File

@@ -18,13 +18,12 @@ bun dev
Using `--filter`, you can run the `dev` script in both packages at once:
```bash
bun --filter '*' dev
bun --filter '*' dev
```
Both commands will be run in parallel, and you will see a nice terminal UI showing their respective outputs:
![Terminal Output](https://github.com/oven-sh/bun/assets/48869301/2a103e42-9921-4c33-948f-a1ad6e6bac71)
## Matching
`--filter` accepts a pattern to match specific packages, either by name or by path. Patterns have full support for glob syntax.
@@ -39,7 +38,7 @@ Path patterns are specified by starting the pattern with `./`, and will select a
## Workspaces
Filters respect your [workspace configuration](/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
Filters respect your [workspace configuration](https://bun.sh/docs/install/workspaces): If you have a `package.json` file that specifies which packages are part of the workspace,
`--filter` will be restricted to only these packages. Also, in a workspace you can use `--filter` to run scripts in packages that are located anywhere in the workspace:
```bash
@@ -52,7 +51,7 @@ bun run --filter foo myscript
```
## Dependency Order
Bun will respect package dependency order when running scripts. Say you have a package `foo` that depends on another package `bar` in your workspace, and both packages have a `build` script. When you run `bun --filter '*' build`, you will notice that `foo` will only start running once `bar` is done.
### Cyclic Dependencies

View File

@@ -68,7 +68,7 @@ $ bun install --concurrent-scripts 5
## Workspaces
Bun supports `"workspaces"` in package.json. For complete documentation refer to [Package manager > Workspaces](/docs/install/workspaces).
Bun supports `"workspaces"` in package.json. For complete documentation refer to [Package manager > Workspaces](https://bun.sh/docs/install/workspaces).
```json#package.json
{
@@ -83,7 +83,7 @@ Bun supports `"workspaces"` in package.json. For complete documentation refer to
## Overrides and resolutions
Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](/docs/install/overrides) for complete documentation.
Bun supports npm's `"overrides"` and Yarn's `"resolutions"` in `package.json`. These are mechanisms for specifying a version range for _metadependencies_—the dependencies of your dependencies. Refer to [Package manager > Overrides and resolutions](https://bun.sh/docs/install/overrides) for complete documentation.
```json-diff#package.json
{
@@ -128,7 +128,7 @@ For reproducible installs, use `--frozen-lockfile`. This will install the exact
$ bun install --frozen-lockfile
```
For more information on Bun's binary lockfile `bun.lockb`, refer to [Package manager > Lockfile](/docs/install/lockfile).
For more information on Bun's binary lockfile `bun.lockb`, refer to [Package manager > Lockfile](https://bun.sh/docs/install/lockfile).
## Dry run
@@ -140,7 +140,7 @@ $ bun install --dry-run
## Non-npm dependencies
Bun supports installing dependencies from Git, GitHub, and local or remotely-hosted tarballs. For complete documentation refer to [Package manager > Git, GitHub, and tarball dependencies](/docs/cli/add).
Bun supports installing dependencies from Git, GitHub, and local or remotely-hosted tarballs. For complete documentation refer to [Package manager > Git, GitHub, and tarball dependencies](https://bun.sh/docs/cli/add).
```json#package.json
{

View File

@@ -1,6 +1,6 @@
An alias for `bun patch --commit` to maintain compatibility with pnpm.
You must prepare the package for patching with [`bun patch <pkg>`](/docs/cli/patch) first.
To get started with patch, first prepare the package for patching with [`bun patch <pkg>`](https://bun.sh/docs/install/patch).
### `--patches-dir`

View File

@@ -156,13 +156,15 @@ $ bun run --bun vite
in monorepos containing multiple packages, you can use the `--filter` argument to execute scripts in many packages at once.
Use `bun run --filter <name_pattern> <script>` to execute `<script>` in all packages whose name matches `<name_pattern>`.
For example, if you have subdirectories containing packages named `foo`, `bar` and `baz`, running
For example, if you have subdirectories containing packages named `foo`, `bar` and `baz`, running
```bash
bun run --filter 'ba*' <script>
```
will execute `<script>` in both `bar` and `baz`, but not in `foo`.
Find more details in the docs page for [filter](/docs/cli/filter).
Find more details in the docs page for [filter](https://bun.sh/docs/cli/filter).
## `bun run -` to pipe code from stdin

View File

@@ -17,7 +17,7 @@ Bun aims for compatibility with Jest, but not everything is implemented. To trac
$ bun test
```
Tests are written in JavaScript or TypeScript with a Jest-like API. Refer to [Writing tests](/docs/test/writing) for full documentation.
Tests are written in JavaScript or TypeScript with a Jest-like API. Refer to [Writing tests](https://bun.sh/docs/test/writing) for full documentation.
```ts#math.test.ts
import { expect, test } from "bun:test";
@@ -53,7 +53,7 @@ To run a specific file in the test runner, make sure the path starts with `./` o
$ bun test ./test/specific-file.test.ts
```
The test runner runs all tests in a single process. It loads all `--preload` scripts (see [Lifecycle](/docs/test/lifecycle) for details), then runs all tests. If a test fails, the test runner will exit with a non-zero exit code.
The test runner runs all tests in a single process. It loads all `--preload` scripts (see [Lifecycle](https://bun.sh/docs/test/lifecycle) for details), then runs all tests. If a test fails, the test runner will exit with a non-zero exit code.
## Timeouts
@@ -109,7 +109,7 @@ These hooks can be defined inside test files, or in a separate file that is prel
$ bun test --preload ./setup.ts
```
See [Test > Lifecycle](/docs/test/lifecycle) for complete documentation.
See [Test > Lifecycle](https://bun.sh/docs/test/lifecycle) for complete documentation.
## Mocks
@@ -137,7 +137,7 @@ Alternatively, you can use `jest.fn()`, it behaves identically.
+ const random = jest.fn(() => Math.random());
```
See [Test > Mocks](/docs/test/mocks) for complete documentation.
See [Test > Mocks](https://bun.sh/docs/test/mocks) for complete documentation.
## Snapshot testing
@@ -158,7 +158,7 @@ To update snapshots, use the `--update-snapshots` flag.
$ bun test --update-snapshots
```
See [Test > Snapshots](/docs/test/snapshots) for complete documentation.
See [Test > Snapshots](https://bun.sh/docs/test/snapshots) for complete documentation.
## UI & DOM testing
@@ -168,7 +168,7 @@ Bun is compatible with popular UI testing libraries:
- [DOM Testing Library](https://testing-library.com/docs/dom-testing-library/intro/)
- [React Testing Library](https://testing-library.com/docs/react-testing-library/intro)
See [Test > DOM Testing](/docs/test/dom) for complete documentation.
See [Test > DOM Testing](https://bun.sh/docs/test/dom) for complete documentation.
## Performance

View File

@@ -19,10 +19,10 @@ app.listen(port, () => {
});
```
Bun implements the [`node:http`](https://nodejs.org/api/http.html) and [`node:https`](https://nodejs.org/api/https.html) modules that these libraries rely on. These modules can also be used directly, though [`Bun.serve`](/docs/api/http) is recommended for most use cases.
Bun implements the [`node:http`](https://nodejs.org/api/http.html) and [`node:https`](https://nodejs.org/api/https.html) modules that these libraries rely on. These modules can also be used directly, though [`Bun.serve`](https://bun.sh/docs/api/http) is recommended for most use cases.
{% callout %}
**Note** — Refer to the [Runtime > Node.js APIs](/docs/runtime/nodejs-apis#node-http) page for more detailed compatibility information.
**Note** — Refer to the [Runtime > Node.js APIs](https://bun.sh/docs/runtime/nodejs-apis#node-http) page for more detailed compatibility information.
{% /callout %}
```ts

View File

@@ -36,7 +36,7 @@ function Div(props: {className: string;}) {
### Server-side rendering
To server-side render (SSR) React in an [HTTP server](/docs/api/http):
To server-side render (SSR) React in an [HTTP server](https://bun.sh/docs/api/http):
```tsx#ssr.tsx
import {renderToReadableStream} from 'react-dom/server';

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