Compare commits

..

202 Commits

Author SHA1 Message Date
Jarred Sumner
c907da5c18 Update SetupWebKit.cmake 2024-10-15 19:18:42 -07:00
Ciro Spaciari
1a08cfcd6b fix h2 tests failures (#14598) 2024-10-15 18:36:23 -07:00
Meghan Denny
06e733cc64 ci: run clang-format on .h files too (#14597)
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-10-15 16:54:49 -07:00
Ciro Spaciari
409e674526 feat(node:http2) Implement HTTP2 server support (#14286)
Co-authored-by: cirospaciari <cirospaciari@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-15 16:28:21 -07:00
Meghan Denny
d15eadaa2c tsconfig.json: update excludes (#14578) 2024-10-15 15:39:09 -07:00
dave caruso
5532e1af10 feat(bake): hot-reloading error modal (#14573) 2024-10-15 00:02:58 -07:00
Meghan Denny
68e6304c73 node:child_process: 'ineherit' stdio should make getters be null (#14576) 2024-10-14 23:41:34 -07:00
Meghan Denny
709cd95c30 test: use isWindows from harness (#14577) 2024-10-14 21:19:09 -07:00
Meghan Denny
3830b0c499 more passing node buffer tests (#14371) 2024-10-14 20:22:14 -07:00
Meghan Denny
291b59eb19 bun-types: small fixes (#12794) 2024-10-14 20:15:03 -07:00
190n
035f97ba13 WIP: nuke EventSource as it doesn't work anyway (#14421) 2024-10-14 19:55:06 -07:00
huseeiin
fef9555f82 fix typo. constributors -> contributors (#14531) 2024-10-14 19:50:17 -07:00
Meghan Denny
ae0106b651 delete legacy node test runner (#14572) 2024-10-14 17:31:34 -07:00
Meghan Denny
355dc56db0 scripts/runner.node.mjs: print list of failing tests when run locally (#14571) 2024-10-14 17:22:06 -07:00
Jarred Sumner
5fc53353fb Allow disabling keep-alive (#14569)
Co-authored-by: Ciro Spaciari <ciro.spaciari@gmail.com>
2024-10-14 16:58:42 -07:00
dave caruso
d2fe1ce1c8 feat(bake): handle bundle errors, re-assemble full client payloads, initial error modal (#14504) 2024-10-14 16:49:38 -07:00
Jarred Sumner
29d287261b Fix several bugs when printing exceptions from Error.captureStackTrace (#14548) 2024-10-14 13:43:06 -07:00
Sebastian
6dbd679c06 docs: fix typo (#14565) 2024-10-14 13:29:28 -07:00
Meghan Denny
a5006a13a8 fetch-tcp-stress.test.ts: todo failing on macos ci (#14514) 2024-10-14 12:48:42 -07:00
Meghan Denny
bebf762bcf streams.test.js: todo failing macos test (#14513) 2024-10-14 12:48:04 -07:00
Minsoo Choo
e6ea389e4e Next.js dev server now runs on Bun (#14566) 2024-10-14 12:11:30 -07:00
Timo Sand
47ff4748bd Remove duplicate in import-json.md (#14521) 2024-10-13 15:34:38 +11:00
Don Isaac
09b031d044 fix(parser): uncaught mismatch between JSX opening/closing tags (#14528) 2024-10-12 19:49:45 -07:00
Zack Radisic
6b8fd718c2 Various CSS stuff (#14499)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-12 07:00:20 -07:00
Jarred Sumner
9ed3858e40 Some types and docs 2024-10-12 06:19:46 -07:00
Dylan Conway
6cf9c41d1f fix(install): ensure read permissions when extracting files (#14511) 2024-10-12 02:37:51 -07:00
Dylan Conway
183a8f61d8 fix bun-build-api.test.ts (#14503) 2024-10-12 00:48:22 -07:00
Jarred Sumner
85fbd1e273 we really need a merge queue 2024-10-11 21:51:40 -07:00
Mathieu Schroeter
9744684b10 Attempt to add support for iterate() with SQLite statements (#14361) 2024-10-11 21:42:59 -07:00
Jarred Sumner
43a5c4a044 Implement Bun.inspect.table (#14486) 2024-10-11 21:35:49 -07:00
Dylan Conway
d3323c84bb fix(publish): missing bins bugfix (#14488)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-11 21:28:47 -07:00
Jarred Sumner
f870293d30 Add timeout warning (#14478) 2024-10-11 21:20:55 -07:00
Jarred Sumner
4c26a257ac Fixes #14398 (#14401) 2024-10-11 21:18:07 -07:00
Jarred Sumner
c77fc5daa0 Implement --drop (#14492)
Co-authored-by: dave caruso <me@paperdave.net>
2024-10-11 20:52:23 -07:00
Dylan Conway
bbb41beadc bump webkit (#14497) 2024-10-11 19:44:53 -07:00
Meghan Denny
3f92ec8af3 fix label in 3-typescript-bug-report.yml (#14502) 2024-10-11 19:39:30 -07:00
Dylan Conway
5fd0a61ae2 CA support for bun install (#14416) 2024-10-11 13:16:26 -07:00
Meghan Denny
9fe6e25372 pm: fix assertion failure when printing lockfile summary after adding git transitive dependency (#14461)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-11 03:43:37 -07:00
190n
50e9be0dc7 Fix napi_value<=>integer conversions and napi_create_empty_array (#14479) 2024-10-10 23:50:39 -07:00
pfg
ba9db6cdb6 Fix console.table for numeric keys (#14484) 2024-10-10 23:50:02 -07:00
Meghan Denny
25fcbed8d1 enhance Buffer.from to support (de)serialization roundtrip (#14201)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-10 22:08:16 -07:00
Meghan Denny
170fafbca9 fix fs-non-number-arguments-throw.test.js (#14312) 2024-10-10 22:07:41 -07:00
Meghan Denny
874c9dbb24 fix fs-open.test.js (#14311) 2024-10-10 22:04:33 -07:00
Jarred Sumner
05f53dc70f Fixes #14464 (#14473) 2024-10-10 21:50:03 -07:00
Meghan Denny
584a8ceb84 enable iterator-helpers in webkit (#14455) 2024-10-10 15:47:59 -07:00
Michael H
05f68d79c8 docs: --conditions flag (#14463) 2024-10-10 04:04:58 -07:00
huseeiin
e650ee7967 Update bun.d.ts (#14429) 2024-10-10 02:35:53 -07:00
190n
50bb5fa1f6 Fix napi_throw_*/napi_create_*_error (#14446) 2024-10-10 02:35:38 -07:00
Dylan Conway
3452f50c96 update webkit (#14449) 2024-10-10 02:35:23 -07:00
snwy
ff476313a8 'let' statements before using statements are now properly converted into 'var' statements (#14260) 2024-10-09 19:14:22 -07:00
Jarred Sumner
def454d859 Bump 2024-10-09 18:20:19 -07:00
Grigory
73537de184 docs(bundler): add missing codetabs closing tag (#14443) 2024-10-09 15:13:42 -07:00
Meghan Denny
1bccd62784 actions: update help text for 'needs repro' label (#14428) 2024-10-09 10:44:31 -07:00
Jarred Sumner
c608a724a6 Update installation.md 2024-10-09 02:36:24 -07:00
Meghan Denny
ca6013acef move .clang-format up a folder so it affects all our c/cpp files (#14400)
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-10-08 23:04:05 -07:00
snwy
05e1832c68 remove function hoisting from _parse (#14419) 2024-10-08 18:04:18 -07:00
Jarred Sumner
7a6d17bb99 chore: Make hash formatter reusable (#14372)
Co-authored-by: dave caruso <me@paperdave.net>
2024-10-08 13:30:17 -07:00
Ashcon Partovi
05fb367c5f Move generated files to codegen/ directory (#14392) 2024-10-08 10:32:16 -07:00
versecafe
7996d06b8f --footer esbuild & rollup style! (#14396)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-10-08 02:32:37 -07:00
Jarred Sumner
a234e067a5 Make .get() ignore Object.prototype instead of using getOwn (#14322) 2024-10-08 00:34:31 -07:00
Meghan Denny
c20901fd4e Update 7-install-crash-report.yml (#14394) 2024-10-07 20:45:30 -07:00
Meghan Denny
0d5eb73db0 test: add missing vm.runInContext stubs (#14341) 2024-10-07 20:38:31 -07:00
Kiwi
87c3b2f8d3 Update lockfile.md - fix typo (#14385) 2024-10-07 20:23:45 -07:00
Meghan Denny
1ce2d0e9f5 fix fs-read-empty-buffer.test.js (#14316) 2024-10-07 19:03:30 -07:00
Meghan Denny
c41ff9da93 fix fs-promises-file-handle-write.test.js (#14315) 2024-10-07 18:26:43 -07:00
190n
b0b38b42ba Return undefined from napi_get_property when property does not exist (#14366) 2024-10-07 18:05:31 -07:00
versecafe
62da730060 add banner, .d.ts, cli, make sourcemap compat, and add tests + docs (#14370) 2024-10-07 18:05:06 -07:00
Dylan Conway
c071415664 add bun pm whoami (#14387) 2024-10-07 17:36:14 -07:00
dave caruso
fc85a2dc92 feat(bake): add dependencies to IncrementalGraph (#14368) 2024-10-07 14:18:26 -07:00
Meghan Denny
c5b1c9e302 ci: shorten label names (#14314) 2024-10-07 11:56:37 -07:00
Jarred Sumner
65a6803093 Fixes #14345 (#14374) 2024-10-05 06:00:17 -07:00
Jarred Sumner
6ca68cab65 Update JSType (#14373) 2024-10-05 03:37:24 -07:00
Jarred Sumner
6645eafa08 do not use std.debug.print 2024-10-05 01:16:45 -07:00
Jarred Sumner
29e1ba044d Make this log better 2024-10-05 00:00:19 -07:00
Dylan Conway
fd15e22d64 comment 2024-10-04 23:38:39 -07:00
Dylan Conway
b2cb3603e2 fix(publish): ignore npm-notice when x-local-cache exists (#14352) 2024-10-04 23:36:34 -07:00
Dylan Conway
a15244a4c9 update webkit (#14364) 2024-10-04 22:32:48 -07:00
Zack Radisic
a01f9d8e1b Integrate CSS with bundler (#14281)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Zack Radisic <zackradisic@Mac.attlocal.net>
Co-authored-by: zackradisic <zackradisic@users.noreply.github.com>
Co-authored-by: Zack Radisic <zackradisic@Zacks-MBP.attlocal.net>
2024-10-04 20:23:10 -07:00
lewismiddleton
3ab3dec34d fix(docs): typo in bundler/index.md (#13370) 2024-10-04 20:21:04 -07:00
Dylan Conway
794e416642 Update CONTRIBUTING.md 2024-10-04 18:54:20 -07:00
Mathias
7885742345 fix segfault when decorating computed property #10887 (#14304) 2024-10-04 18:14:20 -07:00
versecafe
7063116c61 add missing docs for new bun pm commands (#14347) 2024-10-04 15:30:30 -07:00
Meghan Denny
4a5ec261ef node: add more passing tests (#14317) 2024-10-04 11:33:46 -07:00
Ashcon Partovi
e3f4c9fd0b ci: Fix analysis commands (#14356) 2024-10-04 09:13:23 -07:00
Dylan Conway
f307d2a6ef test(publish): ci names in user-agent (#14328) 2024-10-04 00:15:22 -07:00
dave caruso
adc86c773b chore: rename kit -> bake (#14335) 2024-10-03 15:34:53 -07:00
Dylan Conway
15427134e1 update 2024-10-03 15:11:44 -07:00
Dylan Conway
808e58cc4d update 2024-10-03 14:50:23 -07:00
Eric Liu
a375ea94ef docs: fix typo in bun publish (#14334) 2024-10-03 14:03:30 -07:00
Dylan Conway
39b1c0111e add docs for bun publish (#14327) 2024-10-03 03:41:11 -07:00
Jarred Sumner
eda608d629 Tweak how we do symbol versioning for glibc (#14272) 2024-10-03 02:42:28 -07:00
Meghan Denny
9446fd60c9 fix Buffer method aliases not being equal to each other (#14198) 2024-10-03 02:31:23 -07:00
Meghan Denny
8e5255d753 node:stream: fix setDefaultHighWaterMark (#14305) 2024-10-03 02:15:39 -07:00
Meghan Denny
13ca4544f2 enhance INVALID_ARG_TYPE and cleanup some node:buffer error handling (#14200) 2024-10-03 02:13:14 -07:00
Jarred Sumner
4d4dd1c180 Refactor node:module (#14227) 2024-10-03 00:54:56 -07:00
dave caruso
dd6554294e bake: release to canary only (#14258)
Co-authored-by: paperdave <paperdave@users.noreply.github.com>
2024-10-03 00:52:14 -07:00
Dylan Conway
50ed09654f publish help text 2024-10-02 22:57:34 -07:00
190n
0a54c24bd3 Allow throwing exceptions from napi_async_complete_callback (#14302)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-10-02 22:35:45 -07:00
versecafe
b39f49a5b9 remove bun pack in favor of bun pm pack (#14319) 2024-10-02 22:32:42 -07:00
snwy
e8fec640d8 hoisting of exports when there is top level using (#14313) 2024-10-02 22:32:04 -07:00
Ciro Spaciari
25abe67d43 update root certificates to NSS 3.104 (#14276) 2024-10-02 22:29:32 -07:00
Jarred Sumner
5f135a21b3 Update writing.md 2024-10-02 22:28:14 -07:00
Jarred Sumner
b88ed18245 On test timeout, kill any spawned processes (#14310) 2024-10-02 20:55:59 -07:00
Dylan Conway
f374ae6db1 add bun publish (#14215) 2024-10-02 20:47:22 -07:00
Jarred Sumner
94a656bc4f Support bundling .node files in ESM & CJS when targeting Node.js (#14294)
Co-authored-by: Jarred-Sumner <Jarred-Sumner@users.noreply.github.com>
2024-10-02 20:15:29 -07:00
190n
54e177e2f9 Rename internal NapiHandleScope push/pop methods to open/close (#14300) 2024-10-02 15:05:38 -07:00
Meghan Denny
39342e34b1 node: define missing constants (#14211) 2024-10-02 14:35:16 -07:00
Mathias
e1cd7e510e Update CONTRIBUTING.md, fix #14225 (#14303) 2024-10-02 13:44:54 -07:00
Meghan Denny
54a225953b use bun.String.static instead of ZigString when immediately converting to JSValue (#14169) 2024-10-02 13:02:48 -07:00
Meghan Denny
419229d950 add ERR_BUFFER_OUT_OF_BOUNDS to internal/errors (#14195) 2024-10-02 07:59:24 -07:00
Meghan Denny
b8a2a11c6f lazy load these requires so that node:cluster imports faster (#14291) 2024-10-02 02:30:19 -07:00
Meghan Denny
25083a4252 pm: print command name to stdout (#14266) 2024-10-02 02:24:37 -07:00
dave caruso
87424390e1 fix 14248 (#14277) 2024-10-02 02:23:54 -07:00
Dylan Conway
92e66691fa fix bun getcompletes index out of bounds (#14289) 2024-10-02 02:23:36 -07:00
Meghan Denny
edebd6faa3 windows: watcher: that line wasnt meant to go to stdout (#14288) 2024-10-02 00:26:20 -07:00
Meghan Denny
531d78aa97 BunProcess: dont use for-loop for isSignalName (#14285) 2024-10-01 23:42:52 -07:00
Meghan Denny
e831bbf4ca node: implement more validators in native code (#14177)
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
2024-10-01 21:55:05 -07:00
dave caruso
9870314ff6 fix 13394 (#14278) 2024-10-01 21:27:50 -07:00
Meghan Denny
e44d10cf17 node: lowercase primitive expectations of ERR_INVALID_ARG_TYPE (#14284) 2024-10-01 20:37:13 -07:00
Ashcon Partovi
db0750e90c cmake: Fix version detection 2024-10-01 15:48:13 -07:00
Ashcon Partovi
98e09efd02 cmake: Improve command detection (#14166) 2024-10-01 15:37:57 -07:00
Ashcon Partovi
944f342072 Revert "Remove old clang-tidy workflow"
This reverts commit 16917f7922.
2024-10-01 15:32:18 -07:00
Ashcon Partovi
16917f7922 Remove old clang-tidy workflow 2024-10-01 15:31:42 -07:00
Ashcon Partovi
27a157b6c1 Improve command detection in CMake 2024-10-01 13:50:15 -07:00
Jarred Sumner
07fd814629 Update index.md 2024-10-01 04:32:02 -07:00
Jarred Sumner
e348fef1c6 Update index.md 2024-10-01 04:26:19 -07:00
Jarred Sumner
68b910cbd9 Update index.md 2024-10-01 04:25:30 -07:00
Meghan Denny
e2f20d794f clang-format: add InsertNewlineAtEOF (#14267)
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-10-01 03:49:10 -07:00
Jarred Sumner
faa524bf67 Fix missing va_end call 2024-10-01 02:06:56 -07:00
Meghan Denny
016ebf7b9b cmake: only run prettier explicitly (#14228) 2024-09-30 23:43:29 -07:00
Jarred Sumner
2f7ff95e5c Introduce bytecode caching, polish "cjs" bundler output format (#14232)
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
2024-09-30 22:37:42 -07:00
Meghan Denny
857a472033 ci: fix build error (#14262) 2024-09-30 22:20:21 -07:00
Jarred Sumner
7720d23da1 Make v8 stack trace parser code more careful (#14205) 2024-09-30 19:09:14 -07:00
Dylan Conway
ecc3e5e187 fix 14250 (#14256) 2024-09-30 19:08:13 -07:00
snwy
dcaaeecfa3 allow importing of files with top level awaits in bundler (#14218)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-30 16:50:50 -07:00
dave caruso
9ab51983b8 chore: make watcher use an anyopaque pointer context (#14224) 2024-09-28 01:44:55 -07:00
Jarred Sumner
af82a446df Support hmac in Bun.CryptoHasher (#14210) 2024-09-27 23:33:22 -07:00
190n
dd12715071 Propagate exceptions in napi_run_script (#14222) 2024-09-27 22:27:57 -07:00
dave caruso
514d37b3d2 kit: implement server components dev server (#14025) 2024-09-27 20:53:39 -07:00
Jarred Sumner
d09df1af47 Deflake a test 2024-09-27 14:22:59 -07:00
Meghan Denny
05afe42f31 fix Buffer.fill with a non-null empty fill including uninitialized bytes (#14199) 2024-09-27 02:50:32 -07:00
Meghan Denny
123b5219e0 include code in detached buffer error for Buffer.isUtf8 and Buffer.isAscii (#14197) 2024-09-27 02:49:38 -07:00
Meghan Denny
7113206a7d fix MAX_STRING_LENGTH constant value (#14196) 2024-09-27 02:48:04 -07:00
Andres Kalle
89fc3ef34d types: clarified parameter name (#14209) 2024-09-27 02:09:37 -07:00
Meghan Denny
392a58b0ed remove duplicate root.h includes (#14194) 2024-09-26 22:01:05 -07:00
Ciro Spaciari
02fb802b25 add req.json leak test (#14191) 2024-09-26 22:00:40 -07:00
Meghan Denny
69d33bb1d0 fix small leak in node:process.execArgv getter (#14154) 2024-09-26 17:10:14 -07:00
190n
4e51f7d85b Refactoring and bug fixes in the V8 API (#13754)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-26 16:54:37 -07:00
Robert Shuford
5e97fb8d97 Support reading from $HOME/.npmrc (#13990) 2024-09-26 14:41:28 -07:00
Meghan Denny
d42c032eec cleanup some error handling in BunProcess (#14178) 2024-09-26 14:20:35 -07:00
Jarred Sumner
afe974a175 Update color.md 2024-09-26 13:47:09 -07:00
Zack Radisic
274e5a2022 CSS Parser (#14122)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-26 13:39:26 -07:00
Jarred Sumner
18822b9f45 Support AbortSignal in Bun.spawn (#14180) 2024-09-26 10:54:54 -07:00
Meghan Denny
7b058e24ff fix memory leak in Bun.shellEscape return value (#14130) 2024-09-25 18:13:28 -07:00
Meghan Denny
ec7078a006 dont leak the address string in UDPSocket.addressToString (#14127) 2024-09-25 18:12:32 -07:00
snwy
af12ff104a fix utf8 handling when importing json (#14168) 2024-09-25 17:50:11 -07:00
Meghan Denny
80db770521 rework node:zlib to match internal js api and properly support async writes (#14079)
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-09-25 15:55:53 -07:00
Meghan Denny
c4c3019cb0 no need to cache protocol in NewServer when its statically known (#14128) 2024-09-25 14:47:50 -07:00
Ashcon Partovi
1f0f666210 Fix zig build again (#14165) 2024-09-25 13:02:56 -07:00
Ashcon Partovi
73f90c3359 Remove unused .docker directory 2024-09-25 12:43:47 -07:00
Ashcon Partovi
291a50aff5 Fix zig build (#14163) 2024-09-25 12:42:47 -07:00
Ashcon Partovi
128c658f91 Use ephemeral vendor path for now 2024-09-25 11:19:42 -07:00
Ashcon Partovi
a87341b239 Fix download zig script 2024-09-25 10:55:22 -07:00
Ashcon Partovi
3ab990e615 cmake: Fix zig build issue 2024-09-25 10:45:43 -07:00
Ashcon Partovi
ecf5d79e01 bun run clang-tidy (#14162) 2024-09-25 10:31:38 -07:00
Ashcon Partovi
b9a56a6087 cmake: Add target to download Node.js headers 2024-09-25 09:39:06 -07:00
Jarred Sumner
5722ae8d04 Make prototype pollution attacks harder in most Bun APIs that accept objects (#14119) 2024-09-25 01:16:29 -07:00
Meghan Denny
2856267fda add missing defers to JSBundler.Plugin.hasAnyMatches (#14129) 2024-09-25 01:15:32 -07:00
Meghan Denny
da70c891df dont leak the message when node:util.getSystemErrorName is passed an invalid code (#14126) 2024-09-25 01:13:22 -07:00
Wilmer Paulino
6f27b5559d Switch RSA asymmetric sign implementation to BoringSSL (#14125) 2024-09-25 01:12:50 -07:00
Ashcon Partovi
117e1b3883 bun run prettier (#14153)
Co-authored-by: Electroid <Electroid@users.noreply.github.com>
2024-09-24 22:46:18 -07:00
Ashcon Partovi
1e1025ca37 bun run zig-format (#14152) 2024-09-24 22:10:12 -07:00
Ashcon Partovi
30dc72c17b bun run clang-format (#14148)
Co-authored-by: Electroid <Electroid@users.noreply.github.com>
2024-09-24 20:39:29 -07:00
Jarred Sumner
17d719fa4e Make server.stop return a Promise that fulfills when all opened connections are closed (#14120) 2024-09-24 14:07:29 -07:00
Meghan Denny
0ac2a7da0a dont leak return value in crash_handler jsGetFeaturesAsVLQ (#14131) 2024-09-24 12:26:58 -07:00
Dylan Conway
9d23ce16ec fix(install): relative paths to tarballs in workspaces (#14121) 2024-09-23 22:44:24 -07:00
Ashcon Partovi
7d94c59545 Publish VSCode extension 2024-09-23 16:05:12 -07:00
Meghan Denny
33075394a4 cpp: always return empty JSValue value after throwing exception (#13935)
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
2024-09-23 13:53:08 -07:00
Jarred Sumner
ff9560c82a Fix unbalanced ref count involving file descriptors passed to Bun.connect (#14107) 2024-09-23 10:28:50 -07:00
Jarred Sumner
2f8c20ef82 Implement --registry CLI flag in bun install (#14090) 2024-09-22 21:27:33 -07:00
Jarred Sumner
d05070dbfd Fix regression from #13414 (#14092) 2024-09-22 16:02:49 -07:00
Jarred Sumner
1244907a92 Bump 2024-09-22 02:53:21 -07:00
Jarred Sumner
81e5ee26bd Don't re-create the FIFO in streams every time (#14088) 2024-09-22 02:13:11 -07:00
Jarred Sumner
27e7aa7923 Update from-npm-install-to-bun-install.md 2024-09-22 00:33:41 -07:00
Jarred Sumner
f89623aa5e Update from-npm-install-to-bun-install.md 2024-09-22 00:31:01 -07:00
Jarred Sumner
3cc51ceb98 Update from-npm-install-to-bun-install.md 2024-09-22 00:30:08 -07:00
Jarred Sumner
e944bb3638 Update from-npm-install-to-bun-install.md 2024-09-22 00:29:23 -07:00
Jarred Sumner
797750ef42 Update from-npm-install-to-bun-install.md 2024-09-22 00:27:47 -07:00
Jarred Sumner
c267d76f05 Update from-npm-install-to-bun-install.md 2024-09-22 00:25:47 -07:00
Jarred Sumner
c5c1e8ff3a Update from-npm-install-to-bun-install.md 2024-09-22 00:24:56 -07:00
Jarred Sumner
1eab8ec107 Update from-npm-install-to-bun-install.md 2024-09-22 00:23:44 -07:00
Jarred Sumner
60d8c8ad4c Update from-npm-install-to-bun-install.md 2024-09-22 00:17:41 -07:00
Jarred Sumner
dba108f8c4 Update from-npm-install-to-bun-install.md 2024-09-21 23:32:34 -07:00
Jarred Sumner
18251e1b60 Create from-npm-install-to-bun-install.md 2024-09-21 23:29:16 -07:00
Xmarmalade
0bc21b3ddf docs: add ccache for Windows System Dependencies (#14080) 2024-09-21 01:35:01 -07:00
Jarred Sumner
c298b23c45 Fix process.cwd on windows (#14081) 2024-09-21 01:32:23 -07:00
snwy
722e3fa481 fix for windows debug support (#14048)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2024-09-21 00:20:33 -07:00
Jarred Sumner
3fc092d23f Fix ci issue 2024-09-20 22:13:16 -07:00
Jarred Sumner
6e0847ca49 Fix searching for lld in $PATH on Linux 2024-09-20 22:09:21 -07:00
Jarred Sumner
7a190de2f1 Fix upload-s3.ts script 2024-09-20 21:34:50 -07:00
Dylan Conway
57a1d7b4ee update 2024-09-20 20:38:52 -07:00
Dylan Conway
3e0e99176a udpate 2024-09-20 20:37:49 -07:00
1099 changed files with 133453 additions and 31012 deletions

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

40
.github/workflows/clang-format.yml vendored Normal file
View File

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

40
.github/workflows/clang-tidy.yml vendored Normal file
View File

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

View File

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

View File

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

View File

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

36
.github/workflows/prettier-format.yml vendored Normal file
View File

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

View File

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

View File

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

33
.github/workflows/zig-format.yml vendored Normal file
View File

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

3
.gitignore vendored
View File

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

View File

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

6
.vscode/launch.json generated vendored
View File

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

View File

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

52
.vscode/tasks.json vendored Normal file
View File

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

View File

@@ -30,6 +30,7 @@ include(CompilerFlags)
# --- Tools ---
include(SetupGit)
include(SetupBuildkite)
include(SetupBun)
include(SetupEsbuild)
@@ -38,25 +39,13 @@ include(SetupRust)
# --- Targets ---
include(BuildBoringSSL)
include(BuildBrotli)
include(BuildCares)
include(BuildLibDeflate)
include(BuildLibuv)
include(BuildLolHtml)
include(BuildLshpack)
include(BuildMimalloc)
include(BuildPicoHTTPParser)
include(BuildTinyCC)
include(BuildSQLite)
include(BuildWebKit)
include(BuildZlib)
include(BuildLibArchive) # must be loaded after zlib
include(BuildZstd)
include(BuildBun)
# --- Analysis ---
include(RunClangFormat)
include(RunClangTidy)
include(RunZigFormat)
if(ENABLE_ANALYSIS)
include(RunClangFormat)
include(RunClangTidy)
include(RunZigFormat)
include(RunPrettier)
endif()

View File

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

2
LATEST
View File

@@ -1 +1 @@
1.1.27
1.1.30

View File

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

Binary file not shown.

View File

@@ -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(245));
bench("RSA sign RSA_PKCS1_PADDING round-trip", () => {
const sig = crypto.privateEncrypt(keyPair.privateKey, plaintext);
crypto.publicDecrypt(keyPair.publicKey, sig);
});
await run();

View File

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

25
bench/snippets/color.mjs Normal file
View File

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

View File

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

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,6 +1,8 @@
# clang: https://clang.llvm.org/docs/CommandGuide/clang.html
# clang-cl: https://clang.llvm.org/docs/UsersManual.html#id11
# --- Macros ---
macro(setb variable)
if(${variable})
set(${variable} ON)
@@ -9,20 +11,20 @@ macro(setb variable)
endif()
endmacro()
set(bvariables WIN32 APPLE UNIX LINUX)
foreach(bvariable ${bvariables})
setb(${bvariable})
set(targets WIN32 APPLE UNIX LINUX)
foreach(target ${targets})
setb(${target})
endforeach()
# --- CPU target ---
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|ARM64|aarch64|AARCH64")
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|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")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64")
if(ENABLE_BASELINE)
register_compiler_flags(-march=nehalem)
else()
@@ -33,7 +35,6 @@ else()
endif()
# --- MSVC runtime ---
if(WIN32)
register_compiler_flags(
DESCRIPTION "Use static MSVC runtime"
@@ -44,7 +45,6 @@ if(WIN32)
endif()
# --- Optimization level ---
if(DEBUG)
register_compiler_flags(
DESCRIPTION "Disable optimization"
@@ -66,7 +66,6 @@ else()
endif()
# --- Debug level ---
if(WIN32)
register_compiler_flags(
DESCRIPTION "Enable debug symbols (.pdb)"
@@ -98,7 +97,6 @@ endif()
# -fno-eliminate-unused-debug-types # Don't eliminate unused debug symbols
# --- C/C++ flags ---
register_compiler_flags(
DESCRIPTION "Disable C/C++ exceptions"
-fno-exceptions ${UNIX}
@@ -106,8 +104,8 @@ register_compiler_flags(
)
register_compiler_flags(
LANGUAGE CXX
DESCRIPTION "Disable C++ static destructors"
LANGUAGES CXX
-Xclang ${WIN32}
-fno-c++-static-destructors
)
@@ -151,9 +149,9 @@ register_compiler_flags(
/Gw ${WIN32}
)
# This causes libarchive to fail on macOS, with the error:
# having this enabled in debug mode on macOS >=14 causes libarchive to fail to configure with the error:
# > pid_t doesn't exist on this platform?
if((DEBUG AND LINUX) OR ((NOT DEBUG) AND UNIX))
if((DEBUG AND LINUX) OR((NOT DEBUG) AND UNIX))
register_compiler_flags(
DESCRIPTION "Emit an address-significance table"
-faddrsig
@@ -173,7 +171,6 @@ if(WIN32)
endif()
# --- Linker flags ---
if(LINUX)
register_linker_flags(
DESCRIPTION "Disable relocation read-only (RELRO)"
@@ -185,7 +182,6 @@ endif()
# Note: This is a helpful guide about assertions:
# https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++
if(ENABLE_ASSERTIONS)
register_compiler_flags(
DESCRIPTION "Do not eliminate null-pointer checks"
@@ -231,7 +227,6 @@ else()
endif()
# --- Diagnostics ---
if(UNIX)
register_compiler_flags(
DESCRIPTION "Enable color diagnostics"
@@ -245,7 +240,6 @@ register_compiler_flags(
)
# --- LTO ---
if(ENABLE_LTO)
register_compiler_flags(
DESCRIPTION "Enable link-time optimization (LTO)"
@@ -255,8 +249,8 @@ if(ENABLE_LTO)
if(UNIX)
register_compiler_flags(
LANGUAGE CXX
DESCRIPTION "Enable virtual tables"
LANGUAGES CXX
-fforce-emit-vtables
-fwhole-program-vtables
)
@@ -271,7 +265,6 @@ if(ENABLE_LTO)
endif()
# --- Remapping ---
if(UNIX)
register_compiler_flags(
DESCRIPTION "Remap source files"
@@ -289,12 +282,6 @@ if(ENABLE_VALGRIND AND ARCH STREQUAL "x64")
register_compiler_definitions(__SSE4_2__=0)
endif()
if(APPLE)
# The $NOCANCEL variants of various system calls are activated by compiling
# with __DARWIN_NON_CANCELABLE, which prevents them from being pthread cancellation points.
register_compiler_definitions(__DARWIN_NON_CANCELABLE=1)
endif()
# --- Other ---
# Workaround for CMake and clang-cl bug.

File diff suppressed because it is too large Load Diff

View File

@@ -2,8 +2,8 @@ if(NOT CMAKE_SYSTEM_NAME OR NOT CMAKE_SYSTEM_PROCESSOR)
message(FATAL_ERROR "CMake included this file before project() was called")
endif()
optionx(BUN_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(BUN_LINK_ONLY BOOL "If only the linking step should be built" DEFAULT OFF)
optionx(BUN_CPP_ONLY BOOL "If only the C++ part of Bun should be built" DEFAULT OFF)
optionx(BUILDKITE BOOL "If Buildkite is enabled" DEFAULT OFF)
optionx(GITHUB_ACTIONS BOOL "If GitHub Actions is enabled" DEFAULT OFF)
@@ -91,6 +91,8 @@ if(LINUX)
optionx(ENABLE_VALGRIND BOOL "If Valgrind support should be enabled" DEFAULT OFF)
endif()
optionx(ENABLE_PRETTIER BOOL "If prettier should be ran" DEFAULT OFF)
if(USE_VALGRIND AND NOT USE_BASELINE)
message(WARNING "If valgrind is enabled, baseline must also be enabled")
setx(USE_BASELINE ON)
@@ -143,4 +145,15 @@ endif()
optionx(USE_STATIC_LIBATOMIC BOOL "If libatomic should be statically linked" DEFAULT ${DEFAULT_STATIC_LIBATOMIC})
if(APPLE)
set(DEFAULT_WEBKIT_ICU OFF)
else()
set(DEFAULT_WEBKIT_ICU ON)
endif()
optionx(USE_WEBKIT_ICU BOOL "Use the ICU libraries from WebKit" DEFAULT ${DEFAULT_WEBKIT_ICU})
optionx(ERROR_LIMIT STRING "Maximum number of errors to show when compiling C++ code" DEFAULT "100")
list(APPEND CMAKE_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -125,7 +125,5 @@ else()
file(RENAME ${DOWNLOAD_TMP_FILE} ${DOWNLOAD_PATH})
endif()
get_filename_component(DOWNLOAD_FILENAME ${DOWNLOAD_PATH} NAME)
message(STATUS "Saved ${DOWNLOAD_FILENAME}")
file(REMOVE_RECURSE ${DOWNLOAD_TMP_PATH})
message(STATUS "Saved ${DOWNLOAD_PATH}")

View File

@@ -1,21 +1,8 @@
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")
if(NOT ZIG_PATH OR NOT ZIG_COMMIT OR NOT ZIG_VERSION)
message(FATAL_ERROR "ZIG_PATH, ZIG_COMMIT, and ZIG_VERSION are required")
endif()
if(CMAKE_HOST_APPLE)
@@ -51,7 +38,6 @@ else()
set(ZIG_FILENAME ${ZIG_NAME}.tar.xz)
endif()
message(STATUS "Downloading ${ZIG_EXE} ${ZIG_VERSION} on ${ZIG_OS} ${ZIG_ARCH}...")
set(ZIG_DOWNLOAD_URL https://ziglang.org/download/${ZIG_VERSION}/${ZIG_FILENAME})
execute_process(
@@ -72,7 +58,7 @@ if(NOT ZIG_DOWNLOAD_RESULT EQUAL 0)
endif()
if(NOT EXISTS ${ZIG_PATH}/${ZIG_EXE})
message(FATAL_ERROR "Download failed: executable not found: \"${ZIG_PATH}/${ZIG_EXE}\"")
message(FATAL_ERROR "Executable not found: \"${ZIG_PATH}/${ZIG_EXE}\"")
endif()
# Tools like VSCode need a stable path to the zig executable, on both Unix and Windows
@@ -81,31 +67,30 @@ 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}...")
set(ZIG_REPOSITORY_PATH ${ZIG_PATH}/repository)
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
)
execute_process(
COMMAND
${CMAKE_COMMAND}
-DGIT_PATH=${ZIG_REPOSITORY_PATH}
-DGIT_REPOSITORY=oven-sh/zig
-DGIT_COMMIT=${ZIG_COMMIT}
-P ${CMAKE_CURRENT_LIST_DIR}/GitClone.cmake
ERROR_STRIP_TRAILING_WHITESPACE
ERROR_VARIABLE
ZIG_REPOSITORY_ERROR
RESULT_VARIABLE
ZIG_REPOSITORY_RESULT
)
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")
if(NOT ZIG_REPOSITORY_RESULT EQUAL 0)
message(FATAL_ERROR "Download failed: ${ZIG_REPOSITORY_ERROR}")
endif()
message(STATUS "Saved ${ZIG_EXE}")
file(REMOVE_RECURSE ${ZIG_PATH}/lib)
# Use copy_directory instead of file(RENAME) because there were
# race conditions in CI where some files were not copied.
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${ZIG_REPOSITORY_PATH}/lib ${ZIG_PATH}/lib)
file(REMOVE_RECURSE ${ZIG_REPOSITORY_PATH})

View File

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

View File

@@ -1,43 +1,31 @@
register_vendor_target(brotli)
register_repository(
NAME
${brotli}
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
TAG
v1.1.0
)
# 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
)
if(LINUX AND CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|X86_64|x64|X64|amd64|AMD64" AND NOT ENABLE_BASELINE)
set(BROTLI_CMAKE_ARGS "-DCMAKE_C_FLAGS=-fno-lto")
endif()
register_cmake_command(
TARGET
brotli
LIBRARIES
brotlicommon
brotlidec
brotlienc
ARGS
-DBUILD_SHARED_LIBS=OFF
-DBROTLI_BUILD_TOOLS=OFF
-DBROTLI_EMSCRIPTEN=OFF
-DBROTLI_DISABLE_TESTS=ON
${BROTLI_CMAKE_ARGS}
INCLUDES
c/include
)

View File

@@ -12,10 +12,25 @@ else()
set(bunStrip bun)
endif()
# Some commands use this path, and some do not.
# In the future, change those commands so that generated files are written to this path.
set(bunExe ${bun}${CMAKE_EXECUTABLE_SUFFIX})
if(bunStrip)
set(bunStripExe ${bunStrip}${CMAKE_EXECUTABLE_SUFFIX})
set(buns ${bun} ${bunStrip})
else()
set(buns ${bun})
endif()
optionx(CODEGEN_PATH FILEPATH "Path to the codegen directory" DEFAULT ${BUILD_PATH}/codegen)
if(RELEASE OR CI)
set(DEFAULT_CODEGEN_EMBED ON)
else()
set(DEFAULT_CODEGEN_EMBED OFF)
endif()
optionx(CODEGEN_EMBED BOOL "If codegen files should be embedded in the binary" DEFAULT ${DEFAULT_CODEGEN_EMBED})
if((NOT DEFINED CONFIGURE_DEPENDS AND NOT CI) OR CONFIGURE_DEPENDS)
set(CONFIGURE_DEPENDS "CONFIGURE_DEPENDS")
else()
@@ -24,37 +39,6 @@ endif()
# --- Codegen ---
set(BUN_ZIG_IDENTIFIER_SOURCE ${CWD}/src/js_lexer)
set(BUN_ZIG_IDENTIFIER_SCRIPT ${BUN_ZIG_IDENTIFIER_SOURCE}/identifier_data.zig)
file(GLOB BUN_ZIG_IDENTIFIER_SOURCES ${CONFIGURE_DEPENDS}
${BUN_ZIG_IDENTIFIER_SCRIPT}
${BUN_ZIG_IDENTIFIER_SOURCE}/*.zig
)
set(BUN_ZIG_IDENTIFIER_OUTPUTS
${BUN_ZIG_IDENTIFIER_SOURCE}/id_continue_bitset.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_continue_bitset.meta.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_start_bitset.blob
${BUN_ZIG_IDENTIFIER_SOURCE}/id_start_bitset.meta.blob
)
register_command(
TARGET
bun-identifier-data
COMMENT
"Generating src/js_lexer/*.blob"
COMMAND
${ZIG_EXECUTABLE}
run
${CMAKE_ZIG_FLAGS}
${BUN_ZIG_IDENTIFIER_SCRIPT}
SOURCES
${BUN_ZIG_IDENTIFIER_SOURCES}
OUTPUTS
${BUN_ZIG_IDENTIFIER_OUTPUTS}
)
set(BUN_ERROR_SOURCE ${CWD}/packages/bun-error)
file(GLOB BUN_ERROR_SOURCES ${CONFIGURE_DEPENDS}
@@ -65,7 +49,7 @@ file(GLOB BUN_ERROR_SOURCES ${CONFIGURE_DEPENDS}
${BUN_ERROR_SOURCE}/img/*
)
set(BUN_ERROR_OUTPUT ${BUN_ERROR_SOURCE}/dist)
set(BUN_ERROR_OUTPUT ${CODEGEN_PATH}/bun-error)
set(BUN_ERROR_OUTPUTS
${BUN_ERROR_OUTPUT}/index.js
${BUN_ERROR_OUTPUT}/bun-error.css
@@ -103,13 +87,13 @@ register_command(
)
set(BUN_FALLBACK_DECODER_SOURCE ${CWD}/src/fallback.ts)
set(BUN_FALLBACK_DECODER_OUTPUT ${CWD}/src/fallback.out.js)
set(BUN_FALLBACK_DECODER_OUTPUT ${CODEGEN_PATH}/fallback-decoder.js)
register_command(
TARGET
bun-fallback-decoder
COMMENT
"Building src/fallback.out.js"
"Building fallback-decoder.js"
COMMAND
${ESBUILD_EXECUTABLE} ${ESBUILD_ARGS}
${BUN_FALLBACK_DECODER_SOURCE}
@@ -126,7 +110,7 @@ register_command(
)
set(BUN_RUNTIME_JS_SOURCE ${CWD}/src/runtime.bun.js)
set(BUN_RUNTIME_JS_OUTPUT ${CWD}/src/runtime.out.js)
set(BUN_RUNTIME_JS_OUTPUT ${CODEGEN_PATH}/runtime.out.js)
register_command(
TARGET
@@ -156,7 +140,7 @@ file(GLOB BUN_NODE_FALLBACKS_SOURCES ${CONFIGURE_DEPENDS}
${BUN_NODE_FALLBACKS_SOURCE}/*.js
)
set(BUN_NODE_FALLBACKS_OUTPUT ${BUN_NODE_FALLBACKS_SOURCE}/out)
set(BUN_NODE_FALLBACKS_OUTPUT ${CODEGEN_PATH}/node-fallbacks)
set(BUN_NODE_FALLBACKS_OUTPUTS)
foreach(source ${BUN_NODE_FALLBACKS_SOURCES})
get_filename_component(filename ${source} NAME)
@@ -176,7 +160,7 @@ register_command(
TARGET
bun-node-fallbacks
COMMENT
"Building src/node-fallbacks/*.js"
"Building node-fallbacks/*.js"
CWD
${BUN_NODE_FALLBACKS_SOURCE}
COMMAND
@@ -313,40 +297,41 @@ register_command(
${BUN_JAVASCRIPT_OUTPUTS}
)
set(BUN_KIT_RUNTIME_CODEGEN_SCRIPT ${CWD}/src/codegen/kit-codegen.ts)
set(BUN_BAKE_RUNTIME_CODEGEN_SCRIPT ${CWD}/src/codegen/bake-codegen.ts)
file(GLOB_RECURSE BUN_KIT_RUNTIME_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/kit/*.ts
${CWD}/src/kit/*/*.ts
file(GLOB_RECURSE BUN_BAKE_RUNTIME_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/bake/*.ts
${CWD}/src/bake/*/*.ts
${CWD}/src/bake/*/*.css
)
list(APPEND BUN_KIT_RUNTIME_CODEGEN_SOURCES
list(APPEND BUN_BAKE_RUNTIME_CODEGEN_SOURCES
${CWD}/src/bun.js/bindings/InternalModuleRegistry.cpp
)
set(BUN_KIT_RUNTIME_OUTPUTS
${CODEGEN_PATH}/kit_empty_file
${CODEGEN_PATH}/kit.client.js
${CODEGEN_PATH}/kit.server.js
set(BUN_BAKE_RUNTIME_OUTPUTS
${CODEGEN_PATH}/bake.client.js
${CODEGEN_PATH}/bake.server.js
)
register_command(
TARGET
bun-kit-codegen
bun-bake-codegen
COMMENT
"Bundling Kit Runtime"
COMMAND
${BUN_EXECUTABLE}
run
${BUN_KIT_RUNTIME_CODEGEN_SCRIPT}
${BUN_BAKE_RUNTIME_CODEGEN_SCRIPT}
--debug=${DEBUG}
--codegen_root=${CODEGEN_PATH}
SOURCES
${BUN_KIT_RUNTIME_SOURCES}
${BUN_KIT_RUNTIME_CODEGEN_SOURCES}
${BUN_KIT_RUNTIME_CODEGEN_SCRIPT}
${BUN_BAKE_RUNTIME_SOURCES}
${BUN_BAKE_RUNTIME_CODEGEN_SOURCES}
${BUN_BAKE_RUNTIME_CODEGEN_SCRIPT}
OUTPUTS
${BUN_KIT_RUNTIME_OUTPUTS}
${CODEGEN_PATH}/bake_empty_file
${BUN_BAKE_RUNTIME_OUTPUTS}
)
set(BUN_JS_SINK_SCRIPT ${CWD}/src/codegen/generate-jssink.ts)
@@ -387,6 +372,7 @@ set(BUN_OBJECT_LUT_SOURCES
${CWD}/src/bun.js/bindings/BunProcess.cpp
${CWD}/src/bun.js/bindings/ProcessBindingConstants.cpp
${CWD}/src/bun.js/bindings/ProcessBindingNatives.cpp
${CWD}/src/bun.js/modules/NodeModuleModule.cpp
)
set(BUN_OBJECT_LUT_OUTPUTS
@@ -396,8 +382,10 @@ set(BUN_OBJECT_LUT_OUTPUTS
${CODEGEN_PATH}/BunProcess.lut.h
${CODEGEN_PATH}/ProcessBindingConstants.lut.h
${CODEGEN_PATH}/ProcessBindingNatives.lut.h
${CODEGEN_PATH}/NodeModuleModule.lut.h
)
macro(WEBKIT_ADD_SOURCE_DEPENDENCIES _source _deps)
set(_tmp)
get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
@@ -463,19 +451,6 @@ WEBKIT_ADD_SOURCE_DEPENDENCIES(
${CODEGEN_PATH}/InternalModuleRegistryConstants.h
)
if(WIN32)
if(ENABLE_CANARY)
set(Bun_VERSION_WITH_TAG ${VERSION}-canary.${CANARY_REVISION})
else()
set(Bun_VERSION_WITH_TAG ${VERSION})
endif()
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
configure_file(
${CWD}/src/windows-app-info.rc
${CODEGEN_PATH}/windows-app-info.rc
)
endif()
# --- Zig ---
file(GLOB_RECURSE BUN_ZIG_SOURCES ${CONFIGURE_DEPENDS}
@@ -489,7 +464,6 @@ list(APPEND BUN_ZIG_SOURCES
)
set(BUN_ZIG_GENERATED_SOURCES
${BUN_ZIG_IDENTIFIER_OUTPUTS}
${BUN_ERROR_OUTPUTS}
${BUN_FALLBACK_DECODER_OUTPUT}
${BUN_RUNTIME_JS_OUTPUT}
@@ -501,9 +475,9 @@ set(BUN_ZIG_GENERATED_SOURCES
# In debug builds, these are not embedded, but rather referenced at runtime.
if (DEBUG)
list(APPEND BUN_ZIG_GENERATED_SOURCES ${CODEGEN_PATH}/kit_empty_file)
list(APPEND BUN_ZIG_GENERATED_SOURCES ${CODEGEN_PATH}/bake_empty_file)
else()
list(APPEND BUN_ZIG_GENERATED_SOURCES ${BUN_KIT_RUNTIME_OUTPUTS})
list(APPEND BUN_ZIG_GENERATED_SOURCES ${BUN_BAKE_RUNTIME_OUTPUTS})
endif()
set(BUN_ZIG_OUTPUT ${BUILD_PATH}/bun-zig.o)
@@ -545,18 +519,21 @@ register_command(
-Dsha=${REVISION}
-Dreported_nodejs_version=${NODEJS_VERSION}
-Dcanary=${CANARY_REVISION}
-Dgenerated-code=${CODEGEN_PATH}
-Dcodegen_path=${CODEGEN_PATH}
-Dcodegen_embed=$<IF:$<BOOL:${CODEGEN_EMBED}>,true,false>
ARTIFACTS
${BUN_ZIG_OUTPUT}
TARGETS
clone-zig
SOURCES
${BUN_ZIG_SOURCES}
${BUN_ZIG_GENERATED_SOURCES}
)
set_property(TARGET bun-zig PROPERTY JOB_POOL compile_pool)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${CWD}/build.zig)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "build.zig")
# --- C/C++ Object ---
# --- C/C++ Sources ---
set(BUN_USOCKETS_SOURCE ${CWD}/packages/bun-usockets)
@@ -569,7 +546,8 @@ file(GLOB BUN_CXX_SOURCES ${CONFIGURE_DEPENDS}
${CWD}/src/bun.js/bindings/webcrypto/*.cpp
${CWD}/src/bun.js/bindings/webcrypto/*/*.cpp
${CWD}/src/bun.js/bindings/v8/*.cpp
${CWD}/src/kit/*.cpp
${CWD}/src/bun.js/bindings/v8/shim/*.cpp
${CWD}/src/bake/*.cpp
${CWD}/src/deps/*.cpp
${BUN_USOCKETS_SOURCE}/src/crypto/*.cpp
)
@@ -581,15 +559,42 @@ file(GLOB BUN_C_SOURCES ${CONFIGURE_DEPENDS}
${BUN_USOCKETS_SOURCE}/src/crypto/*.c
)
list(APPEND BUN_C_SOURCES ${VENDOR_PATH}/picohttpparser/picohttpparser.c)
if(WIN32)
list(APPEND BUN_C_SOURCES ${CWD}/src/bun.js/bindings/windows/musl-memmem.c)
endif()
register_repository(
NAME
picohttpparser
REPOSITORY
h2o/picohttpparser
COMMIT
066d2b1e9ab820703db0837a7255d92d30f0c9f5
OUTPUTS
picohttpparser.c
)
set(NODEJS_HEADERS_PATH ${VENDOR_PATH}/nodejs)
register_command(
TARGET
bun-node-headers
COMMENT
"Download node ${NODEJS_VERSION} headers"
COMMAND
${CMAKE_COMMAND}
-DDOWNLOAD_PATH=${NODEJS_HEADERS_PATH}
-DDOWNLOAD_URL=https://nodejs.org/dist/v${NODEJS_VERSION}/node-v${NODEJS_VERSION}-headers.tar.gz
-P ${CWD}/cmake/scripts/DownloadUrl.cmake
OUTPUTS
${NODEJS_HEADERS_PATH}/include/node/node_version.h
)
list(APPEND BUN_CPP_SOURCES
${BUN_C_SOURCES}
${BUN_CXX_SOURCES}
${VENDOR_PATH}/picohttpparser/picohttpparser.c
${NODEJS_HEADERS_PATH}/include/node/node_version.h
${BUN_ZIG_GENERATED_CLASSES_OUTPUTS}
${BUN_JS_SINK_OUTPUTS}
${BUN_JAVASCRIPT_OUTPUTS}
@@ -597,12 +602,22 @@ list(APPEND BUN_CPP_SOURCES
)
if(WIN32)
if(ENABLE_CANARY)
set(Bun_VERSION_WITH_TAG ${VERSION}-canary.${CANARY_REVISION})
else()
set(Bun_VERSION_WITH_TAG ${VERSION})
endif()
set(BUN_ICO_PATH ${CWD}/src/bun.ico)
configure_file(
${CWD}/src/windows-app-info.rc
${CODEGEN_PATH}/windows-app-info.rc
)
list(APPEND BUN_CPP_SOURCES ${CODEGEN_PATH}/windows-app-info.rc)
endif()
# --- Executable ---
set(BUN_CPP_OUTPUT ${BUILD_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}${bun}${CMAKE_STATIC_LIBRARY_SUFFIX})
set(BUN_EXE_OUTPUT ${BUILD_PATH}/${CMAKE_EXECUTABLE_PREFIX}${bun}${CMAKE_EXECUTABLE_SUFFIX})
set(BUN_EXE_STRIP_OUTPUT ${BUILD_PATH}/${CMAKE_EXECUTABLE_PREFIX}bun${CMAKE_EXECUTABLE_SUFFIX})
if(BUN_LINK_ONLY)
add_executable(${bun} ${BUN_CPP_OUTPUT} ${BUN_ZIG_OUTPUT})
@@ -610,21 +625,30 @@ if(BUN_LINK_ONLY)
target_link_libraries(${bun} PRIVATE ${BUN_CPP_OUTPUT})
elseif(BUN_CPP_ONLY)
add_library(${bun} STATIC ${BUN_CPP_SOURCES})
upload_artifacts(
TARGET ${bun}
${BUN_CPP_OUTPUT}
register_command(
TARGET
${bun}
TARGET_PHASE
POST_BUILD
COMMENT
"Uploading ${bun}"
COMMAND
${CMAKE_COMMAND} -E true
ARTIFACTS
${BUN_CPP_OUTPUT}
)
else()
add_executable(${bun} ${BUN_CPP_SOURCES})
target_link_libraries(${bun} PRIVATE ${BUN_ZIG_OUTPUT})
upload_artifacts(
TARGET ${bun}
${BUN_EXE_OUTPUT}
)
endif()
if(NOT bun STREQUAL "bun")
add_custom_target(bun DEPENDS ${bun})
endif()
# --- C/C++ Properties ---
set_target_properties(${bun} PROPERTIES
OUTPUT_NAME ${bun}
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS YES
@@ -634,17 +658,6 @@ set_target_properties(${bun} PROPERTIES
VISIBILITY_INLINES_HIDDEN YES
)
if(BUN_LINK_ONLY)
set_target_properties(${bun} PROPERTIES
OUTPUT_NAME ${bun}
LINKER_LANGUAGE CXX
)
endif()
if(NOT bun STREQUAL "bun")
add_custom_target(bun DEPENDS ${bun})
endif()
# --- C/C++ Includes ---
if(WIN32)
@@ -659,6 +672,7 @@ target_include_directories(${bun} PRIVATE
${CWD}/src/bun.js/bindings/webcore
${CWD}/src/bun.js/bindings/webcrypto
${CWD}/src/bun.js/bindings/sqlite
${CWD}/src/bun.js/bindings/v8
${CWD}/src/bun.js/modules
${CWD}/src/js/builtins
${CWD}/src/napi
@@ -666,6 +680,7 @@ target_include_directories(${bun} PRIVATE
${CODEGEN_PATH}
${VENDOR_PATH}
${VENDOR_PATH}/picohttpparser
${NODEJS_HEADERS_PATH}/include
)
# --- C/C++ Definitions ---
@@ -699,6 +714,7 @@ target_compile_definitions(${bun} PRIVATE
WITH_BORINGSSL=1
STATICALLY_LINKED_WITH_JavaScriptCore=1
STATICALLY_LINKED_WITH_BMALLOC=1
BUILDING_WITH_CMAKE=1
JSC_OBJC_API_ENABLED=0
BUN_SINGLE_THREADED_PER_VM_ENTRY_SCOPE=1
NAPI_EXPERIMENTAL=ON
@@ -715,6 +731,7 @@ if(DEBUG AND NOT CI)
)
endif()
# --- Compiler options ---
if(NOT WIN32)
@@ -839,26 +856,33 @@ else()
-Wl,--as-needed
-Wl,--gc-sections
-Wl,-z,stack-size=12800000
-Wl,--wrap=fcntl
-Wl,--wrap=fcntl64
-Wl,--wrap=stat64
-Wl,--wrap=pow
-Wl,--wrap=cosf
-Wl,--wrap=exp
-Wl,--wrap=expf
-Wl,--wrap=log
-Wl,--wrap=log2
-Wl,--wrap=lstat
-Wl,--wrap=stat64
-Wl,--wrap=stat
-Wl,--wrap=fcntl
-Wl,--wrap=fcntl64
-Wl,--wrap=fmod
-Wl,--wrap=fmodf
-Wl,--wrap=fstat
-Wl,--wrap=fstatat
-Wl,--wrap=lstat64
-Wl,--wrap=fstat64
-Wl,--wrap=fstatat
-Wl,--wrap=fstatat64
-Wl,--wrap=log
-Wl,--wrap=log10f
-Wl,--wrap=log2
-Wl,--wrap=log2f
-Wl,--wrap=logf
-Wl,--wrap=lstat
-Wl,--wrap=lstat64
-Wl,--wrap=mknod
-Wl,--wrap=mknodat
-Wl,--wrap=pow
-Wl,--wrap=sincosf
-Wl,--wrap=sinf
-Wl,--wrap=stat
-Wl,--wrap=stat64
-Wl,--wrap=statx
-Wl,--wrap=fmod
-Wl,--wrap=tanf
-Wl,--compress-debug-sections=zlib
-Wl,-z,lazy
-Wl,-z,norelro
@@ -889,6 +913,8 @@ set_target_properties(${bun} PROPERTIES LINK_DEPENDS ${BUN_SYMBOLS_PATH})
# --- WebKit ---
include(SetupWebKit)
if(WIN32)
if(DEBUG)
target_link_libraries(${bun} PRIVATE
@@ -925,38 +951,34 @@ endif()
# --- Dependencies ---
register_link_targets(
TARGET ${bun}
${boringssl}
${brotli}
${cares}
${libarchive}
${libdeflate}
${libuv} ${WIN32}
${lolhtml}
${lshpack}
${mimalloc}
${tinycc}
${sqlite} ${USE_STATIC_SQLITE}
${webkit}
${zlib}
${zstd}
set(BUN_DEPENDENCIES
BoringSSL
Brotli
Cares
LibDeflate
LolHtml
Lshpack
Mimalloc
TinyCC
Zlib
LibArchive # must be loaded after zlib
Zstd
)
register_includes(
TARGET ${bun}
${${picohttpparser}_CWD}
${${boringssl}_CWD}/include
${${brotli}_CWD}/c/include
${${cares}_CWD}/include
${${libarchive}_CWD}/include
${${libdeflate}_CWD}
${${libuv}_CWD}/include ${WIN32}
${${lshpack}_CWD}
${${lshpack}_CWD}/compat/queue ${WIN32}
${${mimalloc}_CWD}/include
${${zlib}_CWD}
)
if(WIN32)
list(APPEND BUN_DEPENDENCIES Libuv)
endif()
if(USE_STATIC_SQLITE)
list(APPEND BUN_DEPENDENCIES SQLite)
endif()
foreach(dependency ${BUN_DEPENDENCIES})
include(Build${dependency})
endforeach()
list(TRANSFORM BUN_DEPENDENCIES TOLOWER OUTPUT_VARIABLE BUN_TARGETS)
add_custom_target(dependencies DEPENDS ${BUN_TARGETS})
if(APPLE)
target_link_libraries(${bun} PRIVATE icucore resolv)
@@ -1002,12 +1024,6 @@ endif()
# --- Packaging ---
if(bunStrip)
set(buns ${bun} ${bunStrip})
else()
set(buns ${bun})
endif()
if(NOT BUN_CPP_ONLY)
if(bunStrip)
register_command(
@@ -1019,15 +1035,15 @@ if(NOT BUN_CPP_ONLY)
"Stripping ${bun}"
COMMAND
${CMAKE_STRIP}
${BUN_EXE_OUTPUT}
${bunExe}
--strip-all
--strip-debug
--discard-all
-o ${BUN_EXE_STRIP_OUTPUT}
-o ${bunStripExe}
CWD
${BUILD_PATH}
OUTPUTS
${BUN_EXE_STRIP_OUTPUT}
${BUILD_PATH}/${bunStripExe}
)
endif()
@@ -1040,9 +1056,9 @@ if(NOT BUN_CPP_ONLY)
"Testing ${bun}"
COMMAND
${CMAKE_COMMAND}
-E env BUN_DEBUG_QUIET_LOGS=1
${BUN_EXE_OUTPUT}
--revision
-E env BUN_DEBUG_QUIET_LOGS=1
${BUILD_PATH}/${bunExe}
--revision
CWD
${BUILD_PATH}
)
@@ -1062,7 +1078,7 @@ if(NOT BUN_CPP_ONLY)
BUN_GARBAGE_COLLECTOR_LEVEL=1
BUN_DEBUG_QUIET_LOGS=1
BUN_FEATURE_FLAG_INTERNAL_FOR_TESTING=1
${BUN_EXE_OUTPUT}
${BUILD_PATH}/${bunExe}
${BUN_FEATURES_SCRIPT}
CWD
${BUILD_PATH}
@@ -1071,7 +1087,7 @@ if(NOT BUN_CPP_ONLY)
)
endif()
if(bunStrip AND APPLE)
if(CMAKE_HOST_APPLE AND bunStrip)
register_command(
TARGET
${bun}
@@ -1101,7 +1117,7 @@ if(NOT BUN_CPP_ONLY)
set(bunTriplet bun-${OS}-${ARCH})
endif()
string(REPLACE bun ${bunTriplet} bunPath ${bun})
set(bunFiles ${BUN_EXE_OUTPUT} features.json)
set(bunFiles ${bunExe} features.json)
if(WIN32)
list(APPEND bunFiles ${bun}.pdb)
elseif(APPLE)
@@ -1138,7 +1154,7 @@ if(NOT BUN_CPP_ONLY)
COMMAND
${CMAKE_COMMAND} -E rm -rf ${bunStripPath} ${bunStripPath}.zip
&& ${CMAKE_COMMAND} -E make_directory ${bunStripPath}
&& ${CMAKE_COMMAND} -E copy ${${BUN_EXE_STRIP_OUTPUT}} ${bunStripPath}
&& ${CMAKE_COMMAND} -E copy ${bunStripExe} ${bunStripPath}
&& ${CMAKE_COMMAND} -E tar cfv ${bunStripPath}.zip --format=zip ${bunStripPath}
&& ${CMAKE_COMMAND} -E rm -rf ${bunStripPath}
CWD

View File

@@ -1,32 +1,27 @@
register_vendor_target(cares)
register_repository(
NAME
${cares}
cares
REPOSITORY
c-ares/c-ares
COMMIT
d1722e6e8acaf10eb73fa995798a9cd421d9f85e
)
register_libraries(
TARGET ${cares}
PATH lib
cares
)
register_cmake_project(
register_cmake_command(
TARGET
${cares}
CMAKE_TARGET
cares
TARGETS
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
ARGS
-DCARES_STATIC=ON
-DCARES_STATIC_PIC=ON # FORCE_PIC was set to 1, but CARES_STATIC_PIC was set to OFF??
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCARES_SHARED=OFF
-DCARES_BUILD_TOOLS=OFF # this was set to ON?
LIB_PATH
lib
LIBRARIES
cares
INCLUDES
include
)

View File

@@ -1,61 +1,53 @@
register_vendor_target(libarchive)
register_repository(
NAME
${libarchive}
libarchive
REPOSITORY
libarchive/libarchive
COMMIT
898dc8319355b7e985f68a9819f182aaed61b53a
)
register_libraries(
TARGET ${libarchive}
PATH libarchive
archive
)
register_cmake_project(
register_cmake_command(
TARGET
${libarchive}
CMAKE_TARGET
libarchive
TARGETS
archive_static
ARGS
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DBUILD_SHARED_LIBS=OFF
-DENABLE_INSTALL=OFF
-DENABLE_TEST=OFF
-DENABLE_WERROR=OFF
-DENABLE_BZIP2=OFF
-DENABLE_CAT=OFF
-DENABLE_EXPAT=OFF
-DENABLE_ICONV=OFF
-DENABLE_LIBB2=OFF
-DENABLE_LibGCC=OFF
-DENABLE_LIBXML2=OFF
-DENABLE_LZ4=OFF
-DENABLE_LZMA=OFF
-DENABLE_LZO=OFF
-DENABLE_MBEDTLS=OFF
-DENABLE_NETTLE=OFF
-DENABLE_OPENSSL=OFF
-DENABLE_PCRE2POSIX=OFF
-DENABLE_PCREPOSIX=OFF
-DENABLE_ZSTD=OFF
# libarchive depends on zlib headers, otherwise it will
# spawn a processes to compress instead of using the library.
-DENABLE_ZLIB=OFF
-DHAVE_ZLIB_H=ON
-DCMAKE_C_FLAGS="-I${VENDOR_PATH}/zlib"
LIB_PATH
libarchive
LIBRARIES
archive
INCLUDES
include
)
register_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})
# Must be loaded after zlib is defined
if(TARGET clone-zlib)
add_dependencies(libarchive clone-zlib)
endif()

View File

@@ -1,30 +1,24 @@
register_vendor_target(libdeflate)
register_repository(
NAME
${libdeflate}
libdeflate
REPOSITORY
ebiggers/libdeflate
COMMIT
dc76454a39e7e83b68c3704b6e3784654f8d5ac5
)
register_libraries(
TARGET ${libdeflate}
deflatestatic ${WIN32}
deflate ${UNIX}
)
register_cmake_project(
register_cmake_command(
TARGET
${libdeflate}
CMAKE_TARGET
libdeflate
TARGETS
libdeflate_static
)
register_cmake_definitions(
TARGET ${libdeflate}
LIBDEFLATE_BUILD_STATIC_LIB=ON
LIBDEFLATE_BUILD_SHARED_LIB=OFF
LIBDEFLATE_BUILD_GZIP=OFF
ARGS
-DLIBDEFLATE_BUILD_STATIC_LIB=ON
-DLIBDEFLATE_BUILD_SHARED_LIB=OFF
-DLIBDEFLATE_BUILD_GZIP=OFF
LIBRARIES
deflatestatic WIN32
deflate UNIX
INCLUDES
.
)

View File

@@ -1,39 +1,29 @@
register_vendor_target(libuv)
register_repository(
NAME
${libuv}
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
)
set(LIBUV_CMAKE_C_FLAGS "/DWIN32 /D_WINDOWS -Wno-int-conversion")
endif()
register_cmake_command(
TARGET
libuv
TARGETS
uv_a
ARGS
-DLIBUV_BUILD_SHARED=OFF
-DLIBUV_BUILD_TESTS=OFF
-DLIBUV_BUILD_BENCH=OFF
-DCMAKE_C_FLAGS=${LIBUV_CMAKE_C_FLAGS}
LIBRARIES
libuv WIN32
uv UNIX
INCLUDES
include
)

View File

@@ -1,50 +1,45 @@
register_vendor_target(lolhtml)
register_repository(
NAME
${lolhtml}
lolhtml
REPOSITORY
cloudflare/lol-html
COMMIT
8d4c273ded322193d017042d1f48df2766b0f88b
)
set(LOLHTML_CWD ${VENDOR_PATH}/lolhtml/c-api)
set(LOLHTML_BUILD_PATH ${BUILD_PATH}/lolhtml)
if(DEBUG)
set(${lolhtml}_BUILD_TYPE debug)
set(LOLHTML_BUILD_TYPE debug)
else()
set(${lolhtml}_BUILD_TYPE release)
set(LOLHTML_BUILD_TYPE release)
endif()
register_libraries(
TARGET ${lolhtml}
PATH ${${lolhtml}_BUILD_TYPE}
VARIABLE ${lolhtml}_LIBRARY
lolhtml
)
set(LOLHTML_LIBRARY ${LOLHTML_BUILD_PATH}/${LOLHTML_BUILD_TYPE}/${CMAKE_STATIC_LIBRARY_PREFIX}lolhtml${CMAKE_STATIC_LIBRARY_SUFFIX})
set(${lolhtml}_BUILD_COMMAND
${CARGO_EXECUTABLE}
build
--target-dir ${${lolhtml}_BUILD_PATH}
set(LOLHTML_BUILD_ARGS
--target-dir ${BUILD_PATH}/lolhtml
)
if(RELEASE)
list(APPEND ${lolhtml}_BUILD_COMMAND --release)
list(APPEND LOLHTML_BUILD_ARGS --release)
endif()
register_command(
TARGET
build-${lolhtml}
lolhtml
CWD
${${lolhtml}_CWD}/c-api
${LOLHTML_CWD}
COMMAND
${${lolhtml}_BUILD_COMMAND}
${CARGO_EXECUTABLE}
build
${LOLHTML_BUILD_ARGS}
ARTIFACTS
${${lolhtml}_LIBRARY}
${LOLHTML_LIBRARY}
)
if(TARGET clone-${lolhtml})
add_dependencies(build-${lolhtml} clone-${lolhtml})
target_link_libraries(${bun} PRIVATE ${LOLHTML_LIBRARY})
if(BUN_LINK_ONLY)
target_sources(${bun} PRIVATE ${LOLHTML_LIBRARY})
endif()
add_dependencies(${lolhtml} build-${lolhtml})

View File

@@ -1,42 +1,33 @@
register_vendor_target(lshpack)
register_repository(
NAME
${lshpack}
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
)
if(WIN32)
set(LSHPACK_INCLUDES . compat/queue)
else()
set(LSHPACK_INCLUDES .)
endif()
register_cmake_command(
TARGET
lshpack
LIBRARIES
ls-hpack
ARGS
-DSHARED=OFF
-DLSHPACK_XXH=ON
# There are linking errors when built with non-Release
# Undefined symbols for architecture arm64:
# "___asan_handle_no_return", referenced from:
# _lshpack_enc_get_static_nameval in libls-hpack.a(lshpack.c.o)
# _lshpack_enc_get_static_name in libls-hpack.a(lshpack.c.o)
# _update_hash in libls-hpack.a(lshpack.c.o)
-DCMAKE_BUILD_TYPE=Release
INCLUDES
${LSHPACK_INCLUDES}
)

View File

@@ -1,63 +1,60 @@
register_vendor_target(mimalloc)
register_repository(
NAME
${mimalloc}
mimalloc
REPOSITORY
oven-sh/mimalloc
COMMIT
4c283af60cdae205df5a872530c77e2a6a307d43
)
set(MIMALLOC_CMAKE_ARGS
-DMI_BUILD_STATIC=ON
-DMI_BUILD_OBJECT=ON
-DMI_BUILD_SHARED=OFF
-DMI_BUILD_TESTS=OFF
-DMI_USE_CXX=ON
-DMI_OVERRIDE=OFF
-DMI_OSX_ZONE=OFF
-DMI_OSX_INTERPOSE=OFF
-DMI_SKIP_COLLECT_ON_EXIT=ON
)
if(DEBUG)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_DEBUG_FULL=ON)
endif()
if(ENABLE_VALGRIND)
list(APPEND MIMALLOC_CMAKE_ARGS -DMI_VALGRIND=ON)
endif()
if(WIN32)
if(DEBUG)
set(MIMALLOC_LIBRARY mimalloc-static-debug)
else()
set(MIMALLOC_LIBRARY mimalloc-static)
endif()
elseif(DEBUG)
set(MIMALLOC_LIBRARY mimalloc-debug)
else()
set(MIMALLOC_LIBRARY mimalloc)
endif()
# Workaround for linker issue on macOS and Linux x64
# https://github.com/microsoft/mimalloc/issues/512
if(APPLE OR (LINUX AND NOT DEBUG))
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}
)
set(MIMALLOC_LIBRARY CMakeFiles/mimalloc-obj.dir/src/static.c.o)
endif()
register_cmake_project(
register_cmake_command(
TARGET
${mimalloc}
CMAKE_TARGETS
mimalloc
TARGETS
mimalloc-static
mimalloc-obj
ARGS
${MIMALLOC_CMAKE_ARGS}
LIBRARIES
${MIMALLOC_LIBRARY}
INCLUDES
include
)
register_cmake_definitions(
TARGET ${mimalloc}
MI_BUILD_STATIC=ON
MI_BUILD_OBJECT=ON
MI_BUILD_SHARED=OFF
MI_BUILD_TESTS=OFF
MI_USE_CXX=ON
MI_OVERRIDE=OFF
MI_OSX_ZONE=OFF
MI_OSX_INTERPOSE=OFF
MI_SKIP_COLLECT_ON_EXIT=ON
)
if(ENABLE_ASSERTIONS)
register_cmake_definitions(
TARGET ${mimalloc}
MI_DEBUG_FULL=ON
MI_SHOW_ERRORS=ON
)
if(ENABLE_VALGRIND)
register_cmake_definitions(
TARGET ${mimalloc}
MI_VALGRIND=ON
)
endif()
endif()

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,38 +1,40 @@
register_vendor_target(zlib)
register_repository(
NAME
${zlib}
zlib
REPOSITORY
cloudflare/zlib
COMMIT
886098f3f339617b4243b286f5ed364b9989e245
)
register_libraries(
TARGET ${zlib}
z ${UNIX}
zlib ${WIN32} AND ${RELEASE}
zlibd ${WIN32} AND ${DEBUG}
)
register_cmake_project(
TARGET
${zlib}
CMAKE_TARGET
zlib
)
register_cmake_definitions(
TARGET ${zlib}
BUILD_SHARED_LIBS=OFF
BUILD_EXAMPLES=OFF
)
# https://gitlab.kitware.com/cmake/cmake/-/issues/25755
if(APPLE)
register_compiler_flags(
TARGET ${zlib}
-fno-define-target-os-macros
)
set(ZLIB_CMAKE_C_FLAGS "-fno-define-target-os-macros")
set(ZLIB_CMAKE_CXX_FLAGS "-fno-define-target-os-macros")
endif()
if(WIN32)
if(DEBUG)
set(ZLIB_LIBRARY "zlibd")
else()
set(ZLIB_LIBRARY "zlib")
endif()
else()
set(ZLIB_LIBRARY "z")
endif()
register_cmake_command(
TARGET
zlib
TARGETS
zlib
ARGS
-DBUILD_SHARED_LIBS=OFF
-DBUILD_EXAMPLES=OFF
"-DCMAKE_C_FLAGS=${ZLIB_CMAKE_C_FLAGS}"
"-DCMAKE_CXX_FLAGS=${ZLIB_CMAKE_CXX_FLAGS}"
LIBRARIES
${ZLIB_LIBRARY}
INCLUDES
.
)

View File

@@ -1,34 +1,26 @@
register_vendor_target(zstd)
register_repository(
NAME
${zstd}
zstd
REPOSITORY
facebook/zstd
COMMIT
794ea1b0afca0f020f4e57b6732332231fb23c70
)
register_libraries(
TARGET ${zstd}
PATH lib
zstd_static ${WIN32}
zstd ${UNIX}
)
register_cmake_project(
register_cmake_command(
TARGET
${zstd}
CMAKE_TARGET
zstd
TARGETS
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
ARGS
-Sbuild/cmake
-DZSTD_BUILD_STATIC=ON
-DZSTD_BUILD_PROGRAMS=OFF
-DZSTD_BUILD_TESTS=OFF
-DZSTD_BUILD_CONTRIB=OFF
LIB_PATH
lib
LIBRARIES
zstd_static WIN32
zstd UNIX
)

View File

@@ -1,4 +1,6 @@
if(NOT BUN_LINK_ONLY)
optionx(BUILDKITE_CACHE BOOL "If the build can use Buildkite caches, even if not running in Buildkite" DEFAULT ${BUILDKITE})
if(NOT BUILDKITE_CACHE OR NOT BUN_LINK_ONLY)
return()
endif()
@@ -31,7 +33,7 @@ if(NOT BUILDKITE_BUILD_ID)
endif()
setx(BUILDKITE_BUILD_URL https://buildkite.com/${BUILDKITE_ORGANIZATION_SLUG}/${BUILDKITE_PIPELINE_SLUG}/builds/${BUILDKITE_BUILD_ID})
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/${BUILDKITE_BUILD_ID})
setx(BUILDKITE_BUILD_PATH ${BUILDKITE_BUILDS_PATH}/builds/${BUILDKITE_BUILD_ID})
file(
DOWNLOAD ${BUILDKITE_BUILD_URL}
@@ -123,14 +125,15 @@ foreach(i RANGE ${BUILDKITE_JOBS_MAX_INDEX})
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}
add_custom_command(
COMMENT
"Downloading ${BUILDKITE_ARTIFACT_PATH}"
VERBATIM COMMAND
${BUILDKITE_DOWNLOAD_COMMAND}
WORKING_DIRECTORY
${BUILD_PATH}
OUTPUT
${BUILD_PATH}/${BUILDKITE_ARTIFACT_PATH}
)
endforeach()

View File

@@ -11,11 +11,18 @@ find_command(
COMMAND
ccache
REQUIRED
ON
${CI}
)
setx(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
setx(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_PROGRAM})
if(NOT CCACHE_PROGRAM)
return()
endif()
set(CCACHE_ARGS CMAKE_C_COMPILER_LAUNCHER CMAKE_CXX_COMPILER_LAUNCHER)
foreach(arg ${CCACHE_ARGS})
setx(${arg} ${CCACHE_PROGRAM})
list(APPEND CMAKE_ARGS -D${arg}=${${arg}})
endforeach()
setenv(CCACHE_DIR ${CACHE_PATH}/ccache)
setenv(CCACHE_BASEDIR ${CWD})

View File

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

View File

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

View File

@@ -52,3 +52,8 @@ if(CMAKE_OSX_SYSROOT_ERROR)
endif()
optionx(CMAKE_OSX_SYSROOT STRING "The macOS SDK path to target" DEFAULT ${DEFAULT_CMAKE_OSX_SYSROOT})
list(APPEND CMAKE_ARGS
-DCMAKE_OSX_DEPLOYMENT_TARGET=${CMAKE_OSX_DEPLOYMENT_TARGET}
-DCMAKE_OSX_SYSROOT=${CMAKE_OSX_SYSROOT}
)

View File

@@ -0,0 +1,86 @@
option(WEBKIT_VERSION "The version of WebKit to use")
option(WEBKIT_LOCAL "If a local version of WebKit should be used instead of downloading")
if(NOT WEBKIT_VERSION)
set(WEBKIT_VERSION 428a917f5a38ac4b79799d73497b57e5c62afb36)
endif()
if(WEBKIT_LOCAL)
set(DEFAULT_WEBKIT_PATH ${VENDOR_PATH}/WebKit/WebKitBuild/${CMAKE_BUILD_TYPE})
else()
set(DEFAULT_WEBKIT_PATH ${CACHE_PATH}/webkit-${WEBKIT_VERSION})
endif()
option(WEBKIT_PATH "The path to the WebKit directory")
if(NOT WEBKIT_PATH)
set(WEBKIT_PATH ${DEFAULT_WEBKIT_PATH})
endif()
set(WEBKIT_INCLUDE_PATH ${WEBKIT_PATH}/include)
set(WEBKIT_LIB_PATH ${WEBKIT_PATH}/lib)
if(WEBKIT_LOCAL)
if(EXISTS ${WEBKIT_PATH}/cmakeconfig.h)
# You may need to run:
# make jsc-compile-debug jsc-copy-headers
include_directories(
${WEBKIT_PATH}
${WEBKIT_PATH}/JavaScriptCore/Headers/JavaScriptCore
${WEBKIT_PATH}/JavaScriptCore/PrivateHeaders
${WEBKIT_PATH}/bmalloc/Headers
${WEBKIT_PATH}/WTF/Headers
)
endif()
# After this point, only prebuilt WebKit is supported
return()
endif()
if(EXISTS ${WEBKIT_PATH}/package.json)
file(READ ${WEBKIT_PATH}/package.json WEBKIT_PACKAGE_JSON)
if(WEBKIT_PACKAGE_JSON MATCHES ${WEBKIT_VERSION})
return()
endif()
endif()
if(WIN32)
set(WEBKIT_OS "windows")
elseif(APPLE)
set(WEBKIT_OS "macos")
elseif(UNIX)
set(WEBKIT_OS "linux")
else()
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}")
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
set(WEBKIT_ARCH "arm64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64|x64|AMD64")
set(WEBKIT_ARCH "amd64")
else()
message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
if(DEBUG)
set(WEBKIT_SUFFIX "-debug")
elseif(ENABLE_LTO AND NOT WIN32)
set(WEBKIT_SUFFIX "-lto")
else()
set(WEBKIT_SUFFIX "")
endif()
set(WEBKIT_NAME bun-webkit-${WEBKIT_OS}-${WEBKIT_ARCH}${WEBKIT_SUFFIX})
set(WEBKIT_FILENAME ${WEBKIT_NAME}.tar.gz)
setx(WEBKIT_DOWNLOAD_URL https://github.com/oven-sh/WebKit/releases/download/autobuild-${WEBKIT_VERSION}/${WEBKIT_FILENAME})
file(DOWNLOAD ${WEBKIT_DOWNLOAD_URL} ${CACHE_PATH}/${WEBKIT_FILENAME} SHOW_PROGRESS)
file(ARCHIVE_EXTRACT INPUT ${CACHE_PATH}/${WEBKIT_FILENAME} DESTINATION ${CACHE_PATH} TOUCH)
file(REMOVE ${CACHE_PATH}/${WEBKIT_FILENAME})
file(REMOVE_RECURSE ${WEBKIT_PATH})
file(RENAME ${CACHE_PATH}/bun-webkit ${WEBKIT_PATH})
if(APPLE)
file(REMOVE_RECURSE ${WEBKIT_INCLUDE_PATH}/unicode)
endif()

View File

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

262
docs/api/color.md Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

107
docs/cli/publish.md Normal file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,7 +1,7 @@
{
"private": true,
"name": "bun",
"version": "1.1.29",
"version": "1.1.31",
"workspaces": [
"./packages/bun-types"
],
@@ -21,7 +21,10 @@
"react": "^18.3.1",
"react-dom": "^18.3.1",
"source-map-js": "^1.2.0",
"typescript": "^5.4.5"
"typescript": "^5.4.5",
"caniuse-lite": "^1.0.30001620",
"autoprefixer": "^10.4.19",
"@mdn/browser-compat-data": "~5.5.28"
},
"resolutions": {
"bun-types": "workspace:packages/bun-types"
@@ -40,25 +43,36 @@
"build:release:local": "bun ./scripts/build.mjs -GNinja -DCMAKE_BUILD_TYPE=Release -DWEBKIT_LOCAL=ON -B build/release",
"build:release:with_logs": "cmake . -DCMAKE_BUILD_TYPE=Release -DENABLE_LOGS=true -GNinja -Bbuild-release && ninja -Cbuild-release",
"build:debug-zig-release": "cmake . -DCMAKE_BUILD_TYPE=Release -DZIG_OPTIMIZE=Debug -GNinja -Bbuild-debug-zig-release && ninja -Cbuild-debug-zig-release",
"css-properties": "bun run src/css/properties/generate_properties.ts",
"bump": "bun ./scripts/bump.ts",
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
"fmt": "prettier --config=.prettierrc-ci --write --cache './{.vscode,src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
"fmt:cpp": "bun run build --target clang-format",
"fmt:zig": "bun run build --target zig-format",
"fmt": "bun run prettier",
"fmt:cpp": "bun run clang-format",
"fmt:zig": "bun run zig-format",
"lint": "eslint './**/*.d.ts' --cache",
"lint:fix": "eslint './**/*.d.ts' --cache --fix",
"test": "node scripts/runner.node.mjs ./build/bun-debug",
"test:release": "node scripts/runner.node.mjs ./build-release/bun",
"test": "node scripts/runner.node.mjs --exec-path ./build/debug/bun-debug",
"test:release": "node scripts/runner.node.mjs --exec-path ./build/release/bun",
"banned": "bun packages/bun-internal-test/src/linter.ts",
"zig": "vendor/zig/zig.exe",
"zig:fmt": "bun run fmt:zig",
"zig:fmt": "bun run zig-format",
"zig:check": "bun run zig build check --summary new",
"zig:check-all": "bun run zig build check-all --summary new",
"zig:check-windows": "bun run zig build check-windows --summary new",
"clang-format": "bun run build --target clang-format --fresh",
"clang-format:check": "bun run build --target clang-format-check --fresh",
"clang-tidy": "bun run build --target clang-tidy --fresh",
"clang-tidy:check": "bun run build --target clang-tidy --fresh",
"zig-format": "bun run build --target zig-format --fresh",
"zig-format:check": "bun run build --target zig-format-check --fresh"
"analysis": "bun ./scripts/build.mjs -DCMAKE_BUILD_TYPE=Debug -DENABLE_ANALYSIS=ON -DENABLE_CCACHE=OFF -B build/analysis",
"analysis:no-llvm": "bun run analysis -DENABLE_LLVM=OFF",
"clang-format": "bun run analysis --target clang-format",
"clang-format:check": "bun run analysis --target clang-format-check",
"clang-format:diff": "bun run analysis --target clang-format-diff",
"clang-tidy": "bun run analysis --target clang-tidy",
"clang-tidy:check": "bun run analysis --target clang-tidy-check",
"clang-tidy:diff": "bun run analysis --target clang-tidy-diff",
"zig-format": "bun run analysis:no-llvm --target zig-format",
"zig-format:check": "bun run analysis:no-llvm --target zig-format-check",
"zig-format:diff": "bun run analysis:no-llvm --target zig-format-diff",
"prettier": "bun run analysis:no-llvm --target prettier",
"prettier:check": "bun run analysis:no-llvm --target prettier-check",
"prettier:extra": "bun run analysis:no-llvm --target prettier-extra",
"prettier:diff": "bun run analysis:no-llvm --target prettier-diff"
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

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