Compare commits

...

175 Commits

Author SHA1 Message Date
Ashcon Partovi
83d4d6264e Make executable 2023-10-23 15:14:07 -07:00
dave caruso
20234bc147 stuff 2023-10-20 21:47:55 -07:00
dave caruso
5e72f7f640 add unified sources code (does not work) 2023-10-20 21:05:19 -07:00
dave caruso
d37bb8efd5 more cmake nonsense 2023-10-20 20:01:24 -07:00
dave caruso
f22b56e64b a 2023-10-20 19:21:49 -07:00
dave caruso
2407143c9e Merge remote-tracking branch 'origin/main' into jarred/prepare-for-libuv 2023-10-20 18:37:18 -07:00
dave caruso
9f79fdea57 Merge remote-tracking branch 'origin/ci-test' into jarred/prepare-for-libuv 2023-10-20 18:36:42 -07:00
dave caruso
c271db39e4 okay 2023-10-20 17:35:53 -08:00
dave caruso
bcf027c35c chaos chaos chaos 2023-10-20 18:28:05 -07:00
Ashcon Partovi
071165b737 More changes to Dockerfile 2023-10-20 16:46:28 -07:00
Ashcon Partovi
9cdf695df3 Build 2023-10-20 16:46:28 -07:00
Ashcon Partovi
b6527820f3 New dockerfile 2023-10-20 16:45:55 -07:00
Ashcon Partovi
0646f106f0 Skip llvm 2023-10-20 16:45:55 -07:00
Ashcon Partovi
929c7ae09a Fix postinstal 2023-10-20 16:45:55 -07:00
Ashcon Partovi
4351966b5d add more to ssh 2023-10-20 16:45:55 -07:00
Ashcon Partovi
7055728cfb ssh into github actions 2023-10-20 16:45:55 -07:00
Ashcon Partovi
aed8be20ec bun install 2023-10-20 16:45:55 -07:00
Ashcon Partovi
ef5c2a29e7 Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
93f530c0ba Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
55444cc434 Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
5af35fbbcb Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
f9b7c24015 Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
560e5f9948 16.0 -> 16 2023-10-20 16:45:55 -07:00
Ashcon Partovi
47f3ace597 Tweak script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
35bb6bf2cf Another sudo attempt 2023-10-20 16:45:55 -07:00
Ashcon Partovi
8536313906 Tweak dependencies 2023-10-20 16:45:55 -07:00
Ashcon Partovi
c5a4060df3 More sudo 2023-10-20 16:45:55 -07:00
Ashcon Partovi
43cc370c9e Use sudo 2023-10-20 16:45:55 -07:00
Ashcon Partovi
a3381ee9b9 Fix script 2023-10-20 16:45:55 -07:00
Ashcon Partovi
00d28e09c0 New build workflow 2023-10-20 16:45:55 -07:00
dave caruso
b72eec9e9a colorterm 2023-10-20 14:49:48 -07:00
dave caruso
7a7c85d05c okay 2023-10-19 23:02:13 -07:00
dave caruso
6158d5986d cool 2023-10-19 21:51:58 -08:00
dave caruso
de3a0f63e9 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-10-19 21:40:17 -08:00
dave caruso
d1c9f073df asdf 2023-10-19 21:40:15 -08:00
dave caruso
0c98256e64 theoretical -DCANARY flag we can use 2023-10-19 22:39:52 -07:00
dave caruso
bb3a11035f asdfg 2023-10-19 22:01:38 -07:00
dave caruso
c4934352db update build dot zig 2023-10-19 21:50:34 -07:00
dave caruso
939e8be057 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-10-19 20:15:42 -08:00
dave caruso
18d368b2cc fgh 2023-10-19 20:15:38 -08:00
dave caruso
5f30a71f8d a 2023-10-19 21:07:52 -07:00
dave caruso
14be6f71c1 adfhjskfjdhkas 2023-10-19 20:07:33 -08:00
dave caruso
74a3582d11 sxdcvbnmk, 2023-10-19 20:26:33 -07:00
dave caruso
5eabbdc27b getting farther 2023-10-19 18:25:13 -08:00
dave caruso
c6f29fb0ec Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-10-19 17:39:17 -08:00
dave caruso
0ed8153798 g 2023-10-19 17:39:14 -08:00
dave caruso
89e7eefd27 sdfadsf 2023-10-19 18:38:46 -07:00
dave caruso
5150c089a0 now it only has linker errors on mac 2023-10-19 17:20:45 -07:00
dave caruso
0e3dab76a6 Merge remote-tracking branch 'origin/main' into jarred/prepare-for-libuv 2023-10-19 16:14:06 -07:00
dave caruso
60be6b2497 finalize merge 2023-10-19 16:13:42 -07:00
dave caruso
42ac78ed49 Merge remote-tracking branch 'origin/jarred/prepare-for-libuv-2' into jarred/prepare-for-libuv 2023-10-19 16:13:36 -07:00
dave caruso
95662b07e6 blah 2023-10-19 14:54:18 -07:00
dave caruso
019bf2cd41 hmm 2023-10-18 22:55:50 -07:00
dave caruso
f794febca2 Merge remote-tracking branch 'origin/main' into jarred/prepare-for-libuv 2023-10-18 22:51:24 -07:00
dave caruso
11d4e85aa1 Process -> BunProcess 2023-10-18 22:34:13 -07:00
dave caruso
c9fa15d0c2 wow 2023-10-18 21:31:03 -08:00
dave caruso
51e0770476 git ignore 2023-10-18 19:45:18 -08:00
dave caruso
a6a3850d56 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-10-18 19:45:04 -08:00
dave caruso
5e100745d4 fghjkl 2023-10-18 19:41:36 -08:00
dave caruso
98f8a45f8b asdfasfdafdsafda 2023-10-18 20:34:31 -07:00
dave caruso
80b4047aaa oops 2023-10-18 17:19:38 -07:00
dave caruso
c29ec25586 ok 2023-10-18 17:09:11 -07:00
dave caruso
4c6c617cf8 fix 2023-10-18 16:59:08 -07:00
dave caruso
07ed4d87d4 bun run build 2023-10-18 16:51:24 -07:00
dave caruso
cb5c4c71c8 yay 2023-10-17 19:42:37 -07:00
dave caruso
bf12268274 progress 2023-10-17 17:44:30 -07:00
dave caruso
602a526723 Merge remote-tracking branch 'origin/main' into jarred/prepare-for-libuv 2023-10-17 15:12:59 -07:00
dave caruso
6ff8c406b1 cmake on mac works 2023-10-17 15:09:01 -07:00
dave caruso
89edf5ef4b windows zig compiles 2023-10-17 14:21:03 -07:00
Jarred Sumner
52d47c24dc Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-09 15:13:58 -08:00
Jarred Sumner
99c92d2b81 Update index.ts 2023-09-09 16:13:45 -07:00
Jarred Sumner
242ab4445b bump 2023-09-09 16:04:00 -07:00
Jarred Sumner
7f6bbce191 Merge branch 'main' into jarred/prepare-for-libuv 2023-09-09 15:03:47 -08:00
Jarred SUmner
fb86c1bdfe [dave]: fix webcrypto crash 2023-09-07 09:03:18 -07:00
Jarred Sumner
f44c2b65a3 hm 2023-09-07 08:58:47 -07:00
Jarred Sumner
7177cb0803 Merge branch 'main' into jarred/prepare-for-libuv 2023-09-07 06:14:50 -07:00
Jarred Sumner
69696793d5 Make sure we remove libusockets is removed 2023-09-07 05:54:45 -07:00
Jarred SUmner
605477f49a Fix some test failures 2023-09-07 05:52:36 -07:00
Jarred SUmner
ce16029183 Fix sqlite test failures 2023-09-07 04:46:53 -07:00
Jarred Sumner
c645342a74 Update mimalloc 2023-09-07 01:54:24 -08:00
Jarred Sumner
48cdfd6685 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-07 01:53:49 -08:00
Jarred Sumner
9452ade912 more 2023-09-07 01:53:41 -08:00
Jarred Sumner
f7ce24895a Set permissions 2023-09-07 00:38:41 -07:00
Jarred Sumner
cffdacc5fa Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 23:09:49 -08:00
Jarred Sumner
dbd57f426c Update feature_flags.zig 2023-09-06 23:47:02 -07:00
Jarred Sumner
497d546048 Revert "avoid duplicate symbols"
This reverts commit 4ac6ca8700.
2023-09-06 23:06:47 -07:00
Jarred Sumner
19a4df3c52 Revert "avoid undefined symbols"
This reverts commit ca835b726f.
2023-09-06 23:06:41 -07:00
Jarred Sumner
c7e93c1376 Update response.zig 2023-09-06 22:44:09 -07:00
Jarred Sumner
9e82e040dc Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 21:41:36 -08:00
Jarred Sumner
b6a4609a73 Update feature_flags.zig 2023-09-06 22:38:10 -07:00
Jarred Sumner
0a968a66c2 churn 2023-09-06 22:37:41 -07:00
Jarred Sumner
61bb92b7bc Merge remote-tracking branch 'origin' into jarred/prepare-for-libuv 2023-09-06 22:37:24 -07:00
Jarred Sumner
4b5233fc3a feat(fetch) rejectUnauthorized and checkServerIdentity (#4514)
* enable root certs on fetch

* rebase

* fix lookup

* some fixes and improvements

* fmt

* more fixes

* more fixes

* check detached onHandshake

* fix promise case

* fix cert non-Native

* add fetch tls tests

* more one test
2023-09-06 22:33:55 -07:00
Birk Skyum
99219d5e1c Update nodejs compat docs cp/cpSync/watchFile/unwatchFile (#4525) 2023-09-06 22:32:27 -07:00
Ashcon Partovi
70ec9afa46 Add bun-types to 'bun fmt' script 2023-09-06 22:32:26 -07:00
Ashcon Partovi
eb316e7197 Add types for watchFile and unwatchFile 2023-09-06 22:32:26 -07:00
Ashcon Partovi
02ba25c103 Add types for cp and cpSync 2023-09-06 22:32:26 -07:00
Ashcon Partovi
2b6f297c0d Remove issue template for install
It's not used, and use the bug issue instead.
2023-09-06 22:32:26 -07:00
Jarred Sumner
dc8d70ab02 Merge branch 'main' into jarred/prepare-for-libuv 2023-09-06 21:27:16 -08:00
Jarred Sumner
b38b345184 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 20:49:26 -08:00
Jarred Sumner
b7241f77fe bump 2023-09-06 20:47:06 -08:00
Dylan Conway
ca835b726f avoid undefined symbols 2023-09-06 14:24:04 -07:00
Dylan Conway
4ac6ca8700 avoid duplicate symbols 2023-09-06 14:12:06 -07:00
Jarred Sumner
bd7a2619e8 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 11:20:35 -08:00
Jarred Sumner
258615a43f fixup 2023-09-06 11:20:01 -08:00
Jarred Sumner
33d83ad6ca Update bun.zig 2023-09-06 12:09:28 -07:00
Jarred Sumner
bb9e0c2043 windows 2023-09-06 11:02:41 -08:00
Jarred Sumner
724a83de53 some clenaup 2023-09-06 10:51:32 -08:00
Jarred Sumner
db42fd3b1d Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 10:31:17 -08:00
Jarred Sumner
9a485be954 ok 2023-09-06 10:29:42 -08:00
Jarred Sumner
dca6ffd4cd We have to bump the version of Debian because libarchive has a higher minimum requirement 2023-09-06 09:28:20 -07:00
Jarred Sumner
dae3887bed Undo that change 2023-09-06 09:20:30 -07:00
Jarred Sumner
6979855f42 Bummp 2023-09-06 08:59:06 -07:00
Jarred Sumner
ce4c1351bb Bump 2023-09-06 08:57:53 -07:00
Jarred Sumner
1a275c6337 small fixes 2023-09-06 08:56:16 -07:00
Jarred Sumner
666fbead09 Fixes 2023-09-06 08:42:43 -07:00
Jarred Sumner
b8329f293e Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-06 06:48:27 -08:00
Jarred Sumner
4601b80d7c use less std.os 2023-09-06 06:48:08 -08:00
Jarred Sumner
4b58698136 Merge branch 'main' into jarred/prepare-for-libuv 2023-09-06 07:40:51 -07:00
Jarred Sumner
400bc949e6 more things work 2023-09-06 06:37:59 -08:00
Jarred Sumner
5fb23b9296 bun install progress 2023-09-06 04:18:14 -08:00
Jarred Sumner
caa3ff71fe Make require() work 2023-09-06 01:19:45 -08:00
Jarred Sumner
c33e86e1a4 Bun.serve() and much of the event loop works now 2023-09-06 00:57:25 -08:00
Jarred Sumner
e44911d4eb fetch works 2023-09-05 22:19:48 -08:00
Jarred Sumner
e7c6b1d683 fixup 2023-09-05 21:25:54 -07:00
Jarred Sumner
38849b566d Update JSSink.h 2023-09-05 21:08:50 -07:00
Jarred Sumner
831919d12a regenaret 2023-09-05 21:08:36 -07:00
Jarred Sumner
547b8453ec reb 2023-09-05 21:05:14 -07:00
Jarred Sumner
b9e5758a86 Merge branch 'main' into jarred/prepare-for-libuv 2023-09-05 19:26:45 -08:00
Jarred Sumner
27c82a6763 Many more things are starting to work. 2023-09-05 17:43:23 -08:00
Jarred Sumner
4b1d1a272a Merge branch 'main' into jarred/prepare-for-libuv 2023-09-05 05:11:46 -08:00
Jarred Sumner
ebc64f2b4d zig fmt 2023-09-05 05:11:39 -08:00
Jarred Sumner
e2d3bdd6b3 Update CMakeLists.txt 2023-09-05 05:08:44 -08:00
Jarred Sumner
f9d325cb56 quite a lot of fixes 2023-09-05 05:08:37 -08:00
Jarred Sumner
5b808d6c5c hm 2023-09-05 00:49:37 -08:00
Jarred Sumner
e84a85b020 Update .gitignore 2023-09-05 00:48:00 -08:00
Jarred Sumner
a66b766ced more 2023-09-05 00:45:51 -08:00
Jarred Sumner
04a2944eb3 further! 2023-09-05 00:44:22 -08:00
Jarred Sumner
c5ea98ae56 Update src/bun.js/bindings/headers-handwritten.h
Co-authored-by: Dylan Conway <35280289+dylan-conway@users.noreply.github.com>
2023-09-04 19:53:38 -07:00
Dylan Conway
5aa1324938 Update wtf-bindings.cpp 2023-09-04 19:43:38 -07:00
Jarred Sumner
fd97e2f17a Fixups 2023-09-04 19:17:01 -07:00
Jarred Sumner
35fdc690b7 Rename file 2023-09-04 19:17:01 -07:00
Jarred Sumner
32084dac41 hmmm 2023-09-04 10:54:50 -08:00
Jarred Sumner
6adb60197e it works 2023-09-04 10:19:29 -08:00
Jarred Sumner
a113950d41 Merge branch 'jarred/prepare-for-libuv' of https://github.com/oven-sh/bun into jarred/prepare-for-libuv 2023-09-04 08:58:06 -08:00
Jarred Sumner
dfa0bf6f5b Fix build issue 2023-09-04 08:58:04 -08:00
Jarred Sumner
c63b9aa548 Update windows.zig 2023-09-04 09:55:55 -07:00
Jarred Sumner
f40b07ad65 Update windows.zig 2023-09-04 09:55:49 -07:00
Jarred Sumner
f76f15c5e2 Add fast-ish path for bun install on Windows 2023-09-04 09:55:18 -07:00
Jarred Sumner
37d8593713 fix variosu issues 2023-09-04 05:58:03 -08:00
Jarred Sumner
3b9318794d Fix getenvZ 2023-09-04 03:07:45 -07:00
Jarred Sumner
60f1a81d06 12 mb 2023-09-04 02:42:21 -07:00
Jarred Sumner
03334de41e More 2023-09-04 00:02:19 -08:00
Jarred Sumner
36840f8ab0 Add musl polyfill for memmem on Windows 2023-09-04 00:02:07 -08:00
Jarred Sumner
2ef51cadb0 Rename Process -> BunProcess
Works around a Windows issue
2023-09-04 00:01:53 -08:00
Jarred Sumner
c9f614a2f2 theres more 2023-09-04 00:01:29 -08:00
Jarred Sumner
5b1f211110 draw the rest of the owl 2023-09-04 00:01:00 -08:00
Jarred Sumner
0ff9a10355 chunk 2023-09-03 23:57:55 -08:00
Jarred Sumner
c267a422ad Fix one of the compiler errors 2023-09-03 22:21:35 -07:00
Jarred Sumner
3de075bbae Fixup 2023-09-03 04:18:51 -07:00
Jarred Sumner
b142009fc9 Fix usockets warnings 2023-09-03 04:14:29 -07:00
Jarred Sumner
8f7f75bb2a put it in the zig file 2023-09-03 03:56:51 -07:00
Jarred Sumner
80e45451cf Update JSSQLStatement.h 2023-09-03 02:24:07 -07:00
Jarred Sumner
1d5ea13825 cmake works 2023-09-03 02:14:02 -07:00
Jarred Sumner
d5d0ffe43c more warnings 2023-09-03 00:46:46 -07:00
Jarred Sumner
8a5f27c1a7 Remove more warnings 2023-09-03 00:32:55 -07:00
Jarred Sumner
40193f8846 Fix a bunch of compiler warnings 2023-09-03 00:29:25 -07:00
Jarred Sumner
24582cc99b Update settings.json 2023-09-02 21:30:16 -07:00
Jarred Sumner
668e5ce368 Add the build scripts 2023-09-01 21:33:52 -07:00
Jarred Sumner
9c8e17e300 Bump mimalloc 2023-09-01 20:40:29 -07:00
Jarred Sumner
cbdf380493 Make compiling each dependency a shell script 2023-09-01 18:15:19 -07:00
Jarred Sumner
3c4015de26 wip 2023-08-31 03:29:03 -07:00
Jarred Sumner
69f85b59ad Update libuv.zig 2023-08-31 02:16:58 -07:00
Jarred Sumner
3775081e5a More progress 2023-08-31 02:11:04 -07:00
Jarred Sumner
a81ca0d9cc Prepare for windows event loop 2023-08-31 00:22:50 -07:00
369 changed files with 11821 additions and 59264 deletions

22
.build/base64.bash Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CFLAGS=${CFLAGS:-}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/base64
echo "1: $(which make)"
echo "2: $(which cmake)"
make clean
cmake $CMAKE_FLAGS .
make
cp libbase64.a $BUN_DEPS_OUT_DIR/libbase64.a

22
.build/base64.ps1 Normal file
View File

@@ -0,0 +1,22 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
# Create the output directory if it doesn't exist
if (-not (Test-Path $BUN_DEPS_OUT_DIR)) {
New-Item -ItemType Directory -Path $BUN_DEPS_OUT_DIR
}
Set-Location (Join-Path $BUN_DEPS_DIR 'base64')
cmake $CMAKE_FLAGS .
cmake --build . --clean-first --config Release
Copy-Item **/*.lib $BUN_DEPS_OUT_DIR

22
.build/boringssl.bash Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CFLAGS=${CFLAGS:-}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/boringssl
rm -rf build
mkdir -p build
cd build
CFLAGS="$CFLAGS" cmake $CMAKE_FLAGS -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld" -GNinja ..
ninja libcrypto.a libssl.a libdecrepit.a
cp **/libcrypto.a $BUN_DEPS_OUT_DIR/libcrypto.a
cp **/libssl.a $BUN_DEPS_OUT_DIR/libssl.a
cp **/libdecrepit.a $BUN_DEPS_OUT_DIR/libdecrepit.a

19
.build/boringssl.ps1 Normal file
View File

@@ -0,0 +1,19 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
mkdir -p $BUN_DEPS_OUT_DIR -Force
Set-Location $BUN_DEPS_DIR/boringssl
cmake $CMAKE_FLAGS .
cmake --build . --target crypto --target ssl --target decrepit --clean-first --config Release
Copy-Item crypto/Release/crypto.lib $BUN_DEPS_OUT_DIR
Copy-Item ssl/Release/ssl.lib $BUN_DEPS_OUT_DIR
Copy-Item decrepit/Release/decrepit.lib $BUN_DEPS_OUT_DIR

24
.build/cares.ps1 Normal file
View File

@@ -0,0 +1,24 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
# Create the output directory if it doesn't exist
if (-not (Test-Path $BUN_DEPS_OUT_DIR)) {
New-Item -ItemType Directory -Path $BUN_DEPS_OUT_DIR
}
Set-Location (Join-Path $BUN_DEPS_DIR 'c-ares')
rm -r build -ErrorAction SilentlyContinue
mkdir build -ErrorAction SilentlyContinue
cd build
cmake $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 17 2022" -DCARES_STATIC=ON -DCARES_SHARED=OFF ..
cmake --build . --clean-first --config Release
cp ./lib/Release/*.lib $BUN_DEPS_OUT_DIR

22
.build/libarchive.bash Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
CFLAGS=${CFLAGS:-}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/libarchive
make clean || echo ""
./build/clean.sh || echo ""
./build/autogen.sh
CFLAGS="$CFLAGS" $CCACHE_CC_FLAG ./configure --disable-shared --enable-static --with-pic --disable-bsdtar --disable-bsdcat --disable-rpath --enable-posix-regex-lib --without-xml2 --without-expat --without-openssl --without-iconv --without-zlib
make -j$CPUS
cp ./.libs/libarchive.a $BUN_DEPS_OUT_DIR/libarchive.a

16
.build/libarchive.ps1 Normal file
View File

@@ -0,0 +1,16 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
Set-Location $BUN_DEPS_DIR/libarchive
cmake -DBUILD_SHARED_LIBS=OFF -DENABLE_TEST=OFF -DENABLE_INSTALL=OFF --compile-no-warning-as-error $CMAKE_FLAGS .
cmake --build . --target ALL_BUILD --clean-first --config Release -- /p:WarningLevel=0
Copy-Item libarchive/Release/archive.lib $BUN_DEPS_OUT_DIR

16
.build/lolhtml.bash Executable file
View File

@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CFLAGS=${CFLAGS:-}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/lol-html/c-api
cargo build --release
cp target/release/liblolhtml.a $BUN_DEPS_OUT_DIR

16
.build/lolhtml.ps1 Normal file
View File

@@ -0,0 +1,16 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
Set-Location $BUN_DEPS_DIR/lol-html/c-api
cargo build --release --target x86_64-pc-windows-msvc
Copy-Item target/x86_64-pc-windows-msvc/release/lolhtml.lib $BUN_DEPS_OUT_DIR
Copy-Item target/x86_64-pc-windows-msvc/release/lolhtml.pdb $BUN_DEPS_OUT_DIR

38
.build/mimalloc-debug.bash Executable file
View File

@@ -0,0 +1,38 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
CFLAGS=${CFLAGS:-}
MIMALLOC_OVERRIDE_FLAG=${MIMALLOC_OVERRIDE_FLAG:-}
MIMALLOC_VALGRIND_ENABLED_FLAG=${MIMALLOC_VALGRIND_ENABLED_FLAG:-}
mkdir -p $BUN_DEPS_OUT_DIR
rm -rf $(BUN_DEPS_DIR)/mimalloc/CMakeCache* $(BUN_DEPS_DIR)/mimalloc/CMakeFiles
cd $(BUN_DEPS_DIR)/mimalloc
make clean || echo ""
CFLAGS="$CFLAGS" cmake $CMAKE_FLAGS $MIMALLOC_OVERRIDE_FLAG $MIMALLOC_VALGRIND_ENABLED_FLAG \
-DCMAKE_BUILD_TYPE=Debug \
-DMI_DEBUG_FULL=1 \
-DMI_SKIP_COLLECT_ON_EXIT=1 \
-DMI_BUILD_SHARED=OFF \
-DMI_BUILD_STATIC=ON \
-DMI_BUILD_TESTS=OFF \
-DMI_OSX_ZONE=OFF \
-DMI_OSX_INTERPOSE=OFF \
-DMI_BUILD_OBJECT=ON \
-DMI_USE_CXX=ON \
-DMI_OVERRIDE=OFF \
-DCMAKE_C_FLAGS="$CFLAGS" \
-DCMAKE_CXX_FLAGS="$CFLAGS" \
-GNinja .
ninja
cp $BUN_DEPS_DIR/mimalloc/libmimalloc-debug.a $BUN_DEPS_OUT_DIR/libmimalloc.a

37
.build/mimalloc.bash Executable file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
CFLAGS=${CFLAGS:-}
MIMALLOC_OVERRIDE_FLAG=${MIMALLOC_OVERRIDE_FLAG:-}
MIMALLOC_VALGRIND_ENABLED_FLAG=${MIMALLOC_VALGRIND_ENABLED_FLAG:-}
mkdir -p $BUN_DEPS_OUT_DIR
rm -rf $BUN_DEPS_DIR/mimalloc/CMakeCache* $BUN_DEPS_DIR/mimalloc/CMakeFiles
cd $BUN_DEPS_DIR/mimalloc
make clean || echo ""
CFLAGS="$CFLAGS" cmake $CMAKE_FLAGS $MIMALLOC_OVERRIDE_FLAG \
-DMI_SKIP_COLLECT_ON_EXIT=1 \
-DMI_BUILD_SHARED=OFF \
-DMI_BUILD_STATIC=ON \
-DMI_BUILD_TESTS=OFF \
-DMI_OSX_ZONE=OFF \
-DMI_OSX_INTERPOSE=OFF \
-DMI_BUILD_OBJECT=ON \
-DMI_USE_CXX=ON \
-DMI_OVERRIDE=OFF \
-DMI_OSX_ZONE=OFF \
-DCMAKE_C_FLAGS="$CFLAGS" \
-GNinja .
ninja
cp $BUN_DEPS_DIR/mimalloc/libmimalloc.a $BUN_DEPS_OUT_DIR/libmimalloc.a

22
.build/mimalloc.ps1 Normal file
View File

@@ -0,0 +1,22 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
# Create the output directory if it doesn't exist
if (-not (Test-Path $BUN_DEPS_OUT_DIR)) {
New-Item -ItemType Directory -Path $BUN_DEPS_OUT_DIR
}
Set-Location (Join-Path $BUN_DEPS_DIR 'mimalloc')
cmake $CMAKE_FLAGS -DMI_SKIP_COLLECT_ON_EXIT=1 -DMI_BUILD_SHARED=OFF -DMI_BUILD_STATIC=ON -DMI_BUILD_TESTS=OFF -DMI_OSX_ZONE=OFF -DMI_OSX_INTERPOSE=OFF -DMI_BUILD_OBJECT=ON -DMI_USE_CXX=ON -DMI_OVERRIDE=OFF -DMI_OSX_ZONE=OFF -DCMAKE_C_FLAGS="$CFLAGS" .
cmake --build . --clean-first --config Release
Copy-Item **/*.lib $BUN_DEPS_OUT_DIR

22
.build/tinycc.bash Executable file
View File

@@ -0,0 +1,22 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
AR=${AR:-ar}
CC=${CC:-cc}
CFLAGS=${CFLAGS:-}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/tinycc
make clean
AR=$AR CC=$CC CFLAGS="$CFLAGS" ./configure --enable-static --cc=$CC --ar=$AR --config-predefs=yes
make -j10
cp *.a $BUN_DEPS_OUT_DIR

18
.build/zlib.bash Executable file
View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/zlib
make clean
$CCACHE_CC_FLAG CFLAGS="$CFLAGS" ./configure --static
make -j${CPUS}
cp ./libz.a $BUN_DEPS_OUT_DIR/libz.a

19
.build/zstd.bash Executable file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -euxo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
CMAKE_FLAGS=${CMAKE_FLAGS:-}
BUN_BASE_DIR=${BUN_BASE_DIR:-$(cd $SCRIPT_DIR && cd ../ && pwd)}
BUN_DEPS_OUT_DIR=${BUN_DEPS_OUT_DIR:-$BUN_BASE_DIR/src/deps/}
BUN_DEPS_DIR=${BUN_DEPS_DIR:-$BUN_BASE_DIR/src/deps}
CCACHE_CC_FLAG=${CCACHE_CC_FLAG:-}
CPUS=${CPUS:-$(nproc || sysctl -n hw.ncpu || echo 1)}
mkdir -p $BUN_DEPS_OUT_DIR
cd $BUN_DEPS_DIR/zstd
rm -rf Release CMakeCache.txt CMakeFiles
cmake $CMAKE_FLAGS -DZSTD_BUILD_STATIC=ON -B Release -S build/cmake -G Ninja
ninja -C Release
cp Release/lib/libzstd.a $BUN_DEPS_OUT_DIR/libzstd.a

21
.build/zstd.ps1 Normal file
View File

@@ -0,0 +1,21 @@
$ErrorActionPreference = 'Stop' # Setting strict mode, similar to 'set -euo pipefail' in bash
$SCRIPT_DIR = Split-Path $PSScriptRoot -Parent
$CMAKE_FLAGS = $env:CMAKE_FLAGS
$BUN_BASE_DIR = if ($env:BUN_BASE_DIR) { $env:BUN_BASE_DIR } else { $SCRIPT_DIR }
$BUN_DEPS_OUT_DIR = if ($env:BUN_DEPS_OUT_DIR) { $env:BUN_DEPS_OUT_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$BUN_DEPS_DIR = if ($env:BUN_DEPS_DIR) { $env:BUN_DEPS_DIR } else { Join-Path $BUN_BASE_DIR 'src\deps' }
$CCACHE_CC_FLAG = $env:CCACHE_CC_FLAG
$CPUS = if ($env:CPUS) { $env:CPUS } else { (Get-WmiObject -Class Win32_ComputerSystem).NumberOfLogicalProcessors }
$CFLAGS = $env:CFLAGS
$CXXFLAGS = $env:CXXFLAGS
# Create the output directory if it doesn't exist
if (-not (Test-Path $BUN_DEPS_OUT_DIR)) {
New-Item -ItemType Directory -Path $BUN_DEPS_OUT_DIR
}
Set-Location (Join-Path $BUN_DEPS_DIR 'zstd\build\cmake')
cmake $CMAKE_FLAGS -DZSTD_BUILD_STATIC=ON -DCMAKE_BUILD_TYPE=Release
cmake --build . --clean-first --config Release
Copy-Item lib\*\**.lib $BUN_DEPS_OUT_DIR

89
.github/workflows/bun-build.yml vendored Normal file
View File

@@ -0,0 +1,89 @@
name: bun-build
env:
ZIG_VERSION: 0.12.0-dev.888+130227491
concurrency:
group: bun-build-${{ github.ref || github.run_id }}
cancel-in-progress: true
on: [push]
# push:
# branches:
# - main
# - ci/*
# paths:
# # Build files
# # Source files
# - "src/**/*"
# - "packages/{bun-usockets,bun-uws}/src/**/*"
# pull_request:
# branches:
# - main
# paths:
# # Build files
# - "a"
# # Source files
# - "src/**/*"
# - "packages/{bun-usockets,bun-uws}/src/**/*"
# workflow_dispatch: {}
permissions:
contents: read
jobs:
build:
name: Build (${{ matrix.id }})
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
include:
- id: linux-x64
runner: ubuntu-latest
runs-on: ${{ matrix.runner }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Restore Cache
uses: actions/cache@v3
with:
key: ${{ runner.os }}-build-${{ matrix.id }}
path: |
build
- name: Setup APT
uses: awalsh128/cache-apt-pkgs-action@latest
with:
version: "1" # increment when packages change
packages: |
make
cmake
ccache
ninja-build
- name: Setup Zig
uses: goto-bus-stop/setup-zig@v2
with:
version: ${{ env.ZIG_VERSION }}
# - name: Setup LLVM
# uses: KyleMayes/install-llvm-action@v1
# with:
# version: "16"
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Dependencies
run: |
bun install
bash .scripts/postinstall.sh
bun install -g esbuild
- name: Setup upterm session
uses: lhotari/action-upterm@v1
with:
limit-access-to-users: Electroid,paperdave,Jarred-Sumner

18
.gitignore vendored
View File

@@ -135,3 +135,21 @@ make-dev-stats.csv
.uuid
tsconfig.tsbuildinfo
build-release
*.lib
*.pdb
CMakeFiles
build.ninja
.ninja_deps
.ninja_log
CMakeCache.txt
cmake_install.cmake
compile_commands.json
*.lib
x64
**/*.vcxproj*
**/*.sln*
**/*.dir
**/*.pdb

View File

@@ -1,21 +0,0 @@
// I would have made this a bash script but there isn't an easy way to track
// time in bash sub-second cross platform.
import fs from "fs";
const start = Date.now() + 5;
const result = Bun.spawnSync(process.argv.slice(2), {
stdio: ["inherit", "inherit", "inherit"],
});
const end = Date.now();
const diff = (Math.max(Math.round(end - start), 0) / 1000).toFixed(3);
const success = result.exitCode === 0;
try {
const line = `${new Date().toISOString()}, ${success ? "success" : "fail"}, ${diff}\n`;
if (fs.existsSync(".scripts/make-dev-stats.csv")) {
fs.appendFileSync(".scripts/make-dev-stats.csv", line);
} else {
fs.writeFileSync(".scripts/make-dev-stats.csv", line);
}
} catch {
// Ignore
}
process.exit(result.exitCode);

View File

@@ -1,13 +1,6 @@
#!/bin/bash
set -euxo pipefail
# if bun-webkit node_modules directory exists
if [ -d ./node_modules/bun-webkit ] || [ -d ./node_modules/bun-webkit-debug ]; then
rm -f bun-webkit
# get the first matching bun-webkit-* directory name
ln -s ./node_modules/$(ls ./node_modules | grep bun-webkit- | grep -v bun-webkit-debug | head -n 1) ./bun-webkit
fi
# sets up vscode C++ intellisense
rm -f .vscode/clang++
ln -s $(which clang++-16 || which clang++) .vscode/clang++ 2>/dev/null

8
.vscode/launch.json generated vendored
View File

@@ -123,7 +123,7 @@
"type": "lldb",
"request": "launch",
"name": "bun run [file]",
"program": "bun-debug",
"program": "./Build/debug/bun.exe",
"args": ["run", "${file}", "${file}"],
"cwd": "${fileDirname}",
"env": {
@@ -307,11 +307,9 @@
"name": "bun install",
"program": "bun-debug",
"args": ["install"],
"cwd": "${fileDirname}",
"cwd": "/Users/jarred/Build/worky",
"console": "internalConsole",
"env": {
"BUN_DEBUG_ALL": "1"
}
"env": {}
},
{
"type": "lldb",

85
.vscode/settings.json vendored
View File

@@ -8,7 +8,6 @@
"search.useIgnoreFiles": true,
"zig.buildOnSave": false,
"zig.formattingProvider": "zls",
"zig.buildArgs": ["obj", "-Dfor-editor"],
"zig.buildOption": "build",
"zig.buildFilePath": "${workspaceFolder}/build.zig",
"[zig]": {
@@ -67,40 +66,40 @@
"test/snapshots": true,
"test/snapshots-no-hmr": true,
"src/bun.js/WebKit": true,
"src/deps/libarchive": true,
"src/deps/mimalloc": true,
"src/deps/s2n-tls": true,
"src/deps/boringssl": true,
"src/deps/openssl": true,
"src/deps/uws": true,
"src/deps/zlib": true,
"src/deps/lol-html": true,
"src/deps/c-ares": true,
"src/deps/tinycc": true,
"src/deps/zstd": true,
// "src/deps/libarchive": true,
// "src/deps/mimalloc": true,
// "src/deps/s2n-tls": true,
// "src/deps/boringssl": true,
// "src/deps/openssl": true,
// "src/deps/uws": true,
// "src/deps/zlib": true,
// "src/deps/lol-html": true,
// "src/deps/c-ares": true,
// "src/deps/tinycc": true,
// "src/deps/zstd": true,
"test/snippets/package-json-exports/_node_modules_copy": true,
"src/js/out": true,
"packages/bun-uws/fuzzing/seed-corpus/": true,
"**/*.dep": true,
"**/CMakeFiles": true
"**/*.dep": true
// "**/CMakeFiles": true
},
"C_Cpp.files.exclude": {
"**/.vscode": true,
"src/bun.js/WebKit/JSTests": true,
"src/bun.js/WebKit/Tools": true,
"src/bun.js/WebKit/WebDriverTests": true,
"src/bun.js/WebKit/WebKit.xcworkspace": true,
"src/bun.js/WebKit/WebKitLibraries": true,
"src/bun.js/WebKit/Websites": true,
"src/bun.js/WebKit/resources": true,
"src/bun.js/WebKit/LayoutTests": true,
"src/bun.js/WebKit/ManualTests": true,
"src/bun.js/WebKit/PerformanceTests": true,
"src/bun.js/WebKit/WebKitLegacy": true,
"src/bun.js/WebKit/WebCore": true,
"src/bun.js/WebKit/WebDriver": true,
"src/bun.js/WebKit/WebKitBuild": true,
"src/bun.js/WebKit/WebInspectorUI": true
"WebKit/JSTests": true,
"WebKit/Tools": true,
"WebKit/WebDriverTests": true,
"WebKit/WebKit.xcworkspace": true,
"WebKit/WebKitLibraries": true,
"WebKit/Websites": true,
"WebKit/resources": true,
"WebKit/LayoutTests": true,
"WebKit/ManualTests": true,
"WebKit/PerformanceTests": true,
"WebKit/WebKitLegacy": true,
"WebKit/WebCore": true,
"WebKit/WebDriver": true,
"WebKit/WebKitBuild": true,
"WebKit/WebInspectorUI": true
},
"[cpp]": {
"editor.defaultFormatter": "xaver.clang-format"
@@ -220,9 +219,33 @@
"regex": "cpp",
"span": "cpp",
"valarray": "cpp",
"codecvt": "cpp"
"codecvt": "cpp",
"types.h": "c",
"bsd.h": "c",
"xtr1common": "cpp",
"stop_token": "cpp",
"xfacet": "cpp",
"xhash": "cpp",
"xiosbase": "cpp",
"xlocale": "cpp",
"xlocbuf": "cpp",
"xlocinfo": "cpp",
"xlocmes": "cpp",
"xlocmon": "cpp",
"xlocnum": "cpp",
"xloctime": "cpp",
"xmemory": "cpp",
"xstring": "cpp",
"xtree": "cpp",
"xutility": "cpp",
"string.h": "c",
"zutil.h": "c",
"gzguts.h": "c",
"stdatomic.h": "c",
"root_certs.h": "c"
},
"C_Cpp.errorSquiggles": "enabled",
"eslint.workingDirectories": ["packages/bun-types"],
"typescript.tsdk": "node_modules/typescript/lib"
"typescript.tsdk": "node_modules/typescript/lib",
"zig.initialSetupDone": true
}

974
CMakeLists.txt Normal file
View File

@@ -0,0 +1,974 @@
cmake_minimum_required(VERSION 3.22)
cmake_policy(SET CMP0091 NEW)
cmake_policy(SET CMP0067 NEW)
set(Bun_VERSION "1.0.7")
set(WEBKIT_TAG 1a49a1f94bf42ab4f8c6b11d7bbbb21e491d2d62)
set(BUN_WORKDIR "${CMAKE_CURRENT_BINARY_DIR}")
message(STATUS "Configuring Bun ${Bun_VERSION} in ${BUN_WORKDIR}")
# --- Build Type ---
# This is done at the start simply so this is the first message printed
if(NOT CMAKE_BUILD_TYPE)
message(WARNING "No CMAKE_BUILD_TYPE value specified, defaulting to Debug.\nSet a build type with -DCMAKE_BUILD_TYPE=<Debug|Release>")
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build (Debug, Release)" FORCE)
else()
if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release)$")
message(FATAL_ERROR
"Invalid CMAKE_BUILD_TYPE value specified: ${CMAKE_BUILD_TYPE}\n"
"CMAKE_BUILD_TYPE must be Debug or Release.")
endif()
message(STATUS "The CMake build type is: ${CMAKE_BUILD_TYPE}")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(DEBUG ON)
set(ZIG_OPTIMIZE "Debug")
set(bun "bun-debug")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
set(DEBUG OFF)
set(ZIG_OPTIMIZE "ReleaseFast")
set(bun "bun-profile")
endif()
# --- LLVM ---
# This detection is a little overkill, but it ensures that the set LLVM_VERSION matches under
# any case possible. Sorry for the complexity...
#
# Bun and WebKit must be compiled with the same compiler, so we do as much as we can to ensure that
# the compiler used for the prebuilt WebKit, LLVM 16, is the one that we detect in this process.
#
# It has to be done before project() is called, so that CMake doesnt pick a compiler for us, but even then
# we do some extra work afterwards to double-check, and we will rerun BUN_FIND_LLVM if the compiler did not match.
#
# If the user passes -DLLVM_PREFIX, most of this logic is skipped, but we still warn if invalid.
set(LLVM_VERSION 16)
macro(BUN_FIND_LLVM)
find_program(
_LLVM_CLANG_PATH
NAMES clang++-${LLVM_VERSION} clang-${LLVM_VERSION} clang++ clang
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s clang++ binary. Please pass -DLLVM_PREFIX with the path to LLVM"
)
if(NOT _LLVM_CLANG_PATH)
message(FATAL_ERROR "Could not find LLVM ${LLVM_VERSION}, search paths: ${PLATFORM_LLVM_SEARCH_PATHS}")
endif()
set(CMAKE_CXX_COMPILER ${_LLVM_CLANG_PATH})
set(CMAKE_C_COMPILER ${_LLVM_CLANG_PATH})
find_program(
STRIP
NAMES llvm-strip
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-strip binary"
)
find_program(
DSYMUTIL
NAMES dsymutil
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s dsymutil binary"
)
find_program(
AR
NAMES llvm-ar
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
find_program(
RANLIB
NAMES llvm-ranlib
PATHS ENV PATH ${PLATFORM_LLVM_SEARCH_PATHS}
DOC "Path to LLVM ${LLVM_VERSION}'s llvm-ar binary"
)
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE _tmp)
string(REGEX MATCH "version ([0-9]+)\\.([0-9]+)\\.([0-9]+)" CMAKE_CXX_COMPILER_VERSION "${_tmp}")
set(CMAKE_CXX_COMPILER_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
endmacro()
if(UNIX)
if(LLVM_PREFIX)
set(PLATFORM_LLVM_SEARCH_PATHS ${LLVM_PREFIX}/bin)
else()
set(PLATFORM_LLVM_SEARCH_PATHS /usr/lib/llvm-${LLVM_VERSION}/bin /lib/llvm-${LLVM_VERSION}/bin /usr/bin /usr/local/bin)
if(APPLE)
set(PLATFORM_LLVM_SEARCH_PATHS /opt/homebrew/opt/llvm@${LLVM_VERSION}/bin /opt/homebrew/bin ${PLATFORM_LLVM_SEARCH_PATHS})
endif()
endif()
if(CMAKE_CXX_COMPILER)
set(_LLVM_CLANG_PATH "${CMAKE_CXX_COMPILER}")
endif()
BUN_FIND_LLVM()
else()
# On windows it is expected to use MSVC, and until we get a better build configuration, it is a free-for-all
endif()
set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD_REQUIRED ON)
project(Bun VERSION "${Bun_VERSION}")
# More effort to prevent using the wrong C++ compiler
if(UNIX)
if((NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (NOT CMAKE_CXX_COMPILER_VERSION MATCHES "^${LLVM_VERSION}\."))
# Attempt to auto-correct the compiler
message(STATUS "Compiler mismatch, attempting to auto-correct")
unset(_LLVM_CLANG_PATH)
BUN_FIND_LLVM()
if((NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (NOT CMAKE_CXX_COMPILER_VERSION MATCHES "^${LLVM_VERSION}\."))
message(WARNING "Expected LLVM ${LLVM_VERSION} as the C++ compiler, build may fail or break at runtime.")
endif()
endif()
endif()
message(STATUS "C++ Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} at ${CMAKE_CXX_COMPILER}")
# --- End LLVM ---
set(DEFAULT_ON_UNLESS_WINDOWS ON)
set(REQUIRED_IF_NOT_WINDOWS "REQUIRED")
if(WIN32)
set(DEFAULT_ON_UNLESS_WINDOWS OFF)
set(REQUIRED_IF_NOT_WINDOWS OFF)
endif()
set(DEFAULT_ON_UNLESS_APPLE ON)
if(APPLE)
set(DEFAULT_ON_UNLESS_APPLE OFF)
endif()
set(CI OFF)
if(DEFINED ENV{CI} OR DEFINED ENV{GITHUB_ACTIONS})
set(CI ON)
endif()
# -- Build Flags --
option(USE_STATIC_SQLITE "Statically link SQLite?" ${DEFAULT_ON_UNLESS_APPLE})
option(USE_CUSTOM_ZLIB "Use Bun's recommended version of zlib" ${DEFAULT_ON_UNLESS_WINDOWS})
option(USE_CUSTOM_BORINGSSL "Use Bun's recommended version of BoringSSL" ON)
option(USE_CUSTOM_LIBARCHIVE "Use Bun's recommended version of libarchive" ON)
option(USE_CUSTOM_MIMALLOC "Use Bun's recommended version of Mimalloc" ON)
option(USE_CUSTOM_ZSTD "Use Bun's recommended version of zstd" ON)
option(USE_CUSTOM_CARES "Use Bun's recommended version of c-ares" ${DEFAULT_ON_UNLESS_WINDOWS})
option(USE_CUSTOM_BASE64 "Use Bun's recommended version of libbase64" ON)
option(USE_CUSTOM_LOLHTML "Use Bun's recommended version of lolhtml" ON)
option(USE_CUSTOM_TINYCC "Use Bun's recommended version of tinycc" ON)
option(USE_CUSTOM_LIBUV "Use Bun's recommended version of libuv (Windows only)" OFF)
option(USE_BASELINE_BUILD "Build Bun for baseline (older) CPUs" OFF)
option(USE_DEBUG_JSC "Enable assertions and use a debug build of JavaScriptCore" OFF)
option(USE_UNIFIED_SOURCES "Use unified sources to speed up the build" OFF)
option(CANARY "Make `bun --revision` report a canary release" OFF)
set(ERROR_LIMIT 100 CACHE STRING "Maximum number of errors to show when compiling C++ code")
set(ARCH x86_64)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|arm")
set(ARCH aarch64)
endif()
if(NOT CPU_TARGET)
set(CPU_TARGET "native" CACHE STRING "CPU target for the compiler" FORCE)
if (ARCH STREQUAL "x86_64")
if (NOT MSVC)
if (USE_BASELINE_BUILD)
set(CPU_TARGET "nehalem")
else()
set(CPU_TARGET "haswell")
endif()
endif()
endif()
endif()
message(STATUS "Building for CPU Target: ${CPU_TARGET}")
set(ZIG_TARGET "native")
if(WIN32)
set(ZIG_TARGET "${ARCH}-windows-msvc")
endif()
# set(CONFIGURE_DEPENDS "")
set(CONFIGURE_DEPENDS "CONFIGURE_DEPENDS")
# --- CLI Paths ---
# Zig Compiler
function(validate_zig validator_result_var item)
set(${validator_result_var} FALSE PARENT_SCOPE)
# We will allow any valid zig compiler, as long as it contains some text from `zig zen`
# Ideally we would do a version or feature check, but that would be quite slow
execute_process(COMMAND ${item} zen OUTPUT_VARIABLE ZIG_ZEN_OUTPUT)
if(ZIG_ZEN_OUTPUT MATCHES "Together we serve the users")
set(${validator_result_var} TRUE PARENT_SCOPE)
else()
set(${validator_result_var} FALSE PARENT_SCOPE)
endif()
endfunction()
find_program(ZIG_COMPILER zig REQUIRED DOC "Path to the Zig compiler" VALIDATOR validate_zig)
message(STATUS "Found Zig Compiler: ${ZIG_COMPILER}")
# Bun
if(NOT WIN32)
find_program(BUN_EXECUTABLE bun REQUIRED DOC "Path to an already built release of Bun")
message(STATUS "Found Bun: ${BUN_EXECUTABLE}")
else()
set(BUN_EXECUTABLE "echo")
endif()
# Prettier
find_program(PRETTIER prettier DOC "Path to prettier" PATHS ./node_modules/.bin ENV PATH)
# Esbuild (TODO: switch these to "bun build")
find_program(ESBUILD esbuild DOC "Path to esbuild" PATHS ./node_modules/.bin ENV PATH)
# Ruby (only needed for unified sources)
if(USE_UNIFIED_SOURCES)
# ruby 'WebKit/Source/WTF/Scripts/generate-unified-source-bundles.rb' source_list.txt --source-tree-path . --derived-sources-path build/unified-sources
find_program(RUBY ruby DOC "Path to ruby")
endif()
# CCache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
message(STATUS "Using ccache: ${CCACHE_PROGRAM}")
endif()
# --- WebKit ---
# WebKit is either prebuilt and distributed via NPM, or you can pass WEBKIT_DIR to use a local build.
# We cannot include their CMake build files (TODO: explain why, for now ask @paperdave why)
#
# On Unix, this will pull from NPM the single package that is needed and use that
if(WIN32)
set(STATIC_LIB_EXT "lib")
set(libJavaScriptCore "JavaScriptCore")
set(libWTF "WTF")
else()
set(STATIC_LIB_EXT "a")
set(libJavaScriptCore "libJavaScriptCore")
set(libWTF "libWTF")
endif()
if(NOT WEBKIT_DIR)
if(WIN32)
message(FATAL_ERROR "Windows does not have prebuilt webkit yet. Please run release-windows.ps1 and pass the path to the built webkit with -DWEBKIT_DIR")
endif()
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "")
set(ASSERT_ENABLED "0")
if(USE_DEBUG_JSC)
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "-debug")
set(ASSERT_ENABLED "1")
elseif(NOT DEBUG)
set(BUN_WEBKIT_PACKAGE_NAME_SUFFIX "-lto")
set(ASSERT_ENABLED "0")
endif()
if (WIN32)
set(BUN_WEBKIT_PACKAGE_PLATFORM "win32")
elseif(APPLE)
set(BUN_WEBKIT_PACKAGE_PLATFORM "macos")
else()
set(BUN_WEBKIT_PACKAGE_PLATFORM "linux")
endif()
if(ARCH STREQUAL "x86_64")
set(BUN_WEBKIT_PACKAGE_ARCH "amd64")
elseif(ARCH MATCHES "aarch64|arm64|arm")
set(BUN_WEBKIT_PACKAGE_ARCH "arm64")
endif()
set(BUN_WEBKIT_PACKAGE_NAME "bun-webkit-${BUN_WEBKIT_PACKAGE_PLATFORM}-${BUN_WEBKIT_PACKAGE_ARCH}${BUN_WEBKIT_PACKAGE_NAME_SUFFIX}")
message(STATUS "Using Pre-built WebKit: ${BUN_WEBKIT_PACKAGE_NAME}")
execute_process(
COMMAND ${BUN_EXECUTABLE}
"${CMAKE_CURRENT_SOURCE_DIR}/src/codegen/download-webkit.ts"
"--outdir=${BUN_WORKDIR}/bun-webkit"
"--tag=${WEBKIT_TAG}"
"--package=${BUN_WEBKIT_PACKAGE_NAME}"
WORKING_DIRECTORY ${BUN_WORKDIR}
)
if(NOT EXISTS "${BUN_WORKDIR}/bun-webkit")
message(FATAL_ERROR "Prebuilt WebKit package ${BUN_WEBKIT_PACKAGE_NAME} failed to install")
endif()
set(WEBKIT_INCLUDE_DIR "${BUN_WORKDIR}/bun-webkit/include")
set(WEBKIT_LIB_DIR "${BUN_WORKDIR}/bun-webkit/lib")
else()
# Setting WEBKIT_DIR means you either have a path to the WebKit repo, or you have a path to packaged webkit
# Non-packaged webkit has CMakeLists.txt
if(EXISTS "${WEBKIT_DIR}/CMakeLists.txt")
# Since we may be doing a Debug build of Bun but with a Release build of JSC, we can't
# include their CMakeLists directly here, but rather we need to run `cmake` as a dependency
# of our build. It'll still have decent caching which is what really matters.
# cmake WEBKIT_DIR -B WEBKIT_DIR/WebKitBuild/WEBKIT_BUILD_TYPE
# -DPORT=JSCOnly
# -DENABLE_STATIC_JSC=ON
# -DENABLE_SINGLE_THREADED_VM_ENTRY_SCOPE=ON
# -DCMAKE_BUILD_TYPE=Debug
# -DENABLE_BUN_SKIP_FAILING_ASSERTIONS=ON
# -DUSE_THIN_ARCHIVES=OFF
# -DENABLE_FTL_JIT=ON
# -DCMAKE_C_COMPILER=(which clang-16)
# -DDCMAKE_CXX_COMPILER=(which clang++-16)
# -DDUSE_BUN_JSC_ADDITIONS=1
# -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld"
# -DCMAKE_AR=$(which llvm-ar)
# -DCMAKE_RANLIB=$(which llvm-ranlib)
# -DALLOW_LINE_AND_COLUMN_NUMBER_IN_BUILTINS=ON
# -G Ninja
# -DCMAKE_OSX_DEPLOYMENT_TARGET=11.0
# -DPTHREAD_JIT_PERMISSIONS_API=1
# -DUSE_PTHREAD_JIT_PERMISSIONS_API=ON
# -DENABLE_REMOTE_INSPECTOR=ON
message(FATAL_ERROR "TODO: Setting WEBKIT_DIR to the WebKit repository to enable automatic builds. For now you need to run the release script, and point to the packaged directory.")
else()
if(NOT EXISTS "${WEBKIT_DIR}/lib/${libWTF}.${STATIC_LIB_EXT}" OR NOT EXISTS "${WEBKIT_DIR}/lib/${libJavaScriptCore}.${STATIC_LIB_EXT}")
if(WEBKIT_DIR MATCHES "src/bun.js/WebKit$")
message(FATAL_ERROR "WebKit directory ${WEBKIT_DIR} does not contain all the required files for Bun. Did you forget to init submodules?")
endif()
message(FATAL_ERROR "WebKit directory ${WEBKIT_DIR} does not contain all the required files for Bun. Expected a path to the oven-sh/WebKit repository, or a path to a folder containing `include` and `lib`.")
endif()
set(WEBKIT_INCLUDE_DIR "${WEBKIT_DIR}/include")
set(WEBKIT_LIB_DIR "${WEBKIT_DIR}/lib")
message(STATUS "Using specified WebKit directory: ${WEBKIT_DIR}")
set(ASSERT_ENABLED "0")
message(STATUS "WebKit assertions: OFF")
endif()
endif()
# --- CMake Macros ---
# Append the given dependencies to the source file
macro(WEBKIT_ADD_SOURCE_DEPENDENCIES _source _deps)
set(_tmp)
get_source_file_property(_tmp ${_source} OBJECT_DEPENDS)
if(NOT _tmp)
set(_tmp "")
endif()
foreach(f ${_deps})
list(APPEND _tmp "${f}")
endforeach()
set_source_files_properties(${_source} PROPERTIES OBJECT_DEPENDS "${_tmp}")
unset(_tmp)
endmacro()
# --- BUILD ---
set(BUN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/src")
set(BUN_DEPS_DIR "${BUN_SRC}/deps")
set(BUN_CODEGEN_SRC "${BUN_SRC}/codegen")
file(GLOB BUN_CPP ${CONFIGURE_DEPENDS}
"${BUN_SRC}/deps/*.cpp"
"${BUN_SRC}/io/*.cpp"
"${BUN_SRC}/bun.js/modules/*.cpp"
"${BUN_SRC}/bun.js/bindings/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcore/*.cpp"
"${BUN_SRC}/bun.js/bindings/sqlite/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcrypto/*.cpp"
"${BUN_SRC}/bun.js/bindings/webcrypto/*/*.cpp"
"${BUN_SRC}/deps/picohttpparser/picohttpparser.c"
)
set(USOCKETS_SRC "${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets/src")
file(GLOB USOCKETS_FILES ${CONFIGURE_DEPENDS}
"${USOCKETS_SRC}/*.c"
"${USOCKETS_SRC}/eventing/*.c"
"${USOCKETS_SRC}/internal/*.c"
"${USOCKETS_SRC}/crypto/*.c"
"${USOCKETS_SRC}/crypto/*.cpp"
)
# --- Classes Generator ---
file(GLOB BUN_CLASSES_TS ${CONFIGURE_DEPENDS}
"${BUN_SRC}/bun.js/*.classes.ts"
"${BUN_SRC}/bun.js/api/*.classes.ts"
"${BUN_SRC}/bun.js/test/*.classes.ts"
"${BUN_SRC}/bun.js/webcore/*.classes.ts"
"${BUN_SRC}/bun.js/node/*.classes.ts"
)
add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/ZigGeneratedClasses.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.cpp"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+lazyStructureHeader.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+DOMClientIsoSubspaces.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+DOMIsoSubspaces.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses+lazyStructureImpl.h"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.zig"
COMMAND ${BUN_EXECUTABLE} "${BUN_CODEGEN_SRC}/generate-classes.ts" ${BUN_CLASSES_TS} "${BUN_WORKDIR}/codegen"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
MAIN_DEPENDENCY "${BUN_CODEGEN_SRC}/generate-classes.ts"
DEPENDS ${BUN_CLASSES_TS}
VERBATIM
COMMENT "Generating *.classes.ts bindings"
)
# --- JSSink Generator ---
add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/JSSink.cpp"
"${BUN_WORKDIR}/codegen/JSSink.h"
COMMAND ${BUN_EXECUTABLE} "src/codegen/generate-jssink.ts" "${BUN_WORKDIR}/codegen"
VERBATIM
MAIN_DEPENDENCY "src/codegen/generate-jssink.ts"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating JSSink"
)
# --- .lut.h Generator ---
set(BUN_OBJECT_LUT_SOURCES
bun.js/bindings/BunObject.cpp
bun.js/bindings/ZigGlobalObject.lut.txt
bun.js/bindings/JSBuffer.cpp
bun.js/bindings/BunProcess.cpp
bun.js/bindings/ProcessBindingConstants.cpp
bun.js/bindings/ProcessBindingNatives.cpp
)
set(BUN_HASH_LUT_GENERATOR "${BUN_CODEGEN_SRC}/create-hash-table.ts")
macro(GENERATE_HASH_LUT _input _output _display_name)
add_custom_command(
OUTPUT ${_output}
MAIN_DEPENDENCY ${BUN_HASH_LUT_GENERATOR}
DEPENDS ${_input}
COMMAND ${BUN_EXECUTABLE} ${BUN_HASH_LUT_GENERATOR} ${_input} ${_output}
VERBATIM
COMMENT "Generating ${_display_name}"
)
# list(APPEND JavaScriptCore_HEADERS ${_output})
WEBKIT_ADD_SOURCE_DEPENDENCIES(${_input} ${_output})
endmacro()
foreach(_file ${BUN_OBJECT_LUT_SOURCES})
if(NOT EXISTS "${BUN_SRC}/${_file}")
message(FATAL_ERROR "Could not find ${_file} needed for LUT generation")
endif()
get_filename_component(_name ${_file} NAME_WE)
# workaround for ZigGlobalObject
if(_name MATCHES "ZigGlobalObject")
set(_name "ZigGlobalObject")
endif()
GENERATE_HASH_LUT(${BUN_SRC}/${_file} ${BUN_WORKDIR}/codegen/${_name}.lut.h ${_name}.lut.h)
endforeach()
WEBKIT_ADD_SOURCE_DEPENDENCIES(${BUN_SRC}/bun.js/bindings/ZigGlobalObject.cpp ${BUN_WORKDIR}/codegen/ZigGlobalObject.lut.h)
# --- Identifier Cache ---
set(BUN_IDENTIFIER_CACHE_OUT
"${BUN_SRC}/js_lexer/id_continue_bitset.blob"
"${BUN_SRC}/js_lexer/id_continue_bitset.meta.blob"
"${BUN_SRC}/js_lexer/id_start_bitset.blob"
"${BUN_SRC}/js_lexer/id_start_bitset.meta.blob")
add_custom_command(
OUTPUT ${BUN_IDENTIFIER_CACHE_OUT}
MAIN_DEPENDENCY "${BUN_SRC}/js_lexer/identifier_data.zig"
DEPENDS "${BUN_SRC}/js_lexer/identifier_cache.zig"
COMMAND ${ZIG_COMPILER} run "${BUN_SRC}/js_lexer/identifier_data.zig"
VERBATIM
COMMENT "Building Identifier Cache"
)
# --- Bundled TS/JS ---
# Note: It's not worth doing this in parallel at the CMake/Ninja level, because this bundling
# requires all the JS files to be known, but also Bun will use all cores during bundling anyways.
file(GLOB BUN_TS_MODULES ${CONFIGURE_DEPENDS}
"${BUN_SRC}/js/node/*.ts"
"${BUN_SRC}/js/node/*.js"
"${BUN_SRC}/js/bun/*.js"
"${BUN_SRC}/js/bun/*.ts"
"${BUN_SRC}/js/thirdparty/*.js"
"${BUN_SRC}/js/thirdparty/*.ts"
"${BUN_SRC}/js/internal/*.js"
"${BUN_SRC}/js/internal/*.ts"
)
file(GLOB BUN_TS_FUNCTIONS ${CONFIGURE_DEPENDS} "${BUN_SRC}/js/builtins/*.ts")
add_custom_command(
OUTPUT
"${BUN_WORKDIR}/codegen/InternalModuleRegistryConstants.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+createInternalModuleById.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+enum.h"
"${BUN_WORKDIR}/codegen/InternalModuleRegistry+numberOfModules.h"
"${BUN_WORKDIR}/codegen/NativeModuleImpl.h"
"${BUN_WORKDIR}/codegen/ResolvedSourceTag.zig"
"${BUN_WORKDIR}/codegen/SyntheticModuleType.h"
COMMAND ${BUN_EXECUTABLE} "${BUN_SRC}/codegen/bundle-modules.ts" "${BUN_WORKDIR}"
DEPENDS ${BUN_TS_MODULES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Bundling JS modules"
)
WEBKIT_ADD_SOURCE_DEPENDENCIES(
"${BUN_SRC}/bun.js/bindings/InternalModuleRegistry.cpp"
"${BUN_WORKDIR}/codegen/InternalModuleRegistryConstants.h"
)
add_custom_command(
OUTPUT "${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.h"
COMMAND ${BUN_EXECUTABLE} "${BUN_SRC}/codegen/bundle-functions.ts" "${BUN_WORKDIR}"
DEPENDS ${BUN_TS_FUNCTIONS} "${BUN_SRC}/codegen/bundle-functions.ts"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Bundling JS builtin functions"
)
# --- Peechy API ---
add_custom_command(
OUTPUT "${BUN_SRC}/api/schema.js"
"${BUN_SRC}/api/schema.d.ts"
"${BUN_SRC}/api/schema.zig"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/node_modules/.bin/peechy"
"--schema" "${BUN_SRC}/api/schema.peechy"
"--esm" "${BUN_SRC}/api/schema.js"
"--ts" "${BUN_SRC}/api/schema.d.ts"
"--zig" "${BUN_SRC}/api/schema.zig"
COMMAND "${ZIG_COMPILER}" "fmt" "src/api/schema.zig"
COMMAND "${PRETTIER}" "--config=.prettierrc.cjs" "--write" "src/api/schema.js" "src/api/schema.d.ts"
DEPENDS "${BUN_SRC}/api/schema.peechy"
COMMENT "Building schema"
)
add_custom_command(
OUTPUT "${BUN_SRC}/analytics/analytics_schema.zig"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/node_modules/.bin/peechy"
"--schema" "${BUN_SRC}/analytics/schema.peechy"
"--zig" "${BUN_SRC}/analytics/analytics_schema.zig"
COMMAND "${ZIG_COMPILER}" "fmt" "${BUN_SRC}/analytics/analytics_schema.zig"
DEPENDS "${BUN_SRC}/api/schema.peechy"
COMMENT "Building analytics_schema.zig"
)
# --- Zig Object ---
file(GLOB ZIG_FILES
"${BUN_SRC}/*.zig"
"${BUN_SRC}/**/*.zig"
"${BUN_SRC}/**/**/*.zig"
"${BUN_SRC}/**/**/**/*.zig"
)
if(DEBUG)
set(BUN_ZIG_OBJ "${BUN_WORKDIR}/CMakeFiles/bun-debug.o")
else()
set(BUN_ZIG_OBJ "${BUN_WORKDIR}/CMakeFiles/bun.o")
endif()
add_custom_command(
OUTPUT "${BUN_ZIG_OBJ}"
COMMAND
"${ZIG_COMPILER}" "build" "obj"
"-Doutput-dir=${BUN_WORKDIR}/CMakeFiles"
"-Dgenerated-code=${BUN_WORKDIR}/codegen"
"-Dversion=${Bun_VERSION}"
"-Dcanary=$<IF:$<BOOL:${CANARY}>,true,false>"
"-Doptimize=${ZIG_OPTIMIZE}"
"-Dcpu=${CPU_TARGET}"
"-Dtarget=${ZIG_TARGET}"
DEPENDS
"${CMAKE_CURRENT_SOURCE_DIR}/build.zig"
"${ZIG_FILES}"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.zig"
"${BUN_WORKDIR}/codegen/ResolvedSourceTag.zig"
"${BUN_IDENTIFIER_CACHE_OUT}"
"${BUN_SRC}/api/schema.zig"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building zig code"
VERBATIM
# This is here to show Zig's progress indicator
USES_TERMINAL
)
set(BUN_EXTRA_SOURCES "")
if(WIN32)
set(BUN_EXTRA_SOURCES "${BUN_SRC}/bun.js/bindings/windows/musl-memmem.c")
include_directories("${BUN_SRC}/bun.js/bindings/windows")
endif()
# -- The Buntime™ ---
add_executable(
${bun}
${BUN_CPP}
${USOCKETS_FILES}
${BUN_ZIG_OBJ}
"${BUN_WORKDIR}/codegen/JSSink.cpp"
"${BUN_WORKDIR}/codegen/ZigGeneratedClasses.cpp"
"${BUN_WORKDIR}/codegen/WebCoreJSBuiltins.cpp"
"${BUN_ZIG_OBJ}"
"${BUN_EXTRA_SOURCES}"
)
set_target_properties(${bun} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS YES
CXX_VISIBILITY_PRESET hidden
C_STANDARD 17
C_STANDARD_REQUIRED YES
VISIBILITY_INLINES_HIDDEN YES
)
# Set /subsystem:console on bun for windows
if(WIN32)
set_target_properties(${bun} PROPERTIES LINK_FLAGS " /SUBSYSTEM:CONSOLE ")
endif()
add_compile_definitions(
# TODO: are all of these variables strictly necessary?
"_HAS_EXCEPTIONS=0"
"LIBUS_USE_OPENSSL=1"
"UWS_HTTPRESPONSE_NO_WRITEMARK=1"
"LIBUS_USE_BORINGSSL=1"
"WITH_BORINGSSL=1"
"STATICALLY_LINKED_WITH_JavaScriptCore=1"
"STATICALLY_LINKED_WITH_WTF=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"
"NOMINMAX"
"IS_BUILD"
"BUILDING_JSCONLY__"
"ASSERT_ENABLED=$<IF:$<CONFIG:ASSERT_ENABLED>,1,0>"
"BUN_DYNAMIC_JS_LOAD_PATH=\"${BUN_WORKDIR}/js\""
)
if(NOT ASSERT_ENABLED)
add_compile_definitions("NDEBUG=1")
endif()
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/packages/
${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets
${CMAKE_CURRENT_SOURCE_DIR}/packages/bun-usockets/src
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/webcore
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/webcrypto
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/bindings/sqlite
${CMAKE_CURRENT_SOURCE_DIR}/src/bun.js/modules
${CMAKE_CURRENT_SOURCE_DIR}/src/js/builtins
${CMAKE_CURRENT_SOURCE_DIR}/src/napi
${CMAKE_CURRENT_SOURCE_DIR}/src/deps
${CMAKE_CURRENT_SOURCE_DIR}/src/deps/picohttpparser
${WEBKIT_INCLUDE_DIR}
"${BUN_WORKDIR}/codegen"
)
# --- clang and linker flags ---
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT MSVC)
target_compile_options(${bun} PUBLIC -g3 -O1)
endif()
add_compile_definitions("BUN_DEBUG=1")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
if (MSVC)
target_compile_options(${bun} PUBLIC /O2)
else()
target_compile_options(${bun} PUBLIC -O3 -flto=full -emit-llvm)
endif()
endif()
if(NOT MSVC)
if(NOT CI)
target_compile_options(${bun} PRIVATE -fdiagnostics-color=always)
endif()
target_compile_options(${bun} PUBLIC
-march=${CPU_TARGET}
-mtune=${CPU_TARGET}
-fconstexpr-steps=1271242
-fconstexpr-depth=27
-fno-exceptions
-fvisibility=hidden
-fvisibility-inlines-hidden
-fno-rtti
-ferror-limit=${ERROR_LIMIT}
-fPIC
-fno-omit-frame-pointer
)
string(APPEND CMAKE_CXX_FLAGS " -std=c++2a ")
else() # MSVC
string(APPEND SUPPRESS_WARNING_NUMBERS
# JSC deletes operator delete to prevent accidental use
"/wd4291 "
# we use #pragma mark in some places
"/wd4068"
)
string(APPEND CMAKE_CXX_FLAGS " /EHsc /GR-")
string(APPEND CMAKE_C_FLAGS " /EHsc /GR- ${SUPPRESS_WARNING_NUMBERS} /experimental:c11atomics /std:c17")
string(APPEND CMAKE_CXX_FLAGS " /Zc:__cplusplus /Zc:inline /bigobj ${SUPPRESS_WARNING_NUMBERS}")
endif()
if(APPLE)
if(ARCH STREQUAL "x86_64")
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0")
endif()
target_link_options(${bun} PUBLIC "-dead_strip")
target_link_options(${bun} PUBLIC "-dead_strip_dylibs")
target_link_options(${bun} PUBLIC "-exported_symbols_list" "${BUN_SRC}/symbols.txt")
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/symbols.txt")
target_link_options(${bun} PUBLIC "-fno-keep-static-consts")
target_link_libraries(${bun} PRIVATE "resolv")
endif()
if(UNIX AND NOT APPLE)
target_link_options(${bun} PUBLIC
"-static-libstdc++"
"-static-libgcc"
"-fuse-ld=lld"
"-Wl,-z,now"
"-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=exp"
"-Wl,--wrap=log"
"-Wl,--wrap=log2"
"-Wl,--wrap=lstat"
"-Wl,--wrap=stat"
"-Wl,--wrap=fstat"
"-Wl,--wrap=fstatat"
"-Wl,--wrap=lstat64"
"-Wl,--wrap=stat64"
"-Wl,--wrap=fstat64"
"-Wl,--wrap=fstatat64"
"-Wl,--wrap=mknod"
"-Wl,--wrap=mknodat"
"-Wl,--wrap=statx "
"-Wl,--compress-debug-sections=zlib"
"-Bsymbolics-functions"
"-rdynamic"
"-Wl,--dynamic-list=${BUN_SRC}/symbols.dyn"
"-Wl,--version-script=${BUN_SRC}/linker.lds"
)
target_link_libraries(${bun} PRIVATE "c")
target_link_libraries(${bun} PRIVATE "libatomic.a")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libicudata.a")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libicui18n.a")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libicuuc.a")
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/linker.lds")
set_target_properties(${bun} PROPERTIES LINK_DEPENDS "${BUN_SRC}/symbols.dyn")
endif()
if(WIN32)
add_compile_definitions(
"WIN32"
"_WINDOWS"
"_CRT_SECURE_NO_WARNINGS"
"WIN32_LEAN_AND_MEAN=1"
)
set_property(TARGET ${bun} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
endif()
if(APPLE)
# TODO: a much better check can be done to find this path
find_path(
ICU4C_DIR NAMES lib/libicudata.a
PATHS ENV PATH /usr/local/opt/icu4c /opt/homebrew/opt/icu4c
)
find_path(
ICONV_DIR NAMES lib/libiconv.a
PATHS ENV PATH /usr/local/opt/libiconv /opt/homebrew/opt/libiconv
)
target_link_libraries(${bun} PRIVATE "icucore")
target_link_libraries(${bun} PRIVATE "${ICONV_DIR}/lib/libiconv.a")
target_link_libraries(${bun} PRIVATE "${ICU4C_DIR}/lib/libicudata.a")
target_link_libraries(${bun} PRIVATE "${ICU4C_DIR}/lib/libicui18n.a")
target_link_libraries(${bun} PRIVATE "${ICU4C_DIR}/lib/libicuuc.a")
include_directories(${ICU4C_DIR}/include)
endif()
# --- Stripped Binary "bun"
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT WIN32)
add_custom_command(
TARGET ${bun}
POST_BUILD
COMMAND ${DSYMUTIL} -o ${BUN_WORKDIR}/bun.dSYM ${BUN_WORKDIR}/${bun}
COMMENT "Stripping Symbols"
)
add_custom_command(
TARGET ${bun}
POST_BUILD
COMMAND ${STRIP} -s -x -S -o ${BUN_WORKDIR}/bun ${BUN_WORKDIR}/${bun}
COMMENT "Stripping Symbols"
)
endif()
# --- Dependencies ---
if(USE_CUSTOM_ZLIB AND (NOT WIN32))
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libz.a")
include_directories(${BUN_DEPS_DIR}/zlib/include)
else()
find_package(ZLIB REQUIRED)
target_link_libraries(${bun} PRIVATE ZLIB::ZLIB)
endif()
if(USE_CUSTOM_BORINGSSL)
include_directories(src/deps/boringssl/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/crypto.lib")
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/ssl.lib")
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/decrepit.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libcrypto.a")
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libssl.a")
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libdecrepit.a")
endif()
else()
include(FindBoringSSL)
FindBoringSSL(${bun})
endif()
if(USE_CUSTOM_LIBARCHIVE)
include_directories(src/deps/libarchive/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/archive.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libarchive.a")
endif()
else()
find_package(LibArchive REQUIRED)
target_link_libraries(${bun} PRIVATE LibArchive::LibArchive)
endif()
if(USE_CUSTOM_MIMALLOC)
include_directories(src/deps/mimalloc/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/mimalloc-static.lib")
elseif(APPLE)
# https://github.com/microsoft/mimalloc/issues/512
# Linking mimalloc via object file on macOS x64 can cause heap corruption
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libmimalloc.a")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libmimalloc.o")
endif()
else()
find_package(mimalloc REQUIRED)
target_link_libraries(${bun} PRIVATE mimalloc)
endif()
if(USE_CUSTOM_ZSTD)
include_directories(src/deps/zstd/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/zstd.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libzstd.a")
endif()
else()
find_package(zstd CONFIG REQUIRED)
target_link_libraries(${bun} PRIVATE zstd::libzstd)
endif()
if(USE_CUSTOM_CARES)
include_directories(src/deps/c-ares/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/cares.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libcares.a")
endif()
else()
find_package(c-ares CONFIG REQUIRED)
target_link_libraries(${bun} PRIVATE c-ares::cares)
endif()
if(USE_CUSTOM_BASE64)
include_directories(src/deps/base64/include)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/base64.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libbase64.a")
endif()
else()
find_package(base64 REQUIRED)
target_link_libraries(${bun} PRIVATE base64::base64)
endif()
if(NOT WIN32)
if (USE_CUSTOM_TINYCC)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/tcc.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/libtcc.a")
endif()
else()
find_package(tinycc REQUIRED)
target_link_libraries(${bun} PRIVATE tinycc::tinycc)
endif()
endif()
if(USE_CUSTOM_LOLHTML)
if (WIN32)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/lolhtml.lib")
else()
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/liblolhtml.a")
endif()
else()
find_package(lolhtml REQUIRED)
target_link_libraries(${bun} PRIVATE lolhtml::lolhtml)
endif()
if(WIN32)
if (USE_CUSTOM_LIBUV)
target_link_libraries(${bun} PRIVATE "${BUN_DEPS_DIR}/uv.lib")
else()
find_package(libuv CONFIG REQUIRED )
target_link_libraries(${bun} PRIVATE $<IF:$<TARGET_EXISTS:libuv::uv_a>,libuv::uv_a,libuv::uv>)
endif()
message(STATUS "Found libuv: ${libuv_LIBRARIES}")
endif()
if(USE_STATIC_SQLITE)
add_library(sqlite3 STATIC src/bun.js/bindings/sqlite/sqlite3.c)
target_include_directories(sqlite3 PUBLIC src/bun.js/bindings/sqlite)
target_link_libraries(${bun} PRIVATE sqlite3)
message(STATUS "Using static sqlite3")
target_compile_definitions(${bun} PRIVATE "LAZY_LOAD_SQLITE=0")
else()
message(STATUS "Using dynamicly linked sqlite3")
target_compile_definitions(${bun} PRIVATE "LAZY_LOAD_SQLITE=1")
endif()
if(NOT MSVC)
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libWTF.a")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libJavaScriptCore.a")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/libbmalloc.a")
else()
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/WTF.lib")
target_link_libraries(${bun} PRIVATE "${WEBKIT_LIB_DIR}/JavaScriptCore.lib")
if (WIN32)
string (APPEND CMAKE_CXX_FLAGS
" /external:anglebrackets /Gs- /Zi"
)
string (APPEND CMAKE_FLAGS
" /external:anglebrackets /Gs- /Zi"
)
set_target_properties(${bun} PROPERTIES LINK_FLAGS " /SUBSYSTEM:CONSOLE /STACK:4194304,2097152")
endif()
if (DEFINED ENV{VCPKG_ROOT})
include_directories($ENV{VCPKG_ROOT}/installed/x64-windows/include)
endif()
# include_directories(C:/Users/windo/Build/WebKit/WebKitBuild/WTF/DerivedSources)
# include_directories(C:/Users/windo/Build/WebKit/WebKitBuild/WTF/Headers)
target_include_directories(${bun} PUBLIC C:/Users/windo/Code/WebKit/WebKitLibraries/win/include)
target_link_directories(${bun} PUBLIC C:/Users/windo/Code/WebKit/WebKitLibraries/win/lib64)
target_link_directories(${bun} PUBLIC C:/Users/windo/Code/lib64)
target_link_libraries(${bun} PUBLIC icuuc icudt icutu icuio icuin icutest)
target_link_libraries(${bun} PUBLIC winmm ws2_32 bcrypt ntdll kernel32 shell32 shlwapi advapi32 vcruntime ucrt legacy_stdio_definitions)
endif()

View File

@@ -1,685 +1,90 @@
ARG DEBIAN_FRONTEND=noninteractive
ARG GITHUB_WORKSPACE=/build
ARG ZIG_PATH=${GITHUB_WORKSPACE}/zig
ARG WEBKIT_DIR=${GITHUB_WORKSPACE}/bun-webkit
ARG BUN_RELEASE_DIR=${GITHUB_WORKSPACE}/bun-release
ARG BUN_DEPS_OUT_DIR=${GITHUB_WORKSPACE}/bun-deps
ARG BUN_DIR=${GITHUB_WORKSPACE}/bun
ARG CPU_TARGET=native
ARG ARCH=x86_64
ARG BUILD_MACHINE_ARCH=x86_64
ARG TRIPLET=${ARCH}-linux-gnu
ARG BUILDARCH=amd64
ARG WEBKIT_TAG=2023-oct3-2
ARG ZIG_TAG=jul1
ARG ZIG_VERSION="0.12.0-dev.899+027aabf49"
ARG WEBKIT_BASENAME="bun-webkit-linux-$BUILDARCH"
FROM bitnami/minideb:bullseye as base
ARG CLANG_VERSION="16"
ARG NODE_VERSION="20"
ARG ZIG_VERSION="0.12.0-dev.1114+e8f3c4c4b"
ARG DEBIAN_FRONTEND="noninteractive"
RUN apt-get update -y \
&& install_packages \
ca-certificates \
curl \
gnupg \
&& echo "deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-${CLANG_VERSION} main" > /etc/apt/sources.list.d/llvm.list \
&& echo "deb-src https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-${CLANG_VERSION} main" >> /etc/apt/sources.list.d/llvm.list \
&& curl -fsSL "https://apt.llvm.org/llvm-snapshot.gpg.key" | apt-key add - \
&& echo "deb https://deb.nodesource.com/node_${NODE_VERSION}.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
&& curl -fsSL "https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key" | apt-key add - \
&& echo "deb https://apt.kitware.com/ubuntu/ focal main" > /etc/apt/sources.list.d/kitware.list \
&& curl -fsSL "https://apt.kitware.com/keys/kitware-archive-latest.asc" | apt-key add - \
&& install_packages \
wget \
bash \
lsb-release \
software-properties-common \
build-essential \
autoconf \
automake \
libtool \
pkg-config \
clang-${CLANG_VERSION} \
lld-${CLANG_VERSION} \
lldb-${CLANG_VERSION} \
clangd-${CLANG_VERSION} \
make \
cmake \
ccache \
ninja-build \
file \
gnupg \
libc-dev \
libxml2 \
libxml2-dev \
xz-utils \
libtcc-dev \
git \
tar \
rsync \
gzip \
unzip \
perl \
python3 \
ruby \
golang \
nodejs \
&& ln -s /usr/bin/clang-${CLANG_VERSION} /usr/bin/clang \
&& ln -s /usr/bin/clang++-${CLANG_VERSION} /usr/bin/clang++ \
&& ln -s /usr/bin/lld-${CLANG_VERSION} /usr/bin/lld \
&& ln -s /usr/bin/lldb-${CLANG_VERSION} /usr/bin/lldb \
&& ln -s /usr/bin/clangd-${CLANG_VERSION} /usr/bin/clangd \
&& ln -s /usr/bin/llvm-ar-${CLANG_VERSION} /usr/bin/llvm-ar \
&& arch="$(dpkg --print-architecture)" \
&& case "${arch##*-}" in \
amd64) variant="x86_64";; \
arm64) variant="aarch64";; \
*) echo "error: unsupported architecture: $arch"; exit 1 ;; \
esac \
&& echo "https://ziglang.org/builds/zig-linux-${variant}-${ZIG_VERSION}.tar.xz" \
&& curl -fsSL "https://ziglang.org/builds/zig-linux-${variant}-${ZIG_VERSION}.tar.xz" | tar xJ --strip-components=1 \
&& mv zig /usr/bin/zig \
&& curl "https://sh.rustup.rs" -sSf | sh -s -- -y \
&& mv ${HOME}/.cargo/bin/* /usr/bin/ \
&& npm install -g bun esbuild
ARG CXX="clang++-${CLANG_VERSION}"
ARG CC="clang-${CLANG_VERSION}"
ARG LD="lld-${CLANG_VERSION}"
ARG AR="/usr/bin/llvm-ar-${CLANG_VERSION}"
COPY package.json package.json
COPY Makefile Makefile
COPY CMakeLists.txt CMakeLists.txt
COPY src/ src/
COPY packages/bun-usockets/ packages/bun-usockets/
COPY packages/bun-uws/ packages/bun-uws/
COPY .scripts/ .scripts/
COPY .build/ .build/
COPY *.zig ./
RUN ./.build/base64.bash
ARG ZIG_FOLDERNAME=zig-linux-${BUILD_MACHINE_ARCH}-${ZIG_VERSION}
ARG ZIG_FILENAME=${ZIG_FOLDERNAME}.tar.xz
ARG WEBKIT_URL="https://github.com/oven-sh/WebKit/releases/download/$WEBKIT_TAG/${WEBKIT_BASENAME}.tar.gz"
ARG ZIG_URL="https://ziglang.org/builds/${ZIG_FILENAME}"
ARG GIT_SHA=""
ARG BUN_BASE_VERSION=1.0
FROM bitnami/minideb:bullseye as bun-base
RUN install_packages ca-certificates curl wget lsb-release software-properties-common gnupg gnupg1 gnupg2 && \
echo "deb https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-16 main" > /etc/apt/sources.list.d/llvm.list && \
echo "deb-src https://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-16 main" >> /etc/apt/sources.list.d/llvm.list && \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
install_packages \
cmake \
file \
git \
gnupg \
libc-dev \
libxml2 \
libxml2-dev \
make \
ninja-build \
perl \
python3 \
rsync \
ruby \
unzip \
clang-16 \
lld-16 \
lldb-16 \
clangd-16 \
xz-utils \
bash tar gzip ccache nodejs && \
npm install -g esbuild
ENV CXX=clang++-16
ENV CC=clang-16
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG BUILDARCH
ARG ZIG_PATH
ARG WEBKIT_URL
ARG ZIG_URL
ARG ZIG_FOLDERNAME
ARG ZIG_FILENAME
ENV WEBKIT_OUT_DIR=${WEBKIT_DIR}
ENV BUILDARCH=${BUILDARCH}
ENV AR=/usr/bin/llvm-ar-16
ENV ZIG "${ZIG_PATH}/zig"
ENV PATH="$ZIG/bin:$PATH"
ENV LD=lld-16
RUN mkdir -p $BUN_DIR $BUN_DEPS_OUT_DIR
FROM bun-base as bun-base-with-zig-and-webkit
WORKDIR $GITHUB_WORKSPACE
ADD $ZIG_URL .
RUN tar xf ${ZIG_FILENAME} && \
rm ${ZIG_FILENAME} && mv ${ZIG_FOLDERNAME} zig;
WORKDIR $GITHUB_WORKSPACE
ARG GITHUB_WORKSPACE
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG BUILDARCH
ARG ZIG_PATH
ARG WEBKIT_URL
ARG ZIG_URL
ARG WEBKIT_BASENAME
ADD ${WEBKIT_URL} .
RUN mkdir -p ${WEBKIT_DIR} && cd ${GITHUB_WORKSPACE} && \
gunzip ${WEBKIT_BASENAME}.tar.gz && tar -xf ${WEBKIT_BASENAME}.tar && \
cat ${WEBKIT_DIR}/include/cmakeconfig.h > /dev/null
LABEL org.opencontainers.image.title="bun base image with zig & webkit ${BUILDARCH} (glibc)"
LABEL org.opencontainers.image.source=https://github.com/oven-sh/bun
FROM bun-base as c-ares
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ENV CCACHE_DIR=/ccache
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/c-ares ${BUN_DIR}/src/deps/c-ares
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && make c-ares && rm -rf ${BUN_DIR}/src/deps/c-ares ${BUN_DIR}/Makefile
FROM bun-base as lolhtml
RUN install_packages build-essential && curl https://sh.rustup.rs -sSf | sh -s -- -y
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/lol-html ${BUN_DIR}/src/deps/lol-html
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache export PATH=$PATH:$HOME/.cargo/bin && export CC=$(which clang-16) && cd ${BUN_DIR} && \
make lolhtml && rm -rf src/deps/lol-html Makefile
FROM bun-base as mimalloc
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/mimalloc ${BUN_DIR}/src/deps/mimalloc
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache cd ${BUN_DIR} && \
make mimalloc && rm -rf src/deps/mimalloc Makefile
FROM bun-base as zlib
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/zlib ${BUN_DIR}/src/deps/zlib
WORKDIR $BUN_DIR
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && \
make zlib && rm -rf src/deps/zlib Makefile
FROM bun-base as libarchive
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
RUN install_packages autoconf automake libtool pkg-config
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/libarchive ${BUN_DIR}/src/deps/libarchive
ENV CCACHE_DIR=/ccache
WORKDIR $BUN_DIR
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && \
make libarchive && rm -rf src/deps/libarchive Makefile
FROM bun-base as tinycc
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
RUN install_packages libtcc-dev && cp /usr/lib/$(uname -m)-linux-gnu/libtcc.a ${BUN_DEPS_OUT_DIR}
FROM bun-base as boringssl
RUN install_packages golang
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/boringssl ${BUN_DIR}/src/deps/boringssl
WORKDIR $BUN_DIR
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache cd ${BUN_DIR} && make boringssl && rm -rf src/deps/boringssl Makefile
FROM bun-base as uws
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY packages/bun-uws ${BUN_DIR}/packages/bun-uws
COPY packages/bun-usockets ${BUN_DIR}/packages/bun-usockets
COPY src/deps/zlib ${BUN_DIR}/src/deps/zlib
COPY src/deps/boringssl/include ${BUN_DIR}/src/deps/boringssl/include
COPY src/deps/c-ares/include ${BUN_DIR}/src/deps/c-ares/include
COPY src/deps/libuwsockets.cpp ${BUN_DIR}/src/deps/libuwsockets.cpp
COPY src/deps/_libusockets.h ${BUN_DIR}/src/deps/_libusockets.h
WORKDIR $BUN_DIR
RUN cd $BUN_DIR && \
make uws && rm -rf packages/bun-uws Makefile
FROM bun-base as base64
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/base64 ${BUN_DIR}/src/deps/base64
WORKDIR $BUN_DIR
RUN cd $BUN_DIR && \
make base64 && rm -rf src/deps/base64 Makefile
FROM bun-base as picohttp
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/picohttpparser ${BUN_DIR}/src/deps/picohttpparser
COPY src/deps/*.c ${BUN_DIR}/src/deps/
COPY src/deps/*.h ${BUN_DIR}/src/deps/
WORKDIR $BUN_DIR
RUN cd $BUN_DIR && \
make picohttp
FROM bun-base-with-zig-and-webkit as identifier_cache
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
WORKDIR $BUN_DIR
COPY Makefile ${BUN_DIR}/Makefile
COPY src/js_lexer/identifier_data.zig ${BUN_DIR}/src/js_lexer/identifier_data.zig
COPY src/js_lexer/identifier_cache.zig ${BUN_DIR}/src/js_lexer/identifier_cache.zig
RUN cd $BUN_DIR && \
make identifier-cache && rm -rf zig-cache Makefile
FROM bun-base-with-zig-and-webkit as node_fallbacks
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
WORKDIR $BUN_DIR
COPY Makefile ${BUN_DIR}/Makefile
COPY src/node-fallbacks ${BUN_DIR}/src/node-fallbacks
RUN cd $BUN_DIR && \
make node-fallbacks && rm -rf src/node-fallbacks/node_modules Makefile
FROM bun-base-with-zig-and-webkit as prepare_release
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
WORKDIR $BUN_DIR
COPY ./root.zig ${BUN_DIR}/root.zig
COPY ./src ${BUN_DIR}/src
COPY ./build.zig ${BUN_DIR}/build.zig
COPY ./completions ${BUN_DIR}/completions
COPY ./packages ${BUN_DIR}/packages
COPY ./src/build-id ${BUN_DIR}/src/build-id
COPY ./package.json ${BUN_DIR}/package.json
COPY ./misctools ${BUN_DIR}/misctools
COPY Makefile ${BUN_DIR}/Makefile
FROM prepare_release as compile_release_obj
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY .prettierrc.cjs ${BUN_DIR}/.prettierrc.cjs
WORKDIR $BUN_DIR
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
ARG ARCH
ARG TRIPLET
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ARG GIT_SHA
ARG BUN_BASE_VERSION
ENV BUN_BASE_VERSION=${BUN_BASE_VERSION}
ENV GIT_SHA=${GIT_SHA}
COPY --from=identifier_cache ${BUN_DIR}/src/js_lexer/*.blob ${BUN_DIR}/src/js_lexer/
COPY --from=node_fallbacks ${BUN_DIR}/src/node-fallbacks/out ${BUN_DIR}/src/node-fallbacks/out
COPY ./src/build-id ${BUN_DIR}/src/build-id
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && mkdir -p src/bun.js/bindings-obj && rm -rf $HOME/.cache zig-cache && make prerelease && \
mkdir -p $BUN_RELEASE_DIR && \
OUTPUT_DIR=/tmp/bun-${TRIPLET}-${GIT_SHA} $ZIG_PATH/zig build obj -Doutput-dir=/tmp/bun-${TRIPLET}-${GIT_SHA} -Doptimize=ReleaseFast -Dtarget="${TRIPLET}" -Dcpu="${CPU_TARGET}" && \
cp /tmp/bun-${TRIPLET}-${GIT_SHA}/bun.o /tmp/bun-${TRIPLET}-${GIT_SHA}/bun-${BUN_BASE_VERSION}.$(cat ${BUN_DIR}/src/build-id).o && cd / && rm -rf $BUN_DIR
FROM scratch as build_release_obj
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG GIT_SHA
ARG TRIPLET
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY --from=compile_release_obj /tmp/bun-${TRIPLET}-${GIT_SHA}/*.o /
FROM prepare_release as compile_cpp
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY .prettierrc.cjs ${BUN_DIR}/.prettierrc.cjs
WORKDIR $BUN_DIR
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
# Required for webcrypto bindings
COPY src/deps/boringssl/include ${BUN_DIR}/src/deps/boringssl/include
ENV CCACHE_DIR=/ccache
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && mkdir -p src/bun.js/bindings-obj && rm -rf $HOME/.cache zig-cache && mkdir -p $BUN_RELEASE_DIR && \
make release-bindings -j10 && mv src/bun.js/bindings-obj/* /tmp
FROM bun-base as sqlite
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ENV CCACHE_DIR=/ccache
COPY Makefile ${BUN_DIR}/Makefile
COPY src/bun.js/bindings/sqlite ${BUN_DIR}/src/bun.js/bindings/sqlite
COPY .prettierrc.cjs ${BUN_DIR}/.prettierrc.cjs
WORKDIR $BUN_DIR
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && make sqlite
FROM bun-base as zstd
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
ENV CCACHE_DIR=/ccache
COPY Makefile ${BUN_DIR}/Makefile
COPY src/deps/zstd ${BUN_DIR}/src/deps/zstd
COPY .prettierrc.cjs ${BUN_DIR}/.prettierrc.cjs
WORKDIR $BUN_DIR
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
RUN --mount=type=cache,target=/ccache cd $BUN_DIR && make zstd
FROM scratch as build_release_cpp
COPY --from=compile_cpp /tmp/*.o /
FROM prepare_release as build_release
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
ARG CPU_TARGET
ENV CPU_TARGET=${CPU_TARGET}
COPY Makefile ${BUN_DIR}/Makefile
COPY .prettierrc.cjs ${BUN_DIR}/.prettierrc.cjs
WORKDIR $BUN_DIR
ENV JSC_BASE_DIR=${WEBKIT_DIR}
ENV LIB_ICU_PATH=${WEBKIT_DIR}/lib
COPY --from=zlib ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=base64 ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=libarchive ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=boringssl ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=lolhtml ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=mimalloc ${BUN_DEPS_OUT_DIR}/*.o ${BUN_DEPS_OUT_DIR}/
COPY --from=picohttp ${BUN_DEPS_OUT_DIR}/*.o ${BUN_DEPS_OUT_DIR}/
COPY --from=sqlite ${BUN_DEPS_OUT_DIR}/*.o ${BUN_DEPS_OUT_DIR}/
COPY --from=zstd ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=tinycc ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=uws ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=uws ${BUN_DEPS_OUT_DIR}/*.o ${BUN_DEPS_OUT_DIR}/
COPY --from=c-ares ${BUN_DEPS_OUT_DIR}/*.a ${BUN_DEPS_OUT_DIR}/
COPY --from=build_release_obj /*.o /tmp
COPY --from=build_release_cpp /*.o ${BUN_DIR}/src/bun.js/bindings-obj/
COPY --from=build_release_cpp /*.a ${BUN_DEPS_OUT_DIR}/
RUN cd $BUN_DIR && mkdir -p ${BUN_RELEASE_DIR} && make bun-relink copy-to-bun-release-dir && \
rm -rf $HOME/.cache zig-cache misctools package.json build-id completions build.zig $(BUN_DIR)/packages
FROM scratch as artifact
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
COPY --from=build_release ${BUN_RELEASE_DIR}/bun /bun
COPY --from=build_release ${BUN_RELEASE_DIR}/bun-profile /bun-profile
COPY --from=build_release ${BUN_DEPS_OUT_DIR}/* /bun-dependencies
COPY --from=build_release_obj /*.o /bun-obj
FROM prepare_release as build_unit
ARG DEBIAN_FRONTEND
ARG GITHUB_WORKSPACE
ARG ZIG_PATH
# Directory extracts to "bun-webkit"
ARG WEBKIT_DIR
ARG BUN_RELEASE_DIR
ARG BUN_DEPS_OUT_DIR
ARG BUN_DIR
WORKDIR $BUN_DIR
ENV PATH "$ZIG_PATH:$PATH"
ENV LIB_ICU_PATH "${WEBKIT_DIR}/lib"
CMD make headers \
api \
analytics \
bun_error \
fallback_decoder \
bindings -j10 && \
make \
run-all-unit-tests
# FROM bun-test-base as test_base
# ARG DEBIAN_FRONTEND=noninteractive
# ARG GITHUB_WORKSPACE=/build
# ARG ZIG_PATH=${GITHUB_WORKSPACE}/zig
# # Directory extracts to "bun-webkit"
# ARG WEBKIT_DIR=${GITHUB_WORKSPACE}/bun-webkit
# ARG BUN_RELEASE_DIR=${GITHUB_WORKSPACE}/bun-release
# ARG BUN_DEPS_OUT_DIR=${GITHUB_WORKSPACE}/bun-deps
# ARG BUN_DIR=${GITHUB_WORKSPACE}/bun
# ARG BUILDARCH=amd64
# RUN groupadd -r chromium && useradd -d ${BUN_DIR} -M -r -g chromium -G audio,video chromium \
# && mkdir -p /home/chromium/Downloads && chown -R chromium:chromium /home/chromium
# USER chromium
# WORKDIR $BUN_DIR
# ENV NPM_CLIENT bun
# ENV PATH "${BUN_DIR}/packages/bun-linux-x64:${BUN_DIR}/packages/bun-linux-aarch64:$PATH"
# ENV CI 1
# ENV BROWSER_EXECUTABLE /usr/bin/chromium
# COPY ./test ${BUN_DIR}/test
# COPY Makefile ${BUN_DIR}/Makefile
# COPY package.json ${BUN_DIR}/package.json
# COPY .docker/run-test.sh ${BUN_DIR}/run-test.sh
# COPY ./bun.lockb ${BUN_DIR}/bun.lockb
# # # We don't want to worry about architecture differences in this image
# COPY --from=release /opt/bun/bin/bun ${BUN_DIR}/packages/bun-linux-aarch64/bun
# COPY --from=release /opt/bun/bin/bun ${BUN_DIR}/packages/bun-linux-x64/bun
# USER root
# RUN chgrp -R chromium ${BUN_DIR} && chmod g+rwx ${BUN_DIR} && chown -R chromium:chromium ${BUN_DIR}
# USER chromium
# CMD [ "bash", "run-test.sh" ]
# FROM release

View File

@@ -39,7 +39,6 @@ endif
MIN_MACOS_VERSION ?= $(DEFAULT_MIN_MACOS_VERSION)
BUN_BASE_VERSION = 1.0
CI ?= false
AR=
@@ -66,7 +65,7 @@ PACKAGE_JSON_VERSION = $(BUN_BASE_VERSION).$(BUILD_ID)
BUN_BUILD_TAG = bun-v$(PACKAGE_JSON_VERSION)
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")
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_RELEASE_DIR ?= $(WEBKIT_DIR)/WebKitBuild/Release
@@ -74,7 +73,7 @@ WEBKIT_DEBUG_DIR ?= $(WEBKIT_DIR)/WebKitBuild/Debug
WEBKIT_RELEASE_DIR_LTO ?= $(WEBKIT_DIR)/WebKitBuild/ReleaseLTO
NPM_CLIENT ?= $(shell which bun 2>/dev/null || which npm 2>/dev/null)
NPM_CLIENT = "$(shell which bun 2>/dev/null || which npm 2>/dev/null)"
ZIG ?= $(shell which zig 2>/dev/null || echo -e "error: Missing zig. Please make sure zig is in PATH. Or set ZIG=/path/to-zig-executable")
# We must use the same compiler version for the JavaScriptCore bindings and JavaScriptCore
@@ -187,11 +186,6 @@ BUN_CFLAGS = $(MACOS_MIN_FLAG) $(MARCH_NATIVE) $(OPTIMIZATION_LEVEL) -fno-excep
BUN_TMP_DIR := /tmp/make-bun
CFLAGS=$(CFLAGS_WITHOUT_MARCH) $(MARCH_NATIVE)
DEFAULT_USE_BMALLOC := 1
USE_BMALLOC ?= DEFAULT_USE_BMALLOC
# Set via postinstall
ifeq (,$(realpath $(JSC_BASE_DIR)))
JSC_BASE_DIR = $(realpath $(firstword $(wildcard bun-webkit)))
@@ -380,9 +374,7 @@ ICU_FLAGS ?=
# Ideally, we could just look up the linker search paths
ifeq ($(OS_NAME),linux)
LIB_ICU_PATH ?= $(JSC_LIB)
ICU_FLAGS += $(LIB_ICU_PATH)/libicuuc.a $(LIB_ICU_PATH)/libicudata.a $(LIB_ICU_PATH)/libicui18n.a
else
LIB_ICU_PATH ?= $(BUN_DEPS_DIR)
ICU_FLAGS += $(LIB_ICU_PATH)/libicuuc.a $(LIB_ICU_PATH)/libicudata.a $(LIB_ICU_PATH)/libicui18n.a
endif
ifeq ($(OS_NAME),darwin)
@@ -764,7 +756,7 @@ USOCKETS_DIR = $(BUN_DIR)/packages/bun-usockets
USOCKETS_SRC_DIR = $(USOCKETS_DIR)/src
usockets:
rm -rf $(USOCKETS_DIR)/*.i $(USOCKETS_DIR)/*.bc $(USOCKETS_DIR)/*.o $(USOCKETS_DIR)/*.s $(USOCKETS_DIR)/*.ii $(USOCKETS_DIR)/*.s
rm -rf $(USOCKETS_DIR)/*.i $(USOCKETS_DIR)/*.bc $(USOCKETS_DIR)/*.o $(USOCKETS_DIR)/*.s $(USOCKETS_DIR)/*.ii $(USOCKETS_DIR)/*.s $(BUN_DEPS_OUT_DIR)/libusockets.a
cd $(USOCKETS_DIR) && $(CC_WITH_CCACHE) -I$(USOCKETS_SRC_DIR) -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc $(EMIT_LLVM_FOR_RELEASE) $(MACOS_MIN_FLAG) -fPIC $(CFLAGS) $(UWS_CC_FLAGS) -save-temps -I$(BUN_DEPS_DIR)/uws/uSockets/src $(UWS_LDFLAGS) -g $(DEFAULT_LINKER_FLAGS) $(PLATFORM_LINKER_FLAGS) $(OPTIMIZATION_LEVEL) -c $(wildcard $(USOCKETS_SRC_DIR)/*.c) $(wildcard $(USOCKETS_SRC_DIR)/**/*.c)
cd $(USOCKETS_DIR) && $(CXX_WITH_CCACHE) -I$(USOCKETS_SRC_DIR) -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc $(EMIT_LLVM_FOR_RELEASE) $(MACOS_MIN_FLAG) -fPIC $(CXXFLAGS) $(UWS_CXX_FLAGS) -save-temps -I$(BUN_DEPS_DIR)/uws/uSockets/src $(UWS_LDFLAGS) -g $(DEFAULT_LINKER_FLAGS) $(PLATFORM_LINKER_FLAGS) $(OPTIMIZATION_LEVEL) -c $(wildcard $(USOCKETS_SRC_DIR)/*.cpp) $(wildcard $(USOCKETS_SRC_DIR)/**/*.cpp)
cd $(USOCKETS_DIR) && $(AR) rcvs $(BUN_DEPS_OUT_DIR)/libusockets.a $(USOCKETS_DIR)/*.{o,bc}
@@ -1485,12 +1477,12 @@ wasm-return1:
$(ZIG) build-lib -OReleaseSmall test/bun.js/wasm-return-1-test.zig -femit-bin=test/bun.js/wasm-return-1-test.wasm -target wasm32-freestanding
generate-classes:
bun src/bun.js/scripts/generate-classes.ts
bun src/codegen/generate-classes.ts
$(ZIG) fmt src/bun.js/bindings/generated_classes.zig
$(CLANG_FORMAT) -i src/bun.js/bindings/ZigGeneratedClasses.h src/bun.js/bindings/ZigGeneratedClasses.cpp
generate-sink:
bun src/bun.js/scripts/generate-jssink.js
bun src/codegen/generate-jssink.js
$(CLANG_FORMAT) -i src/bun.js/bindings/JSSink.cpp src/bun.js/bindings/JSSink.h
./src/bun.js/scripts/create_hash_table src/bun.js/bindings/JSSink.cpp > src/bun.js/bindings/JSSinkLookupTable.h
$(SED) -i -e 's/#include "Lookup.h"//' src/bun.js/bindings/JSSinkLookupTable.h
@@ -1955,4 +1947,8 @@ setup: vendor-dev identifier-cache clean-bindings
.PHONY: help
help: ## to print this help
@echo "For detailed build instructions, see https://bun.sh/docs/project/contributing"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m \t\t%s\n", $$1, $$2}' $(MAKEFILE_LIST)
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m \t\t%s\n", $$1, $$2}' $(MAKEFILE_LIST)
print_linker_flags:
@echo $(CLANG_FLAGS)

View File

@@ -6,23 +6,30 @@ bench("await 1", async function () {
return await 1;
});
function callnextTick(resolve) {
process.nextTick(resolve);
}
if (typeof process !== "undefined") {
bench("process.nextTick x 100", async function () {
var remaining = 100;
var cb, promise;
promise = new Promise(resolve => {
cb = resolve;
});
function awaitNextTick() {
return new Promise(callnextTick);
}
for (let i = 0; i < 100; i++) {
process.nextTick(() => {
if (--remaining === 0) cb();
});
}
bench("promise.nextTick", async function () {
return awaitNextTick();
});
return promise;
});
bench("await 1 x 100", async function () {
for (let i = 0; i < 100; i++) await 1;
});
}
bench("await new Promise(resolve => resolve())", async function () {
await new Promise(resolve => resolve());
});
bench("Promise.all(Array.from({length: 100}, () => new Promise((resolve) => resolve())))", async function () {
return Promise.all(Array.from({ length: 100 }, () => Promise.resolve(1)));
});
await run();

View File

@@ -13,6 +13,11 @@ fn moduleSource(comptime out: []const u8) FileSource {
}
}
fn exists(path: []const u8) bool {
_ = std.fs.openFileAbsolute(path, .{ .mode = .read_only }) catch return false;
return true;
}
const color_map = std.ComptimeStringMap([]const u8, .{
&.{ "black", "30m" },
&.{ "blue", "34m" },
@@ -48,11 +53,37 @@ fn addInternalPackages(b: *Build, step: *CompileStep, _: std.mem.Allocator, _: [
};
step.addModule("async_io", io);
step.addModule("zlib-internal", brk: {
if (target.isWindows()) {
break :brk b.createModule(.{ .source_file = FileSource.relative("src/deps/zlib.win32.zig") });
}
break :brk b.createModule(.{ .source_file = FileSource.relative("src/deps/zlib.posix.zig") });
});
var async_: *Module = brk: {
if (target.isDarwin() or target.isLinux() or target.isFreeBSD()) {
break :brk b.createModule(.{
.source_file = FileSource.relative("src/async/posix_event_loop.zig"),
});
} else if (target.isWindows()) {
break :brk b.createModule(.{
.source_file = FileSource.relative("src/async/windows_event_loop.zig"),
});
}
break :brk b.createModule(.{
.source_file = FileSource.relative("src/async/stub_event_loop.zig"),
});
};
step.addModule("async", async_);
}
const BunBuildOptions = struct {
canary: bool = false,
sha: [:0]const u8 = "",
version: []const u8 = "",
baseline: bool = false,
bindgen: bool = false,
sizegen: bool = false,
@@ -61,6 +92,8 @@ const BunBuildOptions = struct {
runtime_js_version: u64 = 0,
fallback_html_version: u64 = 0,
tinycc: bool = true,
pub fn updateRuntime(this: *BunBuildOptions) anyerror!void {
if (std.fs.cwd().openFile("src/runtime.out.js", .{ .mode = .read_only })) |file| {
defer file.close();
@@ -92,6 +125,11 @@ const BunBuildOptions = struct {
pub fn step(this: BunBuildOptions, b: anytype) *std.build.OptionsStep {
var opts = b.addOptions();
opts.addOption(@TypeOf(this.canary), "is_canary", this.canary);
opts.addOption(
std.SemanticVersion,
"version",
std.SemanticVersion.parse(this.version) catch @panic(b.fmt("Invalid version: {s}", .{this.version})),
);
opts.addOption(@TypeOf(this.sha), "sha", this.sha);
opts.addOption(@TypeOf(this.baseline), "baseline", this.baseline);
opts.addOption(@TypeOf(this.bindgen), "bindgen", this.bindgen);
@@ -99,6 +137,7 @@ const BunBuildOptions = struct {
opts.addOption(@TypeOf(this.base_path), "base_path", this.base_path);
opts.addOption(@TypeOf(this.runtime_js_version), "runtime_js_version", this.runtime_js_version);
opts.addOption(@TypeOf(this.fallback_html_version), "fallback_html_version", this.fallback_html_version);
opts.addOption(@TypeOf(this.tinycc), "tinycc", this.tinycc);
return opts;
}
};
@@ -151,7 +190,7 @@ pub fn build_(b: *Build) !void {
if (!std.mem.eql(u8, @import("builtin").zig_version_string, required_zig_version)) {
const colors = std.io.getStdErr().supportsAnsiEscapeCodes();
std.debug.print(
"{s}WARNING:\nBun requires zig version '{s}', but found '{s}', build may fail...\nMake sure you installed the right version as per https://bun.sh/docs/project/development#install-zig\n{s}You can update to the right version using 'zigup {s}'\n\n",
"{s}WARNING:\nBun requires Zig version '{s}', but found '{s}', build may fail...\nMake sure you installed the right version as per https://bun.sh/docs/project/contributing#install-zig\n{s}You can update to the right version using 'zigup {s}'\n\n",
.{
if (colors) "\x1b[1;33m" else "",
required_zig_version,
@@ -171,6 +210,8 @@ pub fn build_(b: *Build) !void {
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
optimize = b.standardOptimizeOption(.{});
const generated_code_directory = b.option([]const u8, "generated-code", "Set the generated code directory") orelse "./";
var output_dir_buf = std.mem.zeroes([4096]u8);
var bin_label = if (optimize == std.builtin.OptimizeMode.Debug) "packages/debug-bun-" else "packages/bun-";
@@ -203,7 +244,7 @@ pub fn build_(b: *Build) !void {
var triplet = triplet_buf[0 .. osname.len + cpuArchName.len + 1];
if (b.option([]const u8, "output-dir", "target to install to") orelse std.os.getenv("OUTPUT_DIR")) |output_dir_| {
if (b.option([]const u8, "output-dir", "target to install to") orelse b.env_map.get("OUTPUT_DIR")) |output_dir_| {
output_dir = try pathRel(b.allocator, b.install_prefix, output_dir_);
} else {
const output_dir_base = try std.fmt.bufPrint(&output_dir_buf, "{s}{s}", .{ bin_label, triplet });
@@ -236,6 +277,21 @@ pub fn build_(b: *Build) !void {
.main_mod_path = .{ .cwd_relative = b.pathFromRoot(".") },
});
if (!exists(b.pathFromRoot(try std.fs.path.join(b.allocator, &.{
"src",
"js_lexer",
"id_continue_bitset.blob",
})))) {
const identifier_data = b.pathFromRoot(try std.fs.path.join(b.allocator, &.{ "src", "js_lexer", "identifier_data.zig" }));
var run_step = b.addSystemCommand(&.{
b.zig_exe,
"run",
identifier_data,
});
run_step.has_side_effects = true;
obj.step.dependOn(&run_step.step);
}
b.reference_trace = 16;
var default_build_options: BunBuildOptions = brk: {
@@ -262,9 +318,12 @@ pub fn build_(b: *Build) !void {
}
}
const is_canary = (std.os.getenvZ("BUN_CANARY") orelse "0")[0] == '1';
const is_canary =
b.option(bool, "canary", "Treat this as a canary build") orelse
((b.env_map.get("BUN_CANARY") orelse "0")[0] == '1');
break :brk .{
.canary = is_canary,
.version = b.option([]const u8, "version", "Value of `Bun.version`") orelse "0.0.0",
.sha = git_sha,
.baseline = is_baseline,
.bindgen = false,
@@ -319,13 +378,21 @@ pub fn build_(b: *Build) !void {
obj.addOptions("build_options", actual_build_options.step(b));
obj.linkLibC();
// Generated Code
obj.addModule("generated/ZigGeneratedClasses.zig", b.createModule(.{
.source_file = .{ .path = b.fmt("{s}/ZigGeneratedClasses.zig", .{generated_code_directory}) },
}));
obj.addModule("generated/ResolvedSourceTag.zig", b.createModule(.{
.source_file = .{ .path = b.fmt("{s}/ResolvedSourceTag.zig", .{generated_code_directory}) },
}));
obj.linkLibC();
obj.dll_export_fns = true;
obj.strip = false;
obj.bundle_compiler_rt = false;
obj.omit_frame_pointer = optimize != .Debug;
obj.subsystem = .Console;
// Disable stack probing on x86 so we don't need to include compiler_rt
if (target.getCpuArch().isX86()) obj.disable_stack_probing = true;
if (target.getCpuArch().isX86() or target.isWindows()) obj.disable_stack_probing = true;
if (b.option(bool, "for-editor", "Do not emit bin, just check for errors") orelse false) {
// obj.emit_bin = .no_emit;

BIN
bun.lockb

Binary file not shown.

View File

@@ -27,7 +27,7 @@ pub fn main() anyerror!void {
var args = std.mem.bytesAsSlice([]u8, try std.process.argsAlloc(allocator));
const to_resolve = args[args.len - 1];
const cwd = try std.process.getCwdAlloc(allocator);
const cwd = try bun.getcwdAlloc(allocator);
var path: []u8 = undefined;
var out_buffer: [bun.MAX_PATH_BYTES]u8 = undefined;

View File

@@ -47,7 +47,7 @@ pub fn main() anyerror!void {
bun.asByteSlice(args[args.len - 1]),
};
const tarball_path = path_handler.joinAbsStringBuf(try std.process.getCwdAlloc(std.heap.c_allocator), &tarball_path_buf, &parts, .auto);
const tarball_path = path_handler.joinAbsStringBuf(try bun.getcwdAlloc(std.heap.c_allocator), &tarball_path_buf, &parts, .auto);
Output.prettyErrorln("Tarball Path: {s}", .{tarball_path});
var folder = basename;

View File

@@ -15,9 +15,11 @@
},
"private": true,
"scripts": {
"build": "cmake . -DCMAKE_BUILD_TYPE=Debug -GNinja -Bbuild && ninja -Cbuild",
"build:release": "cmake . -DCMAKE_BUILD_TYPE=Release -GNinja -Bbuild-release && ninja -Cbuild-release",
"build-runtime": "esbuild --target=esnext --bundle src/runtime/index.ts --format=iife --platform=browser --global-name=BUN_RUNTIME > src/runtime.out.js; cat src/runtime.footer.js >> src/runtime.out.js",
"build-fallback": "esbuild --target=esnext --bundle src/fallback.ts --format=iife --platform=browser --minify > src/fallback.out.js",
"postinstall": "bash .scripts/postinstall.sh",
"postinstall_not_anymore": "bash .scripts/postinstall.sh",
"typecheck": "tsc --noEmit && cd test && bun run typecheck",
"fmt": "prettier --write --cache './{src,test,bench,packages/{bun-types,bun-inspector-*,bun-vscode,bun-debug-adapter-protocol}}/**/*.{mjs,ts,tsx,js,jsx}'",
"lint": "eslint './**/*.d.ts' --cache",
@@ -26,8 +28,7 @@
"devDependencies": {
"@types/react": "^18.0.25",
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"bun-webkit": "0.0.1-1a49a1f94bf42ab4f8c6b11d7bbbb21e491d2d62"
"@typescript-eslint/parser": "^5.31.0"
},
"version": "0.0.0",
"prettier": "./.prettierrc.cjs"

View File

@@ -566,10 +566,10 @@ void *us_socket_context_ext(int ssl, struct us_socket_context_t *context) {
}
void us_socket_context_on_handshake(int ssl, struct us_socket_context_t *context, void (*on_handshake)(struct us_socket_context_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data) {
void us_socket_context_on_handshake(int ssl, struct us_socket_context_t *context, void (*on_handshake)(struct us_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data) {
#ifndef LIBUS_NO_SSL
if (ssl) {
us_internal_on_ssl_handshake((struct us_internal_ssl_socket_context_t *) context, (void (*)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data))on_handshake, custom_data);
us_internal_on_ssl_handshake((struct us_internal_ssl_socket_context_t *) context, (us_internal_on_handshake_t)on_handshake, custom_data);
return;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,90 @@
// MSVC doesn't support C11 stdatomic.h propertly yet.
// so we use C++ std::atomic instead.
#include "./internal/internal.h"
#include "./root_certs.h"
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <atomic>
static const int root_certs_size = sizeof(root_certs) / sizeof(root_certs[0]);
static X509* root_cert_instances[sizeof(root_certs) / sizeof(root_certs[0])] = {NULL};
static std::atomic_flag root_cert_instances_lock = ATOMIC_FLAG_INIT;
static std::atomic_bool root_cert_instances_initialized = 0;
// This callback is used to avoid the default passphrase callback in OpenSSL
// which will typically prompt for the passphrase. The prompting is designed
// for the OpenSSL CLI, but works poorly for this case because it involves
// synchronous interaction with the controlling terminal, something we never
// want, and use this function to avoid it.
int us_no_password_callback(char* buf, int size, int rwflag, void* u) {
return 0;
}
static X509 * us_ssl_ctx_get_X509_without_callback_from(struct us_cert_string_t content) {
X509 *x = NULL;
BIO *in;
ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate()
in = BIO_new_mem_buf(content.str, content.len);
if (in == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
goto end;
}
x = PEM_read_bio_X509(in, NULL, us_no_password_callback, NULL);
if (x == NULL) {
OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB);
goto end;
}
return x;
end:
X509_free(x);
BIO_free(in);
return NULL;
}
static void us_internal_init_root_certs() {
if(std::atomic_load(&root_cert_instances_initialized) == 1) return;
while(atomic_flag_test_and_set_explicit(&root_cert_instances_lock, std::memory_order_acquire));
if(!atomic_exchange(&root_cert_instances_initialized, 1)) {
for (size_t i = 0; i < root_certs_size; i++) {
root_cert_instances[i] = us_ssl_ctx_get_X509_without_callback_from(root_certs[i]);
}
}
atomic_flag_clear_explicit(&root_cert_instances_lock, std::memory_order_release);
}
extern "C" int us_internal_raw_root_certs(struct us_cert_string_t** out) {
*out = root_certs;
return root_certs_size;
}
extern "C" X509_STORE* us_get_default_ca_store() {
X509_STORE *store = X509_STORE_new();
if (store == NULL) {
return NULL;
}
if (!X509_STORE_set_default_paths(store)) {
X509_STORE_free(store);
return NULL;
}
us_internal_init_root_certs();
// load all root_cert_instances on the default ca store
for (size_t i = 0; i < root_certs_size; i++) {
X509* cert = root_cert_instances[i];
if(cert == NULL) continue;
X509_up_ref(cert);
X509_STORE_add_cert(store, cert);
}
return store;
}

View File

@@ -35,8 +35,8 @@ void us_loop_run_bun_tick(struct us_loop_t *loop, int64_t timeoutMs, void*);
/* Pointer tags are used to indicate a Bun pointer versus a uSockets pointer */
#define UNSET_BITS_49_UNTIL_64 0x0000FFFFFFFFFFFF
#define CLEAR_POINTER_TAG(p) ((void *) ((uintptr_t) (p) & UNSET_BITS_49_UNTIL_64))
#define LIKELY(cond) __builtin_expect((uint64_t)(void*)(cond), 1)
#define UNLIKELY(cond) __builtin_expect((uint64_t)(void*)(cond), 0)
#define LIKELY(cond) __builtin_expect((_Bool)(cond), 1)
#define UNLIKELY(cond) __builtin_expect((_Bool)(cond), 0)
#ifdef LIBUS_USE_EPOLL
#define GET_READY_POLL(loop, index) (struct us_poll_t *) loop->ready_polls[index].data.ptr

View File

@@ -0,0 +1,330 @@
/*
* Authored by Alex Hultman, 2018-2021.
* Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "internal/internal.h"
#include "libusockets.h"
#include <stdlib.h>
#ifdef LIBUS_USE_LIBUV
/* uv_poll_t->data always (except for most times after calling us_poll_stop)
* points to the us_poll_t */
static void poll_cb(uv_poll_t *p, int status, int events) {
us_internal_dispatch_ready_poll((struct us_poll_t *)p->data, status < 0,
events);
}
static void prepare_cb(uv_prepare_t *p) {
struct us_loop_t *loop = p->data;
us_internal_loop_pre(loop);
}
/* Note: libuv timers execute AFTER the post callback */
static void check_cb(uv_check_t *p) {
struct us_loop_t *loop = p->data;
us_internal_loop_post(loop);
}
/* Not used for polls, since polls need two frees */
static void close_cb_free(uv_handle_t *h) { free(h->data); }
/* This one is different for polls, since we need two frees here */
static void close_cb_free_poll(uv_handle_t *h) {
/* It is only in case we called us_poll_stop then quickly us_poll_free that we
* enter this. Most of the time, actual freeing is done by us_poll_free. */
if (h->data) {
free(h->data);
free(h);
}
}
static void timer_cb(uv_timer_t *t) {
struct us_internal_callback_t *cb = t->data;
cb->cb(cb);
}
static void async_cb(uv_async_t *a) {
struct us_internal_callback_t *cb = a->data;
// internal asyncs give their loop, not themselves
cb->cb((struct us_internal_callback_t *)cb->loop);
}
// poll
void us_poll_init(struct us_poll_t *p, LIBUS_SOCKET_DESCRIPTOR fd,
int poll_type) {
p->poll_type = poll_type;
p->fd = fd;
}
void us_poll_free(struct us_poll_t *p, struct us_loop_t *loop) {
/* The idea here is like so; in us_poll_stop we call uv_close after setting
* data of uv-poll to 0. This means that in close_cb_free we call free on 0
* with does nothing, since us_poll_stop should not really free the poll.
* HOWEVER, if we then call us_poll_free while still closing the uv-poll, we
* simply change back the data to point to our structure so that we actually
* do free it like we should. */
if (uv_is_closing((uv_handle_t *)p->uv_p)) {
p->uv_p->data = p;
} else {
free(p->uv_p);
free(p);
}
}
void us_poll_start(struct us_poll_t *p, struct us_loop_t *loop, int events) {
p->poll_type = us_internal_poll_type(p) |
((events & LIBUS_SOCKET_READABLE) ? POLL_TYPE_POLLING_IN : 0) |
((events & LIBUS_SOCKET_WRITABLE) ? POLL_TYPE_POLLING_OUT : 0);
uv_poll_init_socket(loop->uv_loop, p->uv_p, p->fd);
uv_poll_start(p->uv_p, events, poll_cb);
}
void us_poll_change(struct us_poll_t *p, struct us_loop_t *loop, int events) {
if (us_poll_events(p) != events) {
p->poll_type =
us_internal_poll_type(p) |
((events & LIBUS_SOCKET_READABLE) ? POLL_TYPE_POLLING_IN : 0) |
((events & LIBUS_SOCKET_WRITABLE) ? POLL_TYPE_POLLING_OUT : 0);
uv_poll_start(p->uv_p, events, poll_cb);
}
}
void us_poll_stop(struct us_poll_t *p, struct us_loop_t *loop) {
uv_poll_stop(p->uv_p);
/* We normally only want to close the poll here, not free it. But if we stop
* it, then quickly "free" it with us_poll_free, we postpone the actual
* freeing to close_cb_free_poll whenever it triggers. That's why we set data
* to null here, so that us_poll_free can reset it if needed */
p->uv_p->data = 0;
uv_close((uv_handle_t *)p->uv_p, close_cb_free_poll);
}
int us_poll_events(struct us_poll_t *p) {
return ((p->poll_type & POLL_TYPE_POLLING_IN) ? LIBUS_SOCKET_READABLE : 0) |
((p->poll_type & POLL_TYPE_POLLING_OUT) ? LIBUS_SOCKET_WRITABLE : 0);
}
unsigned int us_internal_accept_poll_event(struct us_poll_t *p) { return 0; }
int us_internal_poll_type(struct us_poll_t *p) { return p->poll_type & 3; }
void us_internal_poll_set_type(struct us_poll_t *p, int poll_type) {
p->poll_type = poll_type | (p->poll_type & 12);
}
LIBUS_SOCKET_DESCRIPTOR us_poll_fd(struct us_poll_t *p) { return p->fd; }
void us_loop_pump(struct us_loop_t *loop) {
uv_run(loop->uv_loop, UV_RUN_NOWAIT);
}
struct us_loop_t *us_create_loop(void *hint,
void (*wakeup_cb)(struct us_loop_t *loop),
void (*pre_cb)(struct us_loop_t *loop),
void (*post_cb)(struct us_loop_t *loop),
unsigned int ext_size) {
struct us_loop_t *loop =
(struct us_loop_t *)malloc(sizeof(struct us_loop_t) + ext_size);
loop->uv_loop = hint ? hint : uv_loop_new();
loop->is_default = hint != 0;
loop->uv_pre = malloc(sizeof(uv_prepare_t));
uv_prepare_init(loop->uv_loop, loop->uv_pre);
uv_prepare_start(loop->uv_pre, prepare_cb);
uv_unref((uv_handle_t *)loop->uv_pre);
loop->uv_pre->data = loop;
loop->uv_check = malloc(sizeof(uv_check_t));
uv_check_init(loop->uv_loop, loop->uv_check);
uv_unref((uv_handle_t *)loop->uv_check);
uv_check_start(loop->uv_check, check_cb);
loop->uv_check->data = loop;
// here we create two unreffed handles - timer and async
us_internal_loop_data_init(loop, wakeup_cb, pre_cb, post_cb);
// if we do not own this loop, we need to integrate and set up timer
if (hint) {
us_loop_integrate(loop);
}
return loop;
}
// based on if this was default loop or not
void us_loop_free(struct us_loop_t *loop) {
// ref and close down prepare and check
uv_ref((uv_handle_t *)loop->uv_pre);
uv_prepare_stop(loop->uv_pre);
loop->uv_pre->data = loop->uv_pre;
uv_close((uv_handle_t *)loop->uv_pre, close_cb_free);
uv_ref((uv_handle_t *)loop->uv_check);
uv_check_stop(loop->uv_check);
loop->uv_check->data = loop->uv_check;
uv_close((uv_handle_t *)loop->uv_check, close_cb_free);
us_internal_loop_data_free(loop);
// we need to run the loop one last round to call all close callbacks
// we cannot do this if we do not own the loop, default
if (!loop->is_default) {
uv_run(loop->uv_loop, UV_RUN_NOWAIT);
uv_loop_delete(loop->uv_loop);
}
// now we can free our part
free(loop);
}
void us_loop_run(struct us_loop_t *loop) {
us_loop_integrate(loop);
uv_run(loop->uv_loop, UV_RUN_NOWAIT);
}
struct us_poll_t *us_create_poll(struct us_loop_t *loop, int fallthrough,
unsigned int ext_size) {
struct us_poll_t *p =
(struct us_poll_t *)malloc(sizeof(struct us_poll_t) + ext_size);
p->uv_p = malloc(sizeof(uv_poll_t));
p->uv_p->data = p;
return p;
}
/* If we update our block position we have to updarte the uv_poll data to point
* to us */
struct us_poll_t *us_poll_resize(struct us_poll_t *p, struct us_loop_t *loop,
unsigned int ext_size) {
struct us_poll_t *new_p = realloc(p, sizeof(struct us_poll_t) + ext_size);
new_p->uv_p->data = new_p;
return new_p;
}
// timer
struct us_timer_t *us_create_timer(struct us_loop_t *loop, int fallthrough,
unsigned int ext_size) {
struct us_internal_callback_t *cb = malloc(
sizeof(struct us_internal_callback_t) + sizeof(uv_timer_t) + ext_size);
cb->loop = loop;
cb->cb_expects_the_loop = 0; // never read?
cb->leave_poll_ready = 0; // never read?
uv_timer_t *uv_timer = (uv_timer_t *)(cb + 1);
uv_timer_init(loop->uv_loop, uv_timer);
uv_timer->data = cb;
if (fallthrough) {
uv_unref((uv_handle_t *)uv_timer);
}
return (struct us_timer_t *)cb;
}
void *us_timer_ext(struct us_timer_t *timer) {
return ((char *)timer) + sizeof(struct us_internal_callback_t) +
sizeof(uv_timer_t);
}
void us_timer_close(struct us_timer_t *t) {
struct us_internal_callback_t *cb = (struct us_internal_callback_t *)t;
uv_timer_t *uv_timer = (uv_timer_t *)(cb + 1);
// always ref the timer before closing it
uv_ref((uv_handle_t *)uv_timer);
uv_timer_stop(uv_timer);
uv_timer->data = cb;
uv_close((uv_handle_t *)uv_timer, close_cb_free);
}
void us_timer_set(struct us_timer_t *t, void (*cb)(struct us_timer_t *t),
int ms, int repeat_ms) {
struct us_internal_callback_t *internal_cb =
(struct us_internal_callback_t *)t;
internal_cb->cb = (void (*)(struct us_internal_callback_t *))cb;
uv_timer_t *uv_timer = (uv_timer_t *)(internal_cb + 1);
if (!ms) {
uv_timer_stop(uv_timer);
} else {
uv_timer_start(uv_timer, timer_cb, ms, repeat_ms);
}
}
struct us_loop_t *us_timer_loop(struct us_timer_t *t) {
struct us_internal_callback_t *internal_cb =
(struct us_internal_callback_t *)t;
return internal_cb->loop;
}
// async (internal only)
struct us_internal_async *us_internal_create_async(struct us_loop_t *loop,
int fallthrough,
unsigned int ext_size) {
struct us_internal_callback_t *cb = malloc(
sizeof(struct us_internal_callback_t) + sizeof(uv_async_t) + ext_size);
cb->loop = loop;
return (struct us_internal_async *)cb;
}
void us_internal_async_close(struct us_internal_async *a) {
struct us_internal_callback_t *cb = (struct us_internal_callback_t *)a;
uv_async_t *uv_async = (uv_async_t *)(cb + 1);
// always ref the async before closing it
uv_ref((uv_handle_t *)uv_async);
uv_async->data = cb;
uv_close((uv_handle_t *)uv_async, close_cb_free);
}
void us_internal_async_set(struct us_internal_async *a,
void (*cb)(struct us_internal_async *)) {
struct us_internal_callback_t *internal_cb =
(struct us_internal_callback_t *)a;
internal_cb->cb = (void (*)(struct us_internal_callback_t *))cb;
uv_async_t *uv_async = (uv_async_t *)(internal_cb + 1);
uv_async_init(internal_cb->loop->uv_loop, uv_async, async_cb);
uv_unref((uv_handle_t *)uv_async);
uv_async->data = internal_cb;
}
void us_internal_async_wakeup(struct us_internal_async *a) {
struct us_internal_callback_t *internal_cb =
(struct us_internal_callback_t *)a;
uv_async_t *uv_async = (uv_async_t *)(internal_cb + 1);
uv_async_send(uv_async);
}
#endif

View File

@@ -0,0 +1,47 @@
/*
* Authored by Alex Hultman, 2018-2019.
* Intellectual property of third-party.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef LIBUV_H
#define LIBUV_H
#include "internal/loop_data.h"
#include <uv.h>
#define LIBUS_SOCKET_READABLE UV_READABLE
#define LIBUS_SOCKET_WRITABLE UV_WRITABLE
struct us_loop_t {
alignas(LIBUS_EXT_ALIGNMENT) struct us_internal_loop_data_t data;
uv_loop_t *uv_loop;
int is_default;
uv_prepare_t *uv_pre;
uv_check_t *uv_check;
};
// it is no longer valid to cast a pointer to us_poll_t to a pointer of
// uv_poll_t
struct us_poll_t {
/* We need to hold a pointer to this uv_poll_t since we need to be able to
* resize our block */
uv_poll_t *uv_p;
LIBUS_SOCKET_DESCRIPTOR fd;
unsigned char poll_type;
};
#endif // LIBUV_H

View File

@@ -20,7 +20,9 @@
#if defined(_MSC_VER)
#ifndef __cplusplus
#define alignas(x) __declspec(align(x))
#endif
#else
#include <stdalign.h>
#endif
@@ -43,6 +45,10 @@ void us_internal_loop_update_pending_ready_polls(struct us_loop_t *loop, struct
#include "internal/eventing/epoll_kqueue.h"
#endif
#ifdef LIBUS_USE_LIBUV
#include "internal/eventing/libuv.h"
#endif
/* Poll type and what it polls for */
enum {
/* Two first bits */
@@ -126,6 +132,15 @@ struct us_internal_callback_t {
#endif
#if __cplusplus
extern "C" {
#endif
int us_internal_raw_root_certs(struct us_cert_string_t** out);
#if __cplusplus
}
#endif
/* Listen sockets are sockets */
struct us_listen_socket_t {
alignas(LIBUS_EXT_ALIGNMENT) struct us_socket_t s;
@@ -163,6 +178,7 @@ struct us_socket_context_t {
struct us_internal_ssl_socket_context_t;
struct us_internal_ssl_socket_t;
typedef void (*us_internal_on_handshake_t)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data);
/* SNI functions */
void us_internal_ssl_socket_context_add_server_name(struct us_internal_ssl_socket_context_t *context, const char *hostname_pattern, struct us_socket_context_options_t options, void *user);
@@ -190,8 +206,8 @@ void us_internal_ssl_socket_context_on_close(struct us_internal_ssl_socket_conte
void us_internal_ssl_socket_context_on_data(struct us_internal_ssl_socket_context_t *context,
struct us_internal_ssl_socket_t *(*on_data)(struct us_internal_ssl_socket_t *s, char *data, int length));
void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, void (*on_handshake)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data);
void us_internal_on_ssl_handshake(struct us_internal_ssl_socket_context_t * context, void (*on_handshake)(struct us_internal_ssl_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data);
void us_internal_ssl_handshake(struct us_internal_ssl_socket_t *s, us_internal_on_handshake_t on_handshake, void* custom_data);
void us_internal_on_ssl_handshake(struct us_internal_ssl_socket_context_t * context, us_internal_on_handshake_t on_handshake, void* custom_data);
void us_internal_ssl_socket_context_on_writable(struct us_internal_ssl_socket_context_t *context,
struct us_internal_ssl_socket_t *(*on_writable)(struct us_internal_ssl_socket_t *s));

View File

@@ -153,6 +153,12 @@ struct us_socket_context_options_t {
int ssl_prefer_low_memory_usage; /* Todo: rename to prefer_low_memory_usage and apply for TCP as well */
};
struct us_bun_verify_error_t {
long error;
const char* code;
const char* reason;
};
struct us_socket_events_t {
struct us_socket_t *(*on_open)(struct us_socket_t *, int is_client, char *ip, int ip_length);
struct us_socket_t *(*on_data)(struct us_socket_t *, char *data, int length);
@@ -166,11 +172,6 @@ struct us_socket_events_t {
void (*on_handshake)(struct us_socket_t*, int success, struct us_bun_verify_error_t verify_error, void* custom_data);
};
struct us_bun_verify_error_t {
long error;
const char* code;
const char* reason;
};
struct us_bun_socket_context_options_t {
const char *key_file_name;
@@ -231,7 +232,7 @@ void us_socket_context_on_long_timeout(int ssl, struct us_socket_context_t *cont
void us_socket_context_on_connect_error(int ssl, struct us_socket_context_t *context,
struct us_socket_t *(*on_connect_error)(struct us_socket_t *s, int code));
void us_socket_context_on_handshake(int ssl, struct us_socket_context_t *context, void (*on_handshake)(struct us_socket_context_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data);
void us_socket_context_on_handshake(int ssl, struct us_socket_context_t *context, void (*on_handshake)(struct us_socket_t *, int success, struct us_bun_verify_error_t verify_error, void* custom_data), void* custom_data);
/* Emitted when a socket has been half-closed */
void us_socket_context_on_end(int ssl, struct us_socket_context_t *context, struct us_socket_t *(*on_end)(struct us_socket_t *s));

View File

@@ -18,7 +18,9 @@
#include "libusockets.h"
#include "internal/internal.h"
#include <stdlib.h>
#ifndef WIN32
#include <sys/ioctl.h>
#endif
/* The loop has 2 fallthrough polls */
void us_internal_loop_data_init(struct us_loop_t *loop, void (*wakeup_cb)(struct us_loop_t *loop),

View File

@@ -150,22 +150,76 @@ struct us_socket_t *us_socket_close(int ssl, struct us_socket_t *s, int code, vo
return s;
}
// This function is the same as us_socket_close but:
// - does not emit on_close event
// - does not close
struct us_socket_t *us_socket_detach(int ssl, struct us_socket_t *s) {
if (!us_socket_is_closed(0, s)) {
if (s->low_prio_state == 1) {
/* Unlink this socket from the low-priority queue */
if (!s->prev) s->context->loop->data.low_prio_head = s->next;
else s->prev->next = s->next;
if (s->next) s->next->prev = s->prev;
s->prev = 0;
s->next = 0;
s->low_prio_state = 0;
} else {
us_internal_socket_context_unlink_socket(s->context, s);
}
us_poll_stop((struct us_poll_t *) s, s->context->loop);
/* Link this socket to the close-list and let it be deleted after this iteration */
s->next = s->context->loop->data.closed_head;
s->context->loop->data.closed_head = s;
/* Any socket with prev = context is marked as closed */
s->prev = (struct us_socket_t *) s->context;
return s;
}
return s;
}
// This function is used for moving a socket between two different event loops
struct us_socket_t *us_socket_attach(int ssl, LIBUS_SOCKET_DESCRIPTOR client_fd, struct us_socket_context_t *ctx, int flags, int socket_ext_size) {
struct us_poll_t *accepted_p = us_create_poll(ctx->loop, 0, sizeof(struct us_socket_t) - sizeof(struct us_poll_t) + socket_ext_size);
us_poll_init(accepted_p, client_fd, POLL_TYPE_SOCKET);
us_poll_start(accepted_p, ctx->loop, flags);
struct us_socket_t *s = (struct us_socket_t *) accepted_p;
s->context = ctx;
s->timeout = 0;
s->low_prio_state = 0;
/* We always use nodelay */
bsd_socket_nodelay(client_fd, 1);
us_internal_socket_context_link_socket(ctx, s);
if (ctx->on_open) ctx->on_open(s, 0, 0, 0);
return s;
}
struct us_socket_t *us_socket_pair(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR* fds) {
#ifdef LIBUS_USE_LIBUV
#if defined(LIBUS_USE_LIBUV) || defined(WIN32)
return 0;
#endif
#else
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fds) != 0) {
return 0;
}
return us_socket_from_fd(ctx, socket_ext_size, fds[0]);
#endif
}
struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socket_ext_size, LIBUS_SOCKET_DESCRIPTOR fd) {
#ifdef LIBUS_USE_LIBUV
#if defined(LIBUS_USE_LIBUV) || defined(WIN32)
return 0;
#endif
#else
struct us_poll_t *p1 = us_create_poll(ctx->loop, 0, sizeof(struct us_socket_t) + socket_ext_size);
us_poll_init(p1, fd, POLL_TYPE_SOCKET);
us_poll_start(p1, ctx->loop, LIBUS_SOCKET_READABLE | LIBUS_SOCKET_WRITABLE);
@@ -186,6 +240,7 @@ struct us_socket_t *us_socket_from_fd(struct us_socket_context_t *ctx, int socke
}
return s;
#endif
}

View File

@@ -213,9 +213,9 @@ public:
unsigned char *b = (unsigned char *) binary.data();
if (binary.length() == 4) {
ipLength = sprintf(buf, "%u.%u.%u.%u", b[0], b[1], b[2], b[3]);
ipLength = snprintf(buf, sizeof(buf), "%u.%u.%u.%u", b[0], b[1], b[2], b[3]);
} else {
ipLength = sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
ipLength = snprintf(buf, sizeof(buf), "%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11],
b[12], b[13], b[14], b[15]);
}

296
source_list.txt Normal file
View File

@@ -0,0 +1,296 @@
./src/deps/libuwsockets.cpp
./src/io/io_darwin.cpp
./src/bun.js/modules/BunObjectModule.cpp
./src/bun.js/modules/ObjectModule.cpp
./src/bun.js/bindings/ActiveDOMCallback.cpp
./src/bun.js/bindings/AsyncContextFrame.cpp
./src/bun.js/bindings/BunClientData.cpp
./src/bun.js/bindings/BunDebugger.cpp
./src/bun.js/bindings/BunGCOutputConstraint.cpp
./src/bun.js/bindings/BunInjectedScriptHost.cpp
./src/bun.js/bindings/BunInspector.cpp
./src/bun.js/bindings/BunObject.cpp
./src/bun.js/bindings/BunPlugin.cpp
./src/bun.js/bindings/BunProcess.cpp
./src/bun.js/bindings/BunString.cpp
./src/bun.js/bindings/BunWorkerGlobalScope.cpp
./src/bun.js/bindings/CallSite.cpp
./src/bun.js/bindings/CallSitePrototype.cpp
./src/bun.js/bindings/CodeCoverage.cpp
./src/bun.js/bindings/CommonJSModuleRecord.cpp
./src/bun.js/bindings/DOMException.cpp
./src/bun.js/bindings/DOMFormData.cpp
./src/bun.js/bindings/DOMURL.cpp
./src/bun.js/bindings/DOMWrapperWorld.cpp
./src/bun.js/bindings/ErrorStackTrace.cpp
./src/bun.js/bindings/ImportMetaObject.cpp
./src/bun.js/bindings/InternalModuleRegistry.cpp
./src/bun.js/bindings/JSBuffer.cpp
./src/bun.js/bindings/JSBufferEncodingType.cpp
./src/bun.js/bindings/JSBufferList.cpp
./src/bun.js/bindings/JSBundlerPlugin.cpp
./src/bun.js/bindings/JSCTaskScheduler.cpp
./src/bun.js/bindings/JSCUSocketsLoopIntegration.cpp
./src/bun.js/bindings/JSDOMExceptionHandling.cpp
./src/bun.js/bindings/JSDOMFile.cpp
./src/bun.js/bindings/JSDOMGlobalObject.cpp
./src/bun.js/bindings/JSDOMWrapper.cpp
./src/bun.js/bindings/JSDOMWrapperCache.cpp
./src/bun.js/bindings/JSEnvironmentVariableMap.cpp
./src/bun.js/bindings/JSFFIFunction.cpp
./src/bun.js/bindings/JSMockFunction.cpp
./src/bun.js/bindings/JSNextTickQueue.cpp
./src/bun.js/bindings/JSReadableHelper.cpp
./src/bun.js/bindings/JSReadableState.cpp
./src/bun.js/bindings/JSSocketAddress.cpp
./src/bun.js/bindings/JSStringDecoder.cpp
./src/bun.js/bindings/KeyObject.cpp
./src/bun.js/bindings/MarkingConstraint.cpp
./src/bun.js/bindings/ModuleLoader.cpp
./src/bun.js/bindings/NodeVMScript.cpp
./src/bun.js/bindings/Path.cpp
./src/bun.js/bindings/ProcessBindingConstants.cpp
./src/bun.js/bindings/ProcessBindingNatives.cpp
./src/bun.js/bindings/ProcessBindingUV.cpp
./src/bun.js/bindings/ProcessIdentifier.cpp
./src/bun.js/bindings/RegularExpression.cpp
./src/bun.js/bindings/ScriptExecutionContext.cpp
./src/bun.js/bindings/Serialization.cpp
./src/bun.js/bindings/Strong.cpp
./src/bun.js/bindings/URLDecomposition.cpp
./src/bun.js/bindings/URLSearchParams.cpp
./src/bun.js/bindings/ZigConsoleClient.cpp
./src/bun.js/bindings/ZigGeneratedCode.cpp
./src/bun.js/bindings/ZigGlobalObject.cpp
./src/bun.js/bindings/ZigSourceProvider.cpp
./src/bun.js/bindings/bindings.cpp
./src/bun.js/bindings/blob.cpp
./src/bun.js/bindings/bun-simdutf.cpp
./src/bun.js/bindings/c-bindings.cpp
./src/bun.js/bindings/coroutine.cpp
./src/bun.js/bindings/helpers.cpp
./src/bun.js/bindings/inlines.cpp
./src/bun.js/bindings/isBuiltinModule.cpp
./src/bun.js/bindings/napi.cpp
./src/bun.js/bindings/napi_external.cpp
./src/bun.js/bindings/objects.cpp
./src/bun.js/bindings/simdutf.cpp
./src/bun.js/bindings/spawn.cpp
./src/bun.js/bindings/workaround-missing-symbols.cpp
./src/bun.js/bindings/wtf-bindings.cpp
./src/bun.js/bindings/webcore/AbortController.cpp
./src/bun.js/bindings/webcore/AbortSignal.cpp
./src/bun.js/bindings/webcore/ActiveDOMObject.cpp
./src/bun.js/bindings/webcore/BroadcastChannel.cpp
./src/bun.js/bindings/webcore/BunBroadcastChannelRegistry.cpp
./src/bun.js/bindings/webcore/CloseEvent.cpp
./src/bun.js/bindings/webcore/CommonAtomStrings.cpp
./src/bun.js/bindings/webcore/ContextDestructionObserver.cpp
./src/bun.js/bindings/webcore/CustomEvent.cpp
./src/bun.js/bindings/webcore/CustomEventCustom.cpp
./src/bun.js/bindings/webcore/DOMJITHelpers.cpp
./src/bun.js/bindings/webcore/ErrorCallback.cpp
./src/bun.js/bindings/webcore/ErrorEvent.cpp
./src/bun.js/bindings/webcore/Event.cpp
./src/bun.js/bindings/webcore/EventContext.cpp
./src/bun.js/bindings/webcore/EventDispatcher.cpp
./src/bun.js/bindings/webcore/EventEmitter.cpp
./src/bun.js/bindings/webcore/EventFactory.cpp
./src/bun.js/bindings/webcore/EventListenerMap.cpp
./src/bun.js/bindings/webcore/EventNames.cpp
./src/bun.js/bindings/webcore/EventPath.cpp
./src/bun.js/bindings/webcore/EventTarget.cpp
./src/bun.js/bindings/webcore/EventTargetConcrete.cpp
./src/bun.js/bindings/webcore/EventTargetFactory.cpp
./src/bun.js/bindings/webcore/FetchHeaders.cpp
./src/bun.js/bindings/webcore/HTTPHeaderField.cpp
./src/bun.js/bindings/webcore/HTTPHeaderMap.cpp
./src/bun.js/bindings/webcore/HTTPHeaderNames.cpp
./src/bun.js/bindings/webcore/HTTPHeaderValues.cpp
./src/bun.js/bindings/webcore/HTTPParsers.cpp
./src/bun.js/bindings/webcore/IdentifierEventListenerMap.cpp
./src/bun.js/bindings/webcore/InternalWritableStream.cpp
./src/bun.js/bindings/webcore/JSAbortAlgorithm.cpp
./src/bun.js/bindings/webcore/JSAbortController.cpp
./src/bun.js/bindings/webcore/JSAbortSignal.cpp
./src/bun.js/bindings/webcore/JSAbortSignalCustom.cpp
./src/bun.js/bindings/webcore/JSAddEventListenerOptions.cpp
./src/bun.js/bindings/webcore/JSBroadcastChannel.cpp
./src/bun.js/bindings/webcore/JSByteLengthQueuingStrategy.cpp
./src/bun.js/bindings/webcore/JSCallbackData.cpp
./src/bun.js/bindings/webcore/JSCloseEvent.cpp
./src/bun.js/bindings/webcore/JSCountQueuingStrategy.cpp
./src/bun.js/bindings/webcore/JSCustomEvent.cpp
./src/bun.js/bindings/webcore/JSDOMBindingInternalsBuiltins.cpp
./src/bun.js/bindings/webcore/JSDOMBuiltinConstructorBase.cpp
./src/bun.js/bindings/webcore/JSDOMConstructorBase.cpp
./src/bun.js/bindings/webcore/JSDOMConvertDate.cpp
./src/bun.js/bindings/webcore/JSDOMConvertNumbers.cpp
./src/bun.js/bindings/webcore/JSDOMConvertStrings.cpp
./src/bun.js/bindings/webcore/JSDOMConvertWebGL.cpp
./src/bun.js/bindings/webcore/JSDOMException.cpp
./src/bun.js/bindings/webcore/JSDOMFormData.cpp
./src/bun.js/bindings/webcore/JSDOMGuardedObject.cpp
./src/bun.js/bindings/webcore/JSDOMIterator.cpp
./src/bun.js/bindings/webcore/JSDOMPromise.cpp
./src/bun.js/bindings/webcore/JSDOMPromiseDeferred.cpp
./src/bun.js/bindings/webcore/JSDOMURL.cpp
./src/bun.js/bindings/webcore/JSErrorCallback.cpp
./src/bun.js/bindings/webcore/JSErrorEvent.cpp
./src/bun.js/bindings/webcore/JSErrorEventCustom.cpp
./src/bun.js/bindings/webcore/JSErrorHandler.cpp
./src/bun.js/bindings/webcore/JSEvent.cpp
./src/bun.js/bindings/webcore/JSEventCustom.cpp
./src/bun.js/bindings/webcore/JSEventDOMJIT.cpp
./src/bun.js/bindings/webcore/JSEventEmitter.cpp
./src/bun.js/bindings/webcore/JSEventEmitterCustom.cpp
./src/bun.js/bindings/webcore/JSEventInit.cpp
./src/bun.js/bindings/webcore/JSEventListener.cpp
./src/bun.js/bindings/webcore/JSEventListenerOptions.cpp
./src/bun.js/bindings/webcore/JSEventModifierInit.cpp
./src/bun.js/bindings/webcore/JSEventTarget.cpp
./src/bun.js/bindings/webcore/JSEventTargetCustom.cpp
./src/bun.js/bindings/webcore/JSFetchHeaders.cpp
./src/bun.js/bindings/webcore/JSMessageChannel.cpp
./src/bun.js/bindings/webcore/JSMessageChannelCustom.cpp
./src/bun.js/bindings/webcore/JSMessageEvent.cpp
./src/bun.js/bindings/webcore/JSMessageEventCustom.cpp
./src/bun.js/bindings/webcore/JSMessagePort.cpp
./src/bun.js/bindings/webcore/JSMessagePortCustom.cpp
./src/bun.js/bindings/webcore/JSReadableByteStreamController.cpp
./src/bun.js/bindings/webcore/JSReadableStream.cpp
./src/bun.js/bindings/webcore/JSReadableStreamBYOBReader.cpp
./src/bun.js/bindings/webcore/JSReadableStreamBYOBRequest.cpp
./src/bun.js/bindings/webcore/JSReadableStreamDefaultController.cpp
./src/bun.js/bindings/webcore/JSReadableStreamDefaultReader.cpp
./src/bun.js/bindings/webcore/JSReadableStreamSink.cpp
./src/bun.js/bindings/webcore/JSReadableStreamSource.cpp
./src/bun.js/bindings/webcore/JSReadableStreamSourceCustom.cpp
./src/bun.js/bindings/webcore/JSStructuredSerializeOptions.cpp
./src/bun.js/bindings/webcore/JSTextEncoder.cpp
./src/bun.js/bindings/webcore/JSTransformStream.cpp
./src/bun.js/bindings/webcore/JSTransformStreamDefaultController.cpp
./src/bun.js/bindings/webcore/JSURLSearchParams.cpp
./src/bun.js/bindings/webcore/JSWebSocket.cpp
./src/bun.js/bindings/webcore/JSWorker.cpp
./src/bun.js/bindings/webcore/JSWorkerOptions.cpp
./src/bun.js/bindings/webcore/JSWritableStream.cpp
./src/bun.js/bindings/webcore/JSWritableStreamDefaultController.cpp
./src/bun.js/bindings/webcore/JSWritableStreamDefaultWriter.cpp
./src/bun.js/bindings/webcore/JSWritableStreamSink.cpp
./src/bun.js/bindings/webcore/MessageChannel.cpp
./src/bun.js/bindings/webcore/MessageEvent.cpp
./src/bun.js/bindings/webcore/MessagePort.cpp
./src/bun.js/bindings/webcore/MessagePortChannel.cpp
./src/bun.js/bindings/webcore/MessagePortChannelProvider.cpp
./src/bun.js/bindings/webcore/MessagePortChannelProviderImpl.cpp
./src/bun.js/bindings/webcore/MessagePortChannelRegistry.cpp
./src/bun.js/bindings/webcore/ParsedContentType.cpp
./src/bun.js/bindings/webcore/ReadableStream.cpp
./src/bun.js/bindings/webcore/ReadableStreamDefaultController.cpp
./src/bun.js/bindings/webcore/ReadableStreamSink.cpp
./src/bun.js/bindings/webcore/ReadableStreamSource.cpp
./src/bun.js/bindings/webcore/ScriptWrappable.cpp
./src/bun.js/bindings/webcore/SerializedScriptValue.cpp
./src/bun.js/bindings/webcore/SharedBuffer.cpp
./src/bun.js/bindings/webcore/StructuredClone.cpp
./src/bun.js/bindings/webcore/TextEncoder.cpp
./src/bun.js/bindings/webcore/WebCoreTypedArrayController.cpp
./src/bun.js/bindings/webcore/WebSocket.cpp
./src/bun.js/bindings/webcore/Worker.cpp
./src/bun.js/bindings/webcore/WritableStream.cpp
./src/bun.js/bindings/webcore/weak_handle.cpp
./src/bun.js/bindings/sqlite/JSSQLStatement.cpp
./src/bun.js/bindings/webcrypto/CommonCryptoDERUtilities.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithm.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CBC.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CBCOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CFB.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CFBOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CTR.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_CTROpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_GCM.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_GCMOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_KW.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmAES_KWOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmECDH.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmECDHOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmECDSA.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmECDSAOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmEd25519.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmHKDF.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmHKDFOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmHMAC.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmHMACOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmPBKDF2.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmPBKDF2OpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSAES_PKCS1_v1_5.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSAES_PKCS1_v1_5OpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSASSA_PKCS1_v1_5.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSASSA_PKCS1_v1_5OpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSA_OAEP.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSA_OAEPOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSA_PSS.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRSA_PSSOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRegistry.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmRegistryOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA1.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA224.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA256.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA384.cpp
./src/bun.js/bindings/webcrypto/CryptoAlgorithmSHA512.cpp
./src/bun.js/bindings/webcrypto/CryptoDigest.cpp
./src/bun.js/bindings/webcrypto/CryptoKey.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyAES.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyEC.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyECOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyHMAC.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyOKP.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyOKPOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyRSA.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyRSAComponents.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyRSAOpenSSL.cpp
./src/bun.js/bindings/webcrypto/CryptoKeyRaw.cpp
./src/bun.js/bindings/webcrypto/JSAesCbcCfbParams.cpp
./src/bun.js/bindings/webcrypto/JSAesCtrParams.cpp
./src/bun.js/bindings/webcrypto/JSAesGcmParams.cpp
./src/bun.js/bindings/webcrypto/JSAesKeyParams.cpp
./src/bun.js/bindings/webcrypto/JSCryptoAesKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSCryptoAlgorithmParameters.cpp
./src/bun.js/bindings/webcrypto/JSCryptoEcKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSCryptoHmacKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSCryptoKey.cpp
./src/bun.js/bindings/webcrypto/JSCryptoKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSCryptoKeyPair.cpp
./src/bun.js/bindings/webcrypto/JSCryptoKeyUsage.cpp
./src/bun.js/bindings/webcrypto/JSCryptoRsaHashedKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSCryptoRsaKeyAlgorithm.cpp
./src/bun.js/bindings/webcrypto/JSEcKeyParams.cpp
./src/bun.js/bindings/webcrypto/JSEcdhKeyDeriveParams.cpp
./src/bun.js/bindings/webcrypto/JSEcdsaParams.cpp
./src/bun.js/bindings/webcrypto/JSHkdfParams.cpp
./src/bun.js/bindings/webcrypto/JSHmacKeyParams.cpp
./src/bun.js/bindings/webcrypto/JSJsonWebKey.cpp
./src/bun.js/bindings/webcrypto/JSPbkdf2Params.cpp
./src/bun.js/bindings/webcrypto/JSRsaHashedImportParams.cpp
./src/bun.js/bindings/webcrypto/JSRsaHashedKeyGenParams.cpp
./src/bun.js/bindings/webcrypto/JSRsaKeyGenParams.cpp
./src/bun.js/bindings/webcrypto/JSRsaOaepParams.cpp
./src/bun.js/bindings/webcrypto/JSRsaOtherPrimesInfo.cpp
./src/bun.js/bindings/webcrypto/JSRsaPssParams.cpp
./src/bun.js/bindings/webcrypto/JSSubtleCrypto.cpp
./src/bun.js/bindings/webcrypto/OpenSSLUtilities.cpp
./src/bun.js/bindings/webcrypto/SerializedCryptoKeyWrapOpenSSL.cpp
./src/bun.js/bindings/webcrypto/SubtleCrypto.cpp
./src/deps/picohttpparser/picohttpparser.c
./packages/bun-usockets/src/bsd.c
./packages/bun-usockets/src/context.c
./packages/bun-usockets/src/loop.c
./packages/bun-usockets/src/quic.c
./packages/bun-usockets/src/socket.c
./packages/bun-usockets/src/udp.c
./packages/bun-usockets/src/eventing/epoll_kqueue.c
./packages/bun-usockets/src/eventing/libuv.c
./packages/bun-usockets/src/crypto/openssl.c
./packages/bun-usockets/src/crypto/root_certs.cpp
./packages/bun-usockets/src/crypto/sni_tree.cpp

View File

@@ -7,18 +7,7 @@ const StringTypes = @import("./string_types.zig");
const Mimalloc = @import("root").bun.Mimalloc;
const bun = @import("root").bun;
pub const build_id = std.fmt.parseInt(u64, std.mem.trim(u8, @embedFile("./build-id"), "\n \r\t"), 10) catch unreachable;
pub const version: if (Environment.isWasm)
std.SemanticVersion
else
@import("./install/semver.zig").Version = .{
.major = 1,
.minor = 0,
.patch = build_id,
};
const version_string = std.fmt.comptimePrint("{d}.{d}.{d}", .{ version.major, version.minor, version.patch });
const version_string = Environment.version_string;
pub const package_json_version = if (Environment.isDebug)
version_string ++ "_debug"
@@ -79,7 +68,7 @@ pub fn setThreadName(name: StringTypes.stringZ) void {
/// Flushes stdout and stderr and exits with the given code.
pub fn exit(code: u8) noreturn {
Output.flush();
std.os.exit(code);
std.c._exit(code);
}
pub const AllocatorConfiguration = struct {

View File

@@ -0,0 +1,852 @@
const bun = @import("root").bun;
const Output = bun.Output;
const JSC = bun.JSC;
const uws = bun.uws;
const Environment = bun.Environment;
const std = @import("std");
pub const Loop = uws.Loop;
/// Track if an object whose file descriptor is being watched should keep the event loop alive.
/// This is not reference counted. It only tracks active or inactive.
pub const KeepAlive = struct {
status: Status = .inactive,
const log = Output.scoped(.KeepAlive, false);
const Status = enum { active, inactive, done };
pub inline fn isActive(this: KeepAlive) bool {
return this.status == .active;
}
/// Make calling ref() on this poll into a no-op.
pub fn disable(this: *KeepAlive) void {
this.unref(JSC.VirtualMachine.get());
this.status = .done;
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *KeepAlive, loop: *Loop) void {
if (this.status != .active)
return;
this.status = .inactive;
loop.num_polls -= 1;
loop.active -|= 1;
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *KeepAlive, loop: *Loop) void {
if (this.status != .inactive)
return;
this.status = .active;
loop.num_polls += 1;
loop.active += 1;
}
pub fn init() KeepAlive {
return .{};
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.event_loop_handle.?.unref();
}
/// From another thread, Prevent a poll from keeping the process alive.
pub fn unrefConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.event_loop_handle.?.unrefConcurrently();
}
/// Prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTick(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.pending_unref_counter +|= 1;
}
/// From another thread, prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTickConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
_ = @atomicRmw(@TypeOf(vm.pending_unref_counter), &vm.pending_unref_counter, .Add, 1, .Monotonic);
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
vm.event_loop_handle.?.ref();
}
/// Allow a poll to keep the process alive.
pub fn refConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
vm.event_loop_handle.?.refConcurrently();
}
pub fn refConcurrentlyFromEventLoop(this: *KeepAlive, loop: *JSC.EventLoop) void {
this.refConcurrently(loop.virtual_machine);
}
pub fn unrefConcurrentlyFromEventLoop(this: *KeepAlive, loop: *JSC.EventLoop) void {
this.unrefConcurrently(loop.virtual_machine);
}
};
const KQueueGenerationNumber = if (Environment.isMac and Environment.allow_assert) usize else u0;
pub const FilePoll = struct {
var max_generation_number: KQueueGenerationNumber = 0;
fd: bun.UFileDescriptor = invalid_fd,
flags: Flags.Set = Flags.Set{},
owner: Owner = undefined,
/// We re-use FilePoll objects to avoid allocating new ones.
///
/// That means we might run into situations where the event is stale.
/// on macOS kevent64 has an extra pointer field so we use it for that
/// linux doesn't have a field like that
generation_number: KQueueGenerationNumber = 0,
next_to_free: ?*FilePoll = null,
const FileReader = JSC.WebCore.FileReader;
const FileSink = JSC.WebCore.FileSink;
const FIFO = JSC.WebCore.FIFO;
const Subprocess = JSC.Subprocess;
const BufferedInput = Subprocess.BufferedInput;
const BufferedOutput = Subprocess.BufferedOutput;
const DNSResolver = JSC.DNS.DNSResolver;
const GetAddrInfoRequest = JSC.DNS.GetAddrInfoRequest;
const Deactivated = opaque {
pub var owner: Owner = Owner.init(@as(*Deactivated, @ptrFromInt(@as(usize, 0xDEADBEEF))));
};
pub const Owner = bun.TaggedPointerUnion(.{
FileReader,
FileSink,
Subprocess,
BufferedInput,
FIFO,
Deactivated,
DNSResolver,
GetAddrInfoRequest,
});
fn updateFlags(poll: *FilePoll, updated: Flags.Set) void {
var flags = poll.flags;
flags.remove(.readable);
flags.remove(.writable);
flags.remove(.process);
flags.remove(.machport);
flags.remove(.eof);
flags.remove(.hup);
flags.setUnion(updated);
poll.flags = flags;
}
pub fn onKQueueEvent(poll: *FilePoll, loop: *Loop, kqueue_event: *const std.os.system.kevent64_s) void {
if (KQueueGenerationNumber != u0)
std.debug.assert(poll.generation_number == kqueue_event.ext[0]);
poll.updateFlags(Flags.fromKQueueEvent(kqueue_event.*));
poll.onUpdate(loop, kqueue_event.data);
}
pub fn onEpollEvent(poll: *FilePoll, loop: *Loop, epoll_event: *std.os.linux.epoll_event) void {
poll.updateFlags(Flags.fromEpollEvent(epoll_event.*));
poll.onUpdate(loop, 0);
}
pub fn clearEvent(poll: *FilePoll, flag: Flags) void {
poll.flags.remove(flag);
}
pub fn isReadable(this: *FilePoll) bool {
const readable = this.flags.contains(.readable);
this.flags.remove(.readable);
return readable;
}
pub fn isHUP(this: *FilePoll) bool {
const readable = this.flags.contains(.hup);
this.flags.remove(.hup);
return readable;
}
pub fn isEOF(this: *FilePoll) bool {
const readable = this.flags.contains(.eof);
this.flags.remove(.eof);
return readable;
}
pub fn isWritable(this: *FilePoll) bool {
const readable = this.flags.contains(.writable);
this.flags.remove(.writable);
return readable;
}
pub fn deinit(this: *FilePoll) void {
var vm = JSC.VirtualMachine.get();
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), false);
}
pub fn deinitForceUnregister(this: *FilePoll) void {
var vm = JSC.VirtualMachine.get();
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), true);
}
fn deinitPossiblyDefer(this: *FilePoll, vm: *JSC.VirtualMachine, loop: *Loop, polls: *FilePoll.Store, force_unregister: bool) void {
if (this.isRegistered()) {
_ = this.unregister(loop, force_unregister);
}
this.owner = Deactivated.owner;
const was_ever_registered = this.flags.contains(.was_ever_registered);
this.flags = Flags.Set{};
this.fd = invalid_fd;
polls.put(this, vm, was_ever_registered);
}
pub fn deinitWithVM(this: *FilePoll, vm: *JSC.VirtualMachine) void {
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), false);
}
pub fn isRegistered(this: *const FilePoll) bool {
return this.flags.contains(.poll_writable) or this.flags.contains(.poll_readable) or this.flags.contains(.poll_process) or this.flags.contains(.poll_machport);
}
const kqueue_or_epoll = if (Environment.isMac) "kevent" else "epoll";
pub fn onUpdate(poll: *FilePoll, loop: *Loop, size_or_offset: i64) void {
if (poll.flags.contains(.one_shot) and !poll.flags.contains(.needs_rearm)) {
if (poll.flags.contains(.has_incremented_poll_count)) poll.deactivate(loop);
poll.flags.insert(.needs_rearm);
}
var ptr = poll.owner;
switch (ptr.tag()) {
@field(Owner.Tag, "FIFO") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) FIFO", .{poll.fd});
ptr.as(FIFO).ready(size_or_offset, poll.flags.contains(.hup));
},
@field(Owner.Tag, "Subprocess") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) Subprocess", .{poll.fd});
var loader = ptr.as(JSC.Subprocess);
loader.onExitNotification();
},
@field(Owner.Tag, "FileSink") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) FileSink", .{poll.fd});
var loader = ptr.as(JSC.WebCore.FileSink);
loader.onPoll(size_or_offset, 0);
},
@field(Owner.Tag, "DNSResolver") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) DNSResolver", .{poll.fd});
var loader: *DNSResolver = ptr.as(DNSResolver);
loader.onDNSPoll(poll);
},
@field(Owner.Tag, "GetAddrInfoRequest") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) GetAddrInfoRequest", .{poll.fd});
var loader: *GetAddrInfoRequest = ptr.as(GetAddrInfoRequest);
loader.onMachportChange();
},
else => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) disconnected?", .{poll.fd});
},
}
}
pub const Flags = enum {
// What are we asking the event loop about?
/// Poll for readable events
poll_readable,
/// Poll for writable events
poll_writable,
/// Poll for process-related events
poll_process,
/// Poll for machport events
poll_machport,
// What did the event loop tell us?
readable,
writable,
process,
eof,
hup,
machport,
// What is the type of file descriptor?
fifo,
tty,
one_shot,
needs_rearm,
has_incremented_poll_count,
disable,
nonblocking,
was_ever_registered,
ignore_updates,
pub fn poll(this: Flags) Flags {
return switch (this) {
.readable => .poll_readable,
.writable => .poll_writable,
.process => .poll_process,
.machport => .poll_machport,
else => this,
};
}
pub const Set = std.EnumSet(Flags);
pub const Struct = std.enums.EnumFieldStruct(Flags, bool, false);
pub fn fromKQueueEvent(kqueue_event: std.os.system.kevent64_s) Flags.Set {
var flags = Flags.Set{};
if (kqueue_event.filter == std.os.system.EVFILT_READ) {
flags.insert(Flags.readable);
log("readable", .{});
if (kqueue_event.flags & std.os.system.EV_EOF != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
} else if (kqueue_event.filter == std.os.system.EVFILT_WRITE) {
flags.insert(Flags.writable);
log("writable", .{});
if (kqueue_event.flags & std.os.system.EV_EOF != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
} else if (kqueue_event.filter == std.os.system.EVFILT_PROC) {
log("proc", .{});
flags.insert(Flags.process);
} else if (kqueue_event.filter == std.os.system.EVFILT_MACHPORT) {
log("machport", .{});
flags.insert(Flags.machport);
}
return flags;
}
pub fn fromEpollEvent(epoll: std.os.linux.epoll_event) Flags.Set {
var flags = Flags.Set{};
if (epoll.events & std.os.linux.EPOLL.IN != 0) {
flags.insert(Flags.readable);
log("readable", .{});
}
if (epoll.events & std.os.linux.EPOLL.OUT != 0) {
flags.insert(Flags.writable);
log("writable", .{});
}
if (epoll.events & std.os.linux.EPOLL.ERR != 0) {
flags.insert(Flags.eof);
log("eof", .{});
}
if (epoll.events & std.os.linux.EPOLL.HUP != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
return flags;
}
};
const HiveArray = bun.HiveArray(FilePoll, 128).Fallback;
// We defer freeing FilePoll until the end of the next event loop iteration
// This ensures that we don't free a FilePoll before the next callback is called
pub const Store = struct {
hive: HiveArray,
pending_free_head: ?*FilePoll = null,
pending_free_tail: ?*FilePoll = null,
const log = Output.scoped(.FilePoll, false);
pub fn init(allocator: std.mem.Allocator) Store {
return .{
.hive = HiveArray.init(allocator),
};
}
pub fn get(this: *Store) *FilePoll {
return this.hive.get();
}
pub fn processDeferredFrees(this: *Store) void {
var next = this.pending_free_head;
while (next) |current| {
next = current.next_to_free;
current.next_to_free = null;
this.hive.put(current);
}
this.pending_free_head = null;
this.pending_free_tail = null;
}
pub fn put(this: *Store, poll: *FilePoll, vm: *JSC.VirtualMachine, ever_registered: bool) void {
if (!ever_registered) {
this.hive.put(poll);
return;
}
std.debug.assert(poll.next_to_free == null);
if (this.pending_free_tail) |tail| {
std.debug.assert(this.pending_free_head != null);
std.debug.assert(tail.next_to_free == null);
tail.next_to_free = poll;
}
if (this.pending_free_head == null) {
this.pending_free_head = poll;
std.debug.assert(this.pending_free_tail == null);
}
poll.flags.insert(.ignore_updates);
this.pending_free_tail = poll;
std.debug.assert(vm.after_event_loop_callback == null or vm.after_event_loop_callback == @as(?JSC.OpaqueCallback, @ptrCast(&processDeferredFrees)));
vm.after_event_loop_callback = @ptrCast(&processDeferredFrees);
vm.after_event_loop_callback_ctx = this;
}
};
const log = Output.scoped(.FilePoll, false);
pub inline fn isActive(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
pub inline fn isWatching(this: *const FilePoll) bool {
return !this.flags.contains(.needs_rearm) and (this.flags.contains(.poll_readable) or this.flags.contains(.poll_writable) or this.flags.contains(.poll_process));
}
pub inline fn isKeepingProcessAlive(this: *const FilePoll) bool {
return !this.flags.contains(.disable) and this.isActive();
}
/// Make calling ref() on this poll into a no-op.
pub fn disableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.flags.contains(.disable))
return;
this.flags.insert(.disable);
vm.event_loop_handle.?.active -= @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn enableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.flags.contains(.disable))
return;
this.flags.remove(.disable);
vm.event_loop_handle.?.active += @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn canActivate(this: *const FilePoll) bool {
return !this.flags.contains(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *FilePoll, loop: *Loop) void {
std.debug.assert(this.flags.contains(.has_incremented_poll_count));
loop.num_polls -= @as(i32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
loop.active -|= @as(u32, @intFromBool(!this.flags.contains(.disable) and this.flags.contains(.has_incremented_poll_count)));
this.flags.remove(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *FilePoll, loop: *Loop) void {
loop.num_polls += @as(i32, @intFromBool(!this.flags.contains(.has_incremented_poll_count)));
loop.active += @as(u32, @intFromBool(!this.flags.contains(.disable) and !this.flags.contains(.has_incremented_poll_count)));
this.flags.insert(.has_incremented_poll_count);
}
pub fn init(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, comptime Type: type, owner: *Type) *FilePoll {
return initWithOwner(vm, fd, flags, Owner.init(owner));
}
pub fn initWithOwner(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, owner: Owner) *FilePoll {
var poll = vm.rareData().filePolls(vm).get();
poll.fd = @intCast(fd);
poll.flags = Flags.Set.init(flags);
poll.owner = owner;
poll.next_to_free = null;
if (KQueueGenerationNumber != u0) {
max_generation_number +%= 1;
poll.generation_number = max_generation_number;
}
return poll;
}
pub inline fn canRef(this: *const FilePoll) bool {
if (this.flags.contains(.disable))
return false;
return !this.flags.contains(.has_incremented_poll_count);
}
pub inline fn canUnref(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.canUnref())
return;
log("unref", .{});
this.deactivate(vm.event_loop_handle.?);
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.canRef())
return;
log("ref", .{});
this.activate(vm.event_loop_handle.?);
}
pub fn onTick(loop: *Loop, tagged_pointer: ?*anyopaque) callconv(.C) void {
var tag = Pollable.from(tagged_pointer);
if (tag.tag() != @field(Pollable.Tag, "FilePoll"))
return;
var file_poll: *FilePoll = tag.as(FilePoll);
if (file_poll.flags.contains(.ignore_updates)) {
return;
}
if (comptime Environment.isMac)
onKQueueEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))])
else if (comptime Environment.isLinux)
onEpollEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))]);
}
const Pollable = bun.TaggedPointerUnion(
.{
FilePoll,
Deactivated,
},
);
comptime {
@export(onTick, .{ .name = "Bun__internal_dispatch_ready_poll" });
}
const timeout = std.mem.zeroes(std.os.timespec);
const kevent = std.c.kevent;
const linux = std.os.linux;
pub fn register(this: *FilePoll, loop: *Loop, flag: Flags, one_shot: bool) JSC.Maybe(void) {
return registerWithFd(this, loop, flag, one_shot, this.fd);
}
pub fn registerWithFd(this: *FilePoll, loop: *Loop, flag: Flags, one_shot: bool, fd: u64) JSC.Maybe(void) {
const watcher_fd = loop.fd;
log("register: {s} ({d})", .{ @tagName(flag), fd });
std.debug.assert(fd != invalid_fd);
if (one_shot) {
this.flags.insert(.one_shot);
}
if (comptime Environment.isLinux) {
const one_shot_flag: u32 = if (!this.flags.contains(.one_shot)) 0 else linux.EPOLL.ONESHOT;
const flags: u32 = switch (flag) {
.process,
.readable,
=> linux.EPOLL.IN | linux.EPOLL.HUP | one_shot_flag,
.writable => linux.EPOLL.OUT | linux.EPOLL.HUP | linux.EPOLL.ERR | one_shot_flag,
else => unreachable,
};
var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @intFromPtr(Pollable.init(this).ptr()) } };
var op: u32 = if (this.isRegistered() or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD;
const ctl = linux.epoll_ctl(
watcher_fd,
op,
@intCast(fd),
&event,
);
this.flags.insert(.was_ever_registered);
if (JSC.Maybe(void).errnoSys(ctl, .epoll_ctl)) |errno| {
return errno;
}
} else if (comptime Environment.isMac) {
var changelist = std.mem.zeroes([2]std.os.system.kevent64_s);
const one_shot_flag: u16 = if (!this.flags.contains(.one_shot)) 0 else std.c.EV_ONESHOT;
changelist[0] = switch (flag) {
.readable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.writable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.process => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.machport => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
else => unreachable,
};
// output events only include change errors
const KEVENT_FLAG_ERROR_EVENTS = 0x000002;
// The kevent() system call returns the number of events placed in
// the eventlist, up to the value given by nevents. If the time
// limit expires, then kevent() returns 0.
const rc = rc: {
while (true) {
const rc = std.os.system.kevent64(
watcher_fd,
&changelist,
1,
// The same array may be used for the changelist and eventlist.
&changelist,
// we set 0 here so that if we get an error on
// registration, it becomes errno
0,
KEVENT_FLAG_ERROR_EVENTS,
&timeout,
);
if (std.c.getErrno(rc) == .INTR) continue;
break :rc rc;
}
};
this.flags.insert(.was_ever_registered);
// If an error occurs while
// processing an element of the changelist and there is enough room
// in the eventlist, then the event will be placed in the eventlist
// with EV_ERROR set in flags and the system error in data.
if (changelist[0].flags == std.c.EV_ERROR and changelist[0].data != 0) {
return JSC.Maybe(void).errnoSys(changelist[0].data, .kevent).?;
// Otherwise, -1 will be returned, and errno will be set to
// indicate the error condition.
}
const errno = std.c.getErrno(rc);
if (errno != .SUCCESS) {
return JSC.Maybe(void){
.err = bun.sys.Error.fromCode(errno, .kqueue),
};
}
} else {
bun.todo(@src(), {});
}
if (this.canActivate())
this.activate(loop);
this.flags.insert(switch (flag) {
.readable => .poll_readable,
.process => if (comptime Environment.isLinux) .poll_readable else .poll_process,
.writable => .poll_writable,
.machport => .poll_machport,
else => unreachable,
});
this.flags.remove(.needs_rearm);
return JSC.Maybe(void).success;
}
const invalid_fd = bun.invalid_fd;
pub fn unregister(this: *FilePoll, loop: *Loop, force_unregister: bool) JSC.Maybe(void) {
return this.unregisterWithFd(loop, this.fd, force_unregister);
}
pub fn unregisterWithFd(this: *FilePoll, loop: *Loop, fd: bun.UFileDescriptor, force_unregister: bool) JSC.Maybe(void) {
if (!(this.flags.contains(.poll_readable) or this.flags.contains(.poll_writable) or this.flags.contains(.poll_process) or this.flags.contains(.poll_machport))) {
// no-op
return JSC.Maybe(void).success;
}
std.debug.assert(fd != invalid_fd);
const watcher_fd = loop.fd;
const flag: Flags = brk: {
if (this.flags.contains(.poll_readable))
break :brk .readable;
if (this.flags.contains(.poll_writable))
break :brk .writable;
if (this.flags.contains(.poll_process))
break :brk .process;
if (this.flags.contains(.poll_machport))
break :brk .machport;
return JSC.Maybe(void).success;
};
if (this.flags.contains(.needs_rearm) and !force_unregister) {
log("unregister: {s} ({d}) skipped due to needs_rearm", .{ @tagName(flag), fd });
this.flags.remove(.poll_process);
this.flags.remove(.poll_readable);
this.flags.remove(.poll_process);
this.flags.remove(.poll_machport);
return JSC.Maybe(void).success;
}
log("unregister: {s} ({d})", .{ @tagName(flag), fd });
if (comptime Environment.isLinux) {
const ctl = linux.epoll_ctl(
watcher_fd,
linux.EPOLL.CTL_DEL,
@intCast(fd),
null,
);
if (JSC.Maybe(void).errnoSys(ctl, .epoll_ctl)) |errno| {
return errno;
}
} else if (comptime Environment.isMac) {
var changelist = std.mem.zeroes([2]std.os.system.kevent64_s);
changelist[0] = switch (flag) {
.readable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.machport => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.writable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.process => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
else => unreachable,
};
// output events only include change errors
const KEVENT_FLAG_ERROR_EVENTS = 0x000002;
// The kevent() system call returns the number of events placed in
// the eventlist, up to the value given by nevents. If the time
// limit expires, then kevent() returns 0.
const rc = std.os.system.kevent64(
watcher_fd,
&changelist,
1,
// The same array may be used for the changelist and eventlist.
&changelist,
1,
KEVENT_FLAG_ERROR_EVENTS,
&timeout,
);
// If an error occurs while
// processing an element of the changelist and there is enough room
// in the eventlist, then the event will be placed in the eventlist
// with EV_ERROR set in flags and the system error in data.
if (changelist[0].flags == std.c.EV_ERROR) {
return JSC.Maybe(void).errnoSys(changelist[0].data, .kevent).?;
// Otherwise, -1 will be returned, and errno will be set to
// indicate the error condition.
}
const errno = std.c.getErrno(rc);
switch (rc) {
std.math.minInt(@TypeOf(rc))...-1 => return JSC.Maybe(void).errnoSys(@intFromEnum(errno), .kevent).?,
else => {},
}
} else {
bun.todo(@src(), {});
}
this.flags.remove(.needs_rearm);
this.flags.remove(.one_shot);
// we don't support both right now
std.debug.assert(!(this.flags.contains(.poll_readable) and this.flags.contains(.poll_writable)));
this.flags.remove(.poll_readable);
this.flags.remove(.poll_writable);
this.flags.remove(.poll_process);
this.flags.remove(.poll_machport);
if (this.isActive())
this.deactivate(loop);
return JSC.Maybe(void).success;
}
};
pub const Waker = @import("io").Waker;

View File

@@ -0,0 +1,3 @@
pub const Loop = opaque {};
pub const KeepAlive = opaque {};
pub const FilePoll = opaque {};

View File

@@ -0,0 +1,340 @@
const bun = @import("root").bun;
const Output = bun.Output;
const JSC = bun.JSC;
const uws = bun.uws;
const Environment = bun.Environment;
const std = @import("std");
const uv = bun.windows.libuv;
pub const Loop = uv.Loop;
pub const KeepAlive = struct {
// handle.init zeroes the memory
handle: uv.uv_async_t = undefined,
status: Status = .inactive,
const log = Output.scoped(.KeepAlive, false);
const Status = enum { active, inactive, done };
pub inline fn isActive(this: KeepAlive) bool {
if (comptime Environment.allow_assert) {
if (this.status == .active) {
std.debug.assert(this.handle.isActive());
}
}
return this.status == .active;
}
/// Make calling ref() on this poll into a no-op.
pub fn disable(this: *KeepAlive) void {
if (this.status == .active) {
this.unref(JSC.VirtualMachine.get());
this.handle.close(null);
}
this.status = .done;
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *KeepAlive, loop: *Loop) void {
_ = loop;
if (this.status != .active)
return;
this.status = .inactive;
this.handle.close(null);
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *KeepAlive, loop: *Loop) void {
if (this.status != .active)
return;
this.status = .active;
this.handle.init(loop, null);
}
pub fn init() KeepAlive {
return .{};
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
_ = vm;
if (this.status != .active)
return;
this.status = .inactive;
this.handle.unref();
}
/// From another thread, Prevent a poll from keeping the process alive.
pub fn unrefConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
_ = vm;
if (this.status != .active)
return;
this.status = .inactive;
this.handle.unref();
}
/// Prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTick(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
_ = vm;
if (this.status != .active)
return;
this.status = .inactive;
this.handle.unref();
}
/// From another thread, prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTickConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
_ = vm;
if (this.status != .active)
return;
this.status = .inactive;
this.handle.unref();
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
this.handle.init(vm.event_loop_handle.?, null);
this.handle.ref();
}
/// Allow a poll to keep the process alive.
pub fn refConcurrently(this: *KeepAlive, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
this.handle.init(vm.event_loop_handle.?, null);
this.handle.ref();
}
pub fn refConcurrentlyFromEventLoop(this: *KeepAlive, loop: *JSC.EventLoop) void {
this.refConcurrently(loop.virtual_machine);
}
pub fn unrefConcurrentlyFromEventLoop(this: *KeepAlive, loop: *JSC.EventLoop) void {
this.unrefConcurrently(loop.virtual_machine);
}
};
const Posix = @import("./posix_event_loop.zig");
pub const FilePoll = struct {
fd: bun.FileDescriptor,
owner: Owner = undefined,
flags: Flags.Set = Flags.Set{},
next_to_free: ?*FilePoll = null,
pub const Flags = Posix.FilePoll.Flags;
pub const Owner = Posix.FilePoll.Owner;
const log = Output.scoped(.FilePoll, false);
pub inline fn isActive(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
pub inline fn isWatching(this: *const FilePoll) bool {
return !this.flags.contains(.needs_rearm) and (this.flags.contains(.poll_readable) or this.flags.contains(.poll_writable) or this.flags.contains(.poll_process));
}
pub inline fn isKeepingProcessAlive(this: *const FilePoll) bool {
return !this.flags.contains(.disable) and this.isActive();
}
pub fn isRegistered(this: *const FilePoll) bool {
return this.flags.contains(.poll_writable) or this.flags.contains(.poll_readable) or this.flags.contains(.poll_process) or this.flags.contains(.poll_machport);
}
/// Make calling ref() on this poll into a no-op.
pub fn disableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.flags.contains(.disable))
return;
this.flags.insert(.disable);
vm.event_loop_handle.?.active_handles -= @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn init(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, comptime Type: type, owner: *Type) *FilePoll {
return initWithOwner(vm, fd, flags, Owner.init(owner));
}
pub fn initWithOwner(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, owner: Owner) *FilePoll {
var poll = vm.rareData().filePolls(vm).get();
poll.fd = fd;
poll.flags = Flags.Set.init(flags);
poll.owner = owner;
poll.next_to_free = null;
return poll;
}
pub fn deinit(this: *FilePoll) void {
var vm = JSC.VirtualMachine.get();
this.deinitWithVM(vm);
}
pub fn unregister(this: *FilePoll, loop: *Loop) bool {
_ = loop;
uv.uv_unref(@ptrFromInt(this.fd));
return true;
}
fn deinitPossiblyDefer(this: *FilePoll, vm: *JSC.VirtualMachine, loop: *Loop, polls: *FilePoll.Store) void {
if (this.isRegistered()) {
_ = this.unregister(loop);
}
const was_ever_registered = this.flags.contains(.was_ever_registered);
this.flags = Flags.Set{};
this.fd = bun.invalid_fd;
polls.put(this, vm, was_ever_registered);
}
pub fn isReadable(this: *FilePoll) bool {
const readable = this.flags.contains(.readable);
this.flags.remove(.readable);
return readable;
}
pub fn isHUP(this: *FilePoll) bool {
const readable = this.flags.contains(.hup);
this.flags.remove(.hup);
return readable;
}
pub fn isEOF(this: *FilePoll) bool {
const readable = this.flags.contains(.eof);
this.flags.remove(.eof);
return readable;
}
pub fn clearEvent(poll: *FilePoll, flag: Flags) void {
poll.flags.remove(flag);
}
pub fn isWritable(this: *FilePoll) bool {
const readable = this.flags.contains(.writable);
this.flags.remove(.writable);
return readable;
}
pub fn deinitWithVM(this: *FilePoll, vm: *JSC.VirtualMachine) void {
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm));
}
pub fn enableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.flags.contains(.disable))
return;
this.flags.remove(.disable);
vm.event_loop_handle.?.active_handles += @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn canActivate(this: *const FilePoll) bool {
return !this.flags.contains(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *FilePoll, loop: *Loop) void {
std.debug.assert(this.flags.contains(.has_incremented_poll_count));
loop.active_handles -= @as(u32, @intFromBool(!this.flags.contains(.disable) and this.flags.contains(.has_incremented_poll_count)));
this.flags.remove(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *FilePoll, loop: *Loop) void {
loop.active_handles += @as(u32, @intFromBool(!this.flags.contains(.disable) and !this.flags.contains(.has_incremented_poll_count)));
this.flags.insert(.has_incremented_poll_count);
}
pub inline fn canRef(this: *const FilePoll) bool {
if (this.flags.contains(.disable))
return false;
return !this.flags.contains(.has_incremented_poll_count);
}
pub inline fn canUnref(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.canUnref())
return;
log("unref", .{});
this.deactivate(vm.event_loop_handle.?);
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.canRef())
return;
log("ref", .{});
this.activate(vm.event_loop_handle.?);
}
const HiveArray = bun.HiveArray(FilePoll, 128).Fallback;
pub const Store = struct {
hive: HiveArray,
pending_free_head: ?*FilePoll = null,
pending_free_tail: ?*FilePoll = null,
const log = Output.scoped(.FilePoll, false);
pub fn init(allocator: std.mem.Allocator) Store {
return .{
.hive = HiveArray.init(allocator),
};
}
pub fn get(this: *Store) *FilePoll {
return this.hive.get();
}
pub fn processDeferredFrees(this: *Store) void {
var next = this.pending_free_head;
while (next) |current| {
next = current.next_to_free;
current.next_to_free = null;
this.hive.put(current);
}
this.pending_free_head = null;
this.pending_free_tail = null;
}
pub fn put(this: *Store, poll: *FilePoll, vm: *JSC.VirtualMachine, ever_registered: bool) void {
if (!ever_registered) {
this.hive.put(poll);
return;
}
std.debug.assert(poll.next_to_free == null);
if (this.pending_free_tail) |tail| {
std.debug.assert(this.pending_free_head != null);
std.debug.assert(tail.next_to_free == null);
tail.next_to_free = poll;
}
if (this.pending_free_head == null) {
this.pending_free_head = poll;
std.debug.assert(this.pending_free_tail == null);
}
poll.flags.insert(.ignore_updates);
this.pending_free_tail = poll;
std.debug.assert(vm.after_event_loop_callback == null or vm.after_event_loop_callback == @as(?JSC.OpaqueCallback, @ptrCast(&processDeferredFrees)));
vm.after_event_loop_callback = @ptrCast(&processDeferredFrees);
vm.after_event_loop_callback_ctx = this;
}
};
};

View File

@@ -1 +1 @@
7
7

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
export default [
define({

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
export default [
define({

View File

@@ -204,7 +204,6 @@ const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer;
const getAllocator = @import("../base.zig").getAllocator;
const JSValue = @import("root").bun.JSC.JSValue;
const Microtask = @import("root").bun.JSC.Microtask;
const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject;
const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef;
const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr;
@@ -234,6 +233,7 @@ const Which = @import("../../which.zig");
const ErrorableString = JSC.ErrorableString;
const is_bindgen = JSC.is_bindgen;
const max_addressible_memory = std.math.maxInt(u56);
const Async = bun.Async;
threadlocal var css_imports_list_strings: [512]ZigString = undefined;
threadlocal var css_imports_list: [512]Api.StringPointer = undefined;
@@ -1554,12 +1554,12 @@ pub const Crypto = struct {
promise: JSC.JSPromise.Strong,
event_loop: *JSC.EventLoop,
global: *JSC.JSGlobalObject,
ref: JSC.PollRef = .{},
ref: Async.KeepAlive = .{},
task: JSC.WorkPoolTask = .{ .callback = &run },
pub const Result = struct {
value: Value,
ref: JSC.PollRef = .{},
ref: Async.KeepAlive = .{},
task: JSC.AnyTask = undefined,
promise: JSC.JSPromise.Strong,
@@ -1804,12 +1804,12 @@ pub const Crypto = struct {
promise: JSC.JSPromise.Strong,
event_loop: *JSC.EventLoop,
global: *JSC.JSGlobalObject,
ref: JSC.PollRef = .{},
ref: Async.KeepAlive = .{},
task: JSC.WorkPoolTask = .{ .callback = &run },
pub const Result = struct {
value: Value,
ref: JSC.PollRef = .{},
ref: Async.KeepAlive = .{},
task: JSC.AnyTask = undefined,
promise: JSC.JSPromise.Strong,
@@ -3335,7 +3335,8 @@ pub const Timer = struct {
if (val.did_unref_timer) {
val.did_unref_timer = false;
vm.event_loop_handle.?.num_polls += 1;
if (comptime Environment.isPosix)
vm.event_loop_handle.?.num_polls += 1;
}
}
}
@@ -3408,7 +3409,7 @@ pub const Timer = struct {
.callback = JSC.Strong.create(callback, globalThis),
.globalThis = globalThis,
.timer = uws.Timer.create(
vm.event_loop_handle.?,
vm.uwsLoop(),
id,
),
};
@@ -3454,7 +3455,8 @@ pub const Timer = struct {
if (!val.did_unref_timer) {
val.did_unref_timer = true;
vm.event_loop_handle.?.num_polls -= 1;
if (comptime Environment.isPosix)
vm.event_loop_handle.?.num_polls -= 1;
}
}
}
@@ -3484,7 +3486,7 @@ pub const Timer = struct {
globalThis: *JSC.JSGlobalObject,
timer: *uws.Timer,
did_unref_timer: bool = false,
poll_ref: JSC.PollRef = JSC.PollRef.init(),
poll_ref: Async.KeepAlive = Async.KeepAlive.init(),
arguments: JSC.Strong = .{},
has_scheduled_job: bool = false,
@@ -3606,8 +3608,9 @@ pub const Timer = struct {
this.timer.deinit(false);
// balance double unreffing in doUnref
vm.event_loop_handle.?.num_polls += @as(i32, @intFromBool(this.did_unref_timer));
if (comptime Environment.isPosix)
// balance double unreffing in doUnref
vm.event_loop_handle.?.num_polls += @as(i32, @intFromBool(this.did_unref_timer));
this.callback.deinit();
this.arguments.deinit();
@@ -3663,7 +3666,7 @@ pub const Timer = struct {
.callback = JSC.Strong.create(callback, globalThis),
.globalThis = globalThis,
.timer = uws.Timer.create(
vm.event_loop_handle.?,
vm.uwsLoop(),
Timeout.ID{
.id = id,
.kind = kind,

View File

@@ -14,7 +14,7 @@ const JSC = @import("root").bun.JSC;
const JSValue = JSC.JSValue;
const JSGlobalObject = JSC.JSGlobalObject;
const c_ares = bun.c_ares;
const Async = bun.Async;
const GetAddrInfoAsyncCallback = fn (i32, ?*std.c.addrinfo, ?*anyopaque) callconv(.C) void;
const INET6_ADDRSTRLEN = if (bun.Environment.isWindows) 65 else 46;
const IANA_DNS_PORT = 53;
@@ -42,7 +42,7 @@ const LibInfo = struct {
const RTLD_LAZY = 1;
const RTLD_LOCAL = 4;
handle = std.c.dlopen("libinfo.dylib", RTLD_LAZY | RTLD_LOCAL);
handle = bun.C.dlopen("libinfo.dylib", RTLD_LAZY | RTLD_LOCAL);
if (handle == null)
Output.debug("libinfo.dylib not found", .{});
return handle;
@@ -120,7 +120,7 @@ const LibInfo = struct {
return promise_value;
}
std.debug.assert(request.backend.libinfo.machport != null);
request.backend.libinfo.file_poll = bun.JSC.FilePoll.init(this.vm, std.math.maxInt(i32) - 1, .{}, GetAddrInfoRequest, request);
request.backend.libinfo.file_poll = bun.Async.FilePoll.init(this.vm, std.math.maxInt(i32) - 1, .{}, GetAddrInfoRequest, request);
std.debug.assert(
request.backend.libinfo.file_poll.?.registerWithFd(
this.vm.event_loop_handle.?,
@@ -645,7 +645,7 @@ pub fn ResolveInfoRequest(comptime cares_type: type, comptime type_name: []const
var hasher = std.hash.Wyhash.init(0);
hasher.update(name);
const hash = hasher.final();
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
request.* = .{
.resolver_for_caching = resolver,
@@ -742,7 +742,7 @@ pub const GetHostByAddrInfoRequest = struct {
var hasher = std.hash.Wyhash.init(0);
hasher.update(name);
const hash = hasher.final();
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
request.* = .{
.resolver_for_caching = resolver,
@@ -818,14 +818,14 @@ pub const CAresNameInfo = struct {
globalThis: *JSC.JSGlobalObject = undefined,
promise: JSC.JSPromise.Strong,
poll_ref: JSC.PollRef,
poll_ref: bun.Async.KeepAlive,
allocated: bool = false,
next: ?*@This() = null,
name: []const u8,
pub fn init(globalThis: *JSC.JSGlobalObject, allocator: std.mem.Allocator, name: []const u8) !*@This() {
var this = try allocator.create(@This());
var poll_ref = JSC.PollRef.init();
var poll_ref = bun.Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
this.* = .{ .globalThis = globalThis, .promise = JSC.JSPromise.Strong.init(globalThis), .poll_ref = poll_ref, .allocated = true, .name = name };
return this;
@@ -906,7 +906,7 @@ pub const GetNameInfoRequest = struct {
var hasher = std.hash.Wyhash.init(0);
hasher.update(name);
const hash = hasher.final();
var poll_ref = JSC.PollRef.init();
var poll_ref = bun.Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
request.* = .{
.resolver_for_caching = resolver,
@@ -997,7 +997,7 @@ pub const GetAddrInfoRequest = struct {
comptime cache_field: []const u8,
) !*GetAddrInfoRequest {
var request = try globalThis.allocator().create(GetAddrInfoRequest);
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
request.* = .{
.backend = backend,
@@ -1129,7 +1129,7 @@ pub const GetAddrInfoRequest = struct {
},
pub const LibInfo = struct {
file_poll: ?*bun.JSC.FilePoll = null,
file_poll: ?*bun.Async.FilePoll = null,
machport: ?*anyopaque = null,
extern fn getaddrinfo_send_reply(*anyopaque, *const JSC.DNS.LibInfo.GetaddrinfoAsyncHandleReply) bool;
@@ -1208,14 +1208,14 @@ pub const CAresReverse = struct {
globalThis: *JSC.JSGlobalObject = undefined,
promise: JSC.JSPromise.Strong,
poll_ref: JSC.PollRef,
poll_ref: Async.KeepAlive,
allocated: bool = false,
next: ?*@This() = null,
name: []const u8,
pub fn init(globalThis: *JSC.JSGlobalObject, allocator: std.mem.Allocator, name: []const u8) !*@This() {
var this = try allocator.create(@This());
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
this.* = .{ .globalThis = globalThis, .promise = JSC.JSPromise.Strong.init(globalThis), .poll_ref = poll_ref, .allocated = true, .name = name };
return this;
@@ -1279,14 +1279,14 @@ pub fn CAresLookup(comptime cares_type: type, comptime type_name: []const u8) ty
globalThis: *JSC.JSGlobalObject = undefined,
promise: JSC.JSPromise.Strong,
poll_ref: JSC.PollRef,
poll_ref: Async.KeepAlive,
allocated: bool = false,
next: ?*@This() = null,
name: []const u8,
pub fn init(globalThis: *JSC.JSGlobalObject, allocator: std.mem.Allocator, name: []const u8) !*@This() {
var this = try allocator.create(@This());
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
this.* = .{ .globalThis = globalThis, .promise = JSC.JSPromise.Strong.init(globalThis), .poll_ref = poll_ref, .allocated = true, .name = name };
return this;
@@ -1352,11 +1352,11 @@ pub const DNSLookup = struct {
promise: JSC.JSPromise.Strong,
allocated: bool = false,
next: ?*DNSLookup = null,
poll_ref: JSC.PollRef,
poll_ref: Async.KeepAlive,
pub fn init(globalThis: *JSC.JSGlobalObject, allocator: std.mem.Allocator) !*DNSLookup {
var this = try allocator.create(DNSLookup);
var poll_ref = JSC.PollRef.init();
var poll_ref = Async.KeepAlive.init();
poll_ref.ref(globalThis.bunVM());
this.* = .{
@@ -1463,7 +1463,7 @@ pub const GlobalData = struct {
global.* = .{
.resolver = .{
.vm = vm,
.polls = std.AutoArrayHashMap(i32, ?*JSC.FilePoll).init(allocator),
.polls = std.AutoArrayHashMap(i32, ?*Async.FilePoll).init(allocator),
},
};
@@ -1476,7 +1476,7 @@ pub const DNSResolver = struct {
channel: ?*c_ares.Channel = null,
vm: *JSC.VirtualMachine,
polls: std.AutoArrayHashMap(i32, ?*JSC.FilePoll) = undefined,
polls: std.AutoArrayHashMap(i32, ?*Async.FilePoll) = undefined,
pending_host_cache_cares: PendingCache = PendingCache.init(),
pending_host_cache_native: PendingCache = PendingCache.init(),
@@ -1818,7 +1818,7 @@ pub const DNSResolver = struct {
pub fn onDNSPoll(
this: *DNSResolver,
poll: *JSC.FilePoll,
poll: *Async.FilePoll,
) void {
var vm = this.vm;
defer vm.drainMicrotasks();
@@ -1842,6 +1842,11 @@ pub const DNSResolver = struct {
readable: bool,
writable: bool,
) void {
if (comptime Environment.isWindows) {
bun.todo(@src(), {});
return;
}
var vm = this.vm;
if (!readable and !writable) {
@@ -1860,7 +1865,7 @@ pub const DNSResolver = struct {
var poll_entry = this.polls.getOrPut(fd) catch unreachable;
if (!poll_entry.found_existing) {
poll_entry.value_ptr.* = JSC.FilePoll.init(vm, bun.toFD(fd), .{}, DNSResolver, this);
poll_entry.value_ptr.* = Async.FilePoll.init(vm, bun.toFD(fd), .{}, DNSResolver, this);
}
var poll = poll_entry.value_ptr.*.?;
@@ -2020,8 +2025,8 @@ pub const DNSResolver = struct {
return .zero;
}
const ip = ip_str.toSliceClone(globalThis, bun.default_allocator).slice();
const ip_slice = ip_str.toSliceClone(globalThis, bun.default_allocator);
const ip = ip_slice.slice();
var vm = globalThis.bunVM();
var resolver = vm.rareData().globalDNSResolver(vm);
var channel: *c_ares.Channel = switch (resolver.getChannel()) {
@@ -2032,7 +2037,7 @@ pub const DNSResolver = struct {
.code = bun.String.static(err.code()),
.message = bun.String.static(err.label()),
};
defer ip_slice.deinit();
globalThis.throwValue(system_error.toErrorInstance(globalThis));
return .zero;
},

View File

@@ -17,6 +17,7 @@ const uws = @import("root").bun.uws;
const ZigString = JSC.ZigString;
const BoringSSL = bun.BoringSSL;
const X509 = @import("./x509.zig");
const Async = bun.Async;
fn normalizeListeningHost(host: [:0]const u8) ?[*:0]const u8 {
if (host.len == 0 or strings.eqlComptime(host, "0.0.0.0")) {
@@ -447,7 +448,7 @@ pub const Listener = struct {
handlers: Handlers,
listener: ?*uws.ListenSocket = null,
poll_ref: JSC.PollRef = JSC.PollRef.init(),
poll_ref: Async.KeepAlive = Async.KeepAlive.init(),
connection: UnixOrHost,
socket_context: ?*uws.SocketContext = null,
ssl: bool = false,
@@ -582,7 +583,7 @@ pub const Listener = struct {
var socket_context = uws.us_create_bun_socket_context(
@intFromBool(ssl_enabled),
uws.Loop.get().?,
uws.Loop.get(),
@sizeOf(usize),
ctx_opts,
) orelse {
@@ -919,7 +920,7 @@ pub const Listener = struct {
globalObject.bunVM().eventLoop().ensureWaker();
var socket_context = uws.us_create_bun_socket_context(@intFromBool(ssl_enabled), uws.Loop.get().?, @sizeOf(usize), ctx_opts).?;
var socket_context = uws.us_create_bun_socket_context(@intFromBool(ssl_enabled), uws.Loop.get(), @sizeOf(usize), ctx_opts).?;
var connection: Listener.UnixOrHost = if (port) |port_| .{
.host = .{ .host = (hostname_or_unix.cloneIfNeeded(bun.default_allocator) catch unreachable).slice(), .port = port_ },
} else .{
@@ -1087,7 +1088,7 @@ fn NewSocket(comptime ssl: bool) type {
wrapped: WrappedType = .none,
handlers: *Handlers,
this_value: JSC.JSValue = .zero,
poll_ref: JSC.PollRef = JSC.PollRef.init(),
poll_ref: Async.KeepAlive = Async.KeepAlive.init(),
reffer: JSC.Ref = JSC.Ref.init(),
last_4: [4]u8 = .{ 0, 0, 0, 0 },
authorized: bool = false,

View File

@@ -13,8 +13,9 @@ const JSC = @import("root").bun.JSC;
const JSValue = JSC.JSValue;
const JSGlobalObject = JSC.JSGlobalObject;
const Which = @import("../../../which.zig");
const uws = @import("../../../deps/uws.zig");
const Async = bun.Async;
const IPC = @import("../../ipc.zig");
const uws = bun.uws;
pub const Subprocess = struct {
const log = Output.scoped(.Subprocess, false);
@@ -30,7 +31,7 @@ pub const Subprocess = struct {
stdout: Readable,
stderr: Readable,
killed: bool = false,
poll_ref: ?*JSC.FilePoll = null,
poll_ref: ?*Async.FilePoll = null,
exit_promise: JSC.Strong = .{},
on_exit_callback: JSC.Strong = .{},
@@ -467,7 +468,7 @@ pub const Subprocess = struct {
pub const BufferedInput = struct {
remain: []const u8 = "",
fd: bun.FileDescriptor = bun.invalid_fd,
poll_ref: ?*JSC.FilePoll = null,
poll_ref: ?*Async.FilePoll = null,
written: usize = 0,
source: union(enum) {
@@ -1560,7 +1561,7 @@ pub const Subprocess = struct {
const watchfd = if (comptime Environment.isLinux) pidfd else pid;
if (comptime !is_sync) {
var poll = JSC.FilePoll.init(jsc_vm, watchfd, .{}, Subprocess, subprocess);
var poll = Async.FilePoll.init(jsc_vm, watchfd, .{}, Subprocess, subprocess);
subprocess.poll_ref = poll;
switch (subprocess.poll_ref.?.register(
jsc_vm.event_loop_handle.?,
@@ -1623,7 +1624,7 @@ pub const Subprocess = struct {
subprocess.closeIO(.stdin);
{
var poll = JSC.FilePoll.init(jsc_vm, watchfd, .{}, Subprocess, subprocess);
var poll = Async.FilePoll.init(jsc_vm, watchfd, .{}, Subprocess, subprocess);
subprocess.poll_ref = poll;
switch (subprocess.poll_ref.?.register(
jsc_vm.event_loop_handle.?,

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
const names = ["SHA1", "MD5", "MD4", "SHA224", "SHA512", "SHA384", "SHA256", "SHA512_256"];
const named = names.map(name => {

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
export default [
define({

View File

@@ -50,7 +50,6 @@ const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer;
const getAllocator = @import("../base.zig").getAllocator;
const JSValue = @import("root").bun.JSC.JSValue;
const Microtask = @import("root").bun.JSC.Microtask;
const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject;
const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef;
const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr;
@@ -672,7 +671,9 @@ pub const FFI = struct {
val.arg_types.clearAndFree(allocator);
if (val.state) |state| {
TCC.tcc_delete(state);
if (comptime !Environment.isWindows) {
TCC.tcc_delete(state);
}
val.state = null;
}
@@ -772,6 +773,9 @@ pub const FFI = struct {
this: *Function,
allocator: std.mem.Allocator,
) !void {
if (comptime Environment.isWindows) {
return;
}
var source_code = std.ArrayList(u8).init(allocator);
var source_code_writer = source_code.writer();
try this.printSourceCode(&source_code_writer);
@@ -786,7 +790,9 @@ pub const FFI = struct {
this.state = state;
defer {
if (this.step == .failed) {
TCC.tcc_delete(state);
if (comptime !Environment.isWindows) {
TCC.tcc_delete(state);
}
this.state = null;
}
}
@@ -895,6 +901,9 @@ pub const FFI = struct {
}
pub fn inject(state: *TCC.TCCState) void {
if (comptime Environment.isWindows) {
return;
}
JSC.markBinding(@src());
_ = TCC.tcc_add_symbol(state, "memset", &memset);
_ = TCC.tcc_add_symbol(state, "memcpy", &memcpy);
@@ -935,6 +944,9 @@ pub const FFI = struct {
js_function: JSValue,
is_threadsafe: bool,
) !void {
if (comptime Environment.isWindows) {
return;
}
JSC.markBinding(@src());
var source_code = std.ArrayList(u8).init(allocator);
var source_code_writer = source_code.writer();
@@ -958,7 +970,9 @@ pub const FFI = struct {
this.state = state;
defer {
if (this.step == .failed) {
TCC.tcc_delete(state);
if (comptime !Environment.isWindows) {
TCC.tcc_delete(state);
}
this.state = null;
}
}

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
export default [
define({

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
export default [
define({

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
function generate(name) {
return define({

View File

@@ -49,7 +49,6 @@ const MarkedArrayBuffer = @import("../base.zig").MarkedArrayBuffer;
const getAllocator = @import("../base.zig").getAllocator;
const JSValue = @import("root").bun.JSC.JSValue;
const Microtask = @import("root").bun.JSC.Microtask;
const JSGlobalObject = @import("root").bun.JSC.JSGlobalObject;
const ExceptionValueRef = @import("root").bun.JSC.ExceptionValueRef;
const JSPrivateDataPtr = @import("root").bun.JSC.JSPrivateDataPtr;
@@ -90,6 +89,7 @@ const SendfileContext = struct {
};
const DateTime = bun.DateTime;
const linux = std.os.linux;
const Async = bun.Async;
const BlobFileContentResult = struct {
data: [:0]const u8,
@@ -4830,7 +4830,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
listen_callback: JSC.AnyTask = undefined,
allocator: std.mem.Allocator,
poll_ref: JSC.PollRef = .{},
poll_ref: Async.KeepAlive = .{},
temporary_url_buffer: std.ArrayListUnmanaged(u8) = .{},
cached_hostname: bun.String = bun.String.empty,
@@ -5580,7 +5580,7 @@ pub fn NewServer(comptime NamespaceType: type, comptime ssl_enabled_: bool, comp
}
this.listener = socket;
this.vm.event_loop_handle = uws.Loop.get();
this.vm.event_loop_handle = Async.Loop.get();
if (!ssl_enabled_)
this.vm.addListeningSocketForWatchMode(@intCast(socket.?.socket().fd()));
}

View File

@@ -1,4 +1,4 @@
import { define } from "../scripts/class-definitions";
import { define } from "../../codegen/class-definitions";
function generate(ssl) {
return define({

View File

@@ -1591,848 +1591,6 @@ pub const Ref = struct {
}
};
/// Track if an object whose file descriptor is being watched should keep the event loop alive.
/// This is not reference counted. It only tracks active or inactive.
pub const PollRef = struct {
status: Status = .inactive,
const log = Output.scoped(.PollRef, false);
const Status = enum { active, inactive, done };
pub inline fn isActive(this: PollRef) bool {
return this.status == .active;
}
/// Make calling ref() on this poll into a no-op.
pub fn disable(this: *PollRef) void {
this.unref(JSC.VirtualMachine.get());
this.status = .done;
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *PollRef, loop: *uws.Loop) void {
if (this.status != .active)
return;
this.status = .inactive;
loop.num_polls -= 1;
loop.active -|= 1;
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *PollRef, loop: *uws.Loop) void {
if (this.status != .inactive)
return;
this.status = .active;
loop.num_polls += 1;
loop.active += 1;
}
pub fn init() PollRef {
return .{};
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.event_loop_handle.?.unref();
}
/// From another thread, Prevent a poll from keeping the process alive.
pub fn unrefConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.event_loop_handle.?.unrefConcurrently();
}
/// Prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTick(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
vm.pending_unref_counter +|= 1;
}
/// From another thread, prevent a poll from keeping the process alive on the next tick.
pub fn unrefOnNextTickConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .active)
return;
this.status = .inactive;
_ = @atomicRmw(@TypeOf(vm.pending_unref_counter), &vm.pending_unref_counter, .Add, 1, .Monotonic);
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
vm.event_loop_handle.?.ref();
}
/// Allow a poll to keep the process alive.
pub fn refConcurrently(this: *PollRef, vm: *JSC.VirtualMachine) void {
if (this.status != .inactive)
return;
this.status = .active;
vm.event_loop_handle.?.refConcurrently();
}
pub fn refConcurrentlyFromEventLoop(this: *PollRef, loop: *JSC.EventLoop) void {
this.refConcurrently(loop.virtual_machine);
}
pub fn unrefConcurrentlyFromEventLoop(this: *PollRef, loop: *JSC.EventLoop) void {
this.unrefConcurrently(loop.virtual_machine);
}
};
const KQueueGenerationNumber = if (Environment.isMac and Environment.allow_assert) usize else u0;
pub const FilePoll = struct {
var max_generation_number: KQueueGenerationNumber = 0;
fd: bun.UFileDescriptor = invalid_fd,
flags: Flags.Set = Flags.Set{},
owner: Owner = undefined,
/// We re-use FilePoll objects to avoid allocating new ones.
///
/// That means we might run into situations where the event is stale.
/// on macOS kevent64 has an extra pointer field so we use it for that
/// linux doesn't have a field like that
generation_number: KQueueGenerationNumber = 0,
next_to_free: ?*FilePoll = null,
const FileReader = JSC.WebCore.FileReader;
const FileSink = JSC.WebCore.FileSink;
const FIFO = JSC.WebCore.FIFO;
const Subprocess = JSC.Subprocess;
const BufferedInput = Subprocess.BufferedInput;
const BufferedOutput = Subprocess.BufferedOutput;
const DNSResolver = JSC.DNS.DNSResolver;
const GetAddrInfoRequest = JSC.DNS.GetAddrInfoRequest;
const Deactivated = opaque {
pub var owner: Owner = Owner.init(@as(*Deactivated, @ptrFromInt(@as(usize, 0xDEADBEEF))));
};
pub const Owner = bun.TaggedPointerUnion(.{
FileReader,
FileSink,
Subprocess,
BufferedInput,
FIFO,
Deactivated,
DNSResolver,
GetAddrInfoRequest,
});
fn updateFlags(poll: *FilePoll, updated: Flags.Set) void {
var flags = poll.flags;
flags.remove(.readable);
flags.remove(.writable);
flags.remove(.process);
flags.remove(.machport);
flags.remove(.eof);
flags.remove(.hup);
flags.setUnion(updated);
poll.flags = flags;
}
pub fn onKQueueEvent(poll: *FilePoll, loop: *uws.Loop, kqueue_event: *const std.os.system.kevent64_s) void {
if (KQueueGenerationNumber != u0)
std.debug.assert(poll.generation_number == kqueue_event.ext[0]);
poll.updateFlags(Flags.fromKQueueEvent(kqueue_event.*));
poll.onUpdate(loop, kqueue_event.data);
}
pub fn onEpollEvent(poll: *FilePoll, loop: *uws.Loop, epoll_event: *std.os.linux.epoll_event) void {
poll.updateFlags(Flags.fromEpollEvent(epoll_event.*));
poll.onUpdate(loop, 0);
}
pub fn clearEvent(poll: *FilePoll, flag: Flags) void {
poll.flags.remove(flag);
}
pub fn isReadable(this: *FilePoll) bool {
const readable = this.flags.contains(.readable);
this.flags.remove(.readable);
return readable;
}
pub fn isHUP(this: *FilePoll) bool {
const readable = this.flags.contains(.hup);
this.flags.remove(.hup);
return readable;
}
pub fn isEOF(this: *FilePoll) bool {
const readable = this.flags.contains(.eof);
this.flags.remove(.eof);
return readable;
}
pub fn isWritable(this: *FilePoll) bool {
const readable = this.flags.contains(.writable);
this.flags.remove(.writable);
return readable;
}
pub fn deinit(this: *FilePoll) void {
var vm = JSC.VirtualMachine.get();
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), false);
}
pub fn deinitForceUnregister(this: *FilePoll) void {
var vm = JSC.VirtualMachine.get();
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), true);
}
fn deinitPossiblyDefer(this: *FilePoll, vm: *JSC.VirtualMachine, loop: *uws.Loop, polls: *JSC.FilePoll.Store, force_unregister: bool) void {
if (this.isRegistered()) {
_ = this.unregister(loop, force_unregister);
}
this.owner = Deactivated.owner;
const was_ever_registered = this.flags.contains(.was_ever_registered);
this.flags = Flags.Set{};
this.fd = invalid_fd;
polls.put(this, vm, was_ever_registered);
}
pub fn deinitWithVM(this: *FilePoll, vm: *JSC.VirtualMachine) void {
var loop = vm.event_loop_handle.?;
this.deinitPossiblyDefer(vm, loop, vm.rareData().filePolls(vm), false);
}
pub fn isRegistered(this: *const FilePoll) bool {
return this.flags.contains(.poll_writable) or this.flags.contains(.poll_readable) or this.flags.contains(.poll_process) or this.flags.contains(.poll_machport);
}
const kqueue_or_epoll = if (Environment.isMac) "kevent" else "epoll";
pub fn onUpdate(poll: *FilePoll, loop: *uws.Loop, size_or_offset: i64) void {
if (poll.flags.contains(.one_shot) and !poll.flags.contains(.needs_rearm)) {
if (poll.flags.contains(.has_incremented_poll_count)) poll.deactivate(loop);
poll.flags.insert(.needs_rearm);
}
var ptr = poll.owner;
switch (ptr.tag()) {
@field(Owner.Tag, "FIFO") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) FIFO", .{poll.fd});
ptr.as(FIFO).ready(size_or_offset, poll.flags.contains(.hup));
},
@field(Owner.Tag, "Subprocess") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) Subprocess", .{poll.fd});
var loader = ptr.as(JSC.Subprocess);
loader.onExitNotification();
},
@field(Owner.Tag, "FileSink") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) FileSink", .{poll.fd});
var loader = ptr.as(JSC.WebCore.FileSink);
loader.onPoll(size_or_offset, 0);
},
@field(Owner.Tag, "DNSResolver") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) DNSResolver", .{poll.fd});
var loader: *DNSResolver = ptr.as(DNSResolver);
loader.onDNSPoll(poll);
},
@field(Owner.Tag, "GetAddrInfoRequest") => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) GetAddrInfoRequest", .{poll.fd});
var loader: *GetAddrInfoRequest = ptr.as(GetAddrInfoRequest);
loader.onMachportChange();
},
else => {
log("onUpdate " ++ kqueue_or_epoll ++ " (fd: {d}) disconnected?", .{poll.fd});
},
}
}
pub const Flags = enum {
// What are we asking the event loop about?
/// Poll for readable events
poll_readable,
/// Poll for writable events
poll_writable,
/// Poll for process-related events
poll_process,
/// Poll for machport events
poll_machport,
// What did the event loop tell us?
readable,
writable,
process,
eof,
hup,
machport,
// What is the type of file descriptor?
fifo,
tty,
one_shot,
needs_rearm,
has_incremented_poll_count,
disable,
nonblocking,
was_ever_registered,
ignore_updates,
pub fn poll(this: Flags) Flags {
return switch (this) {
.readable => .poll_readable,
.writable => .poll_writable,
.process => .poll_process,
.machport => .poll_machport,
else => this,
};
}
pub const Set = std.EnumSet(Flags);
pub const Struct = std.enums.EnumFieldStruct(Flags, bool, false);
pub fn fromKQueueEvent(kqueue_event: std.os.system.kevent64_s) Flags.Set {
var flags = Flags.Set{};
if (kqueue_event.filter == std.os.system.EVFILT_READ) {
flags.insert(Flags.readable);
log("readable", .{});
if (kqueue_event.flags & std.os.system.EV_EOF != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
} else if (kqueue_event.filter == std.os.system.EVFILT_WRITE) {
flags.insert(Flags.writable);
log("writable", .{});
if (kqueue_event.flags & std.os.system.EV_EOF != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
} else if (kqueue_event.filter == std.os.system.EVFILT_PROC) {
log("proc", .{});
flags.insert(Flags.process);
} else if (kqueue_event.filter == std.os.system.EVFILT_MACHPORT) {
log("machport", .{});
flags.insert(Flags.machport);
}
return flags;
}
pub fn fromEpollEvent(epoll: std.os.linux.epoll_event) Flags.Set {
var flags = Flags.Set{};
if (epoll.events & std.os.linux.EPOLL.IN != 0) {
flags.insert(Flags.readable);
log("readable", .{});
}
if (epoll.events & std.os.linux.EPOLL.OUT != 0) {
flags.insert(Flags.writable);
log("writable", .{});
}
if (epoll.events & std.os.linux.EPOLL.ERR != 0) {
flags.insert(Flags.eof);
log("eof", .{});
}
if (epoll.events & std.os.linux.EPOLL.HUP != 0) {
flags.insert(Flags.hup);
log("hup", .{});
}
return flags;
}
};
const HiveArray = bun.HiveArray(FilePoll, 128).Fallback;
// We defer freeing FilePoll until the end of the next event loop iteration
// This ensures that we don't free a FilePoll before the next callback is called
pub const Store = struct {
hive: HiveArray,
pending_free_head: ?*FilePoll = null,
pending_free_tail: ?*FilePoll = null,
const log = Output.scoped(.FilePoll, false);
pub fn init(allocator: std.mem.Allocator) Store {
return .{
.hive = HiveArray.init(allocator),
};
}
pub fn get(this: *Store) *FilePoll {
return this.hive.get();
}
pub fn processDeferredFrees(this: *Store) void {
var next = this.pending_free_head;
while (next) |current| {
next = current.next_to_free;
current.next_to_free = null;
this.hive.put(current);
}
this.pending_free_head = null;
this.pending_free_tail = null;
}
pub fn put(this: *Store, poll: *FilePoll, vm: *JSC.VirtualMachine, ever_registered: bool) void {
if (!ever_registered) {
this.hive.put(poll);
return;
}
std.debug.assert(poll.next_to_free == null);
if (this.pending_free_tail) |tail| {
std.debug.assert(this.pending_free_head != null);
std.debug.assert(tail.next_to_free == null);
tail.next_to_free = poll;
}
if (this.pending_free_head == null) {
this.pending_free_head = poll;
std.debug.assert(this.pending_free_tail == null);
}
poll.flags.insert(.ignore_updates);
this.pending_free_tail = poll;
std.debug.assert(vm.after_event_loop_callback == null or vm.after_event_loop_callback == @as(?JSC.OpaqueCallback, @ptrCast(&processDeferredFrees)));
vm.after_event_loop_callback = @ptrCast(&processDeferredFrees);
vm.after_event_loop_callback_ctx = this;
}
};
const log = Output.scoped(.FilePoll, false);
pub inline fn isActive(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
pub inline fn isWatching(this: *const FilePoll) bool {
return !this.flags.contains(.needs_rearm) and (this.flags.contains(.poll_readable) or this.flags.contains(.poll_writable) or this.flags.contains(.poll_process));
}
pub inline fn isKeepingProcessAlive(this: *const FilePoll) bool {
return !this.flags.contains(.disable) and this.isActive();
}
/// Make calling ref() on this poll into a no-op.
pub fn disableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.flags.contains(.disable))
return;
this.flags.insert(.disable);
vm.event_loop_handle.?.active -= @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn enableKeepingProcessAlive(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.flags.contains(.disable))
return;
this.flags.remove(.disable);
vm.event_loop_handle.?.active += @as(u32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
}
pub fn canActivate(this: *const FilePoll) bool {
return !this.flags.contains(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn deactivate(this: *FilePoll, loop: *uws.Loop) void {
std.debug.assert(this.flags.contains(.has_incremented_poll_count));
loop.num_polls -= @as(i32, @intFromBool(this.flags.contains(.has_incremented_poll_count)));
loop.active -|= @as(u32, @intFromBool(!this.flags.contains(.disable) and this.flags.contains(.has_incremented_poll_count)));
this.flags.remove(.has_incremented_poll_count);
}
/// Only intended to be used from EventLoop.Pollable
pub fn activate(this: *FilePoll, loop: *uws.Loop) void {
loop.num_polls += @as(i32, @intFromBool(!this.flags.contains(.has_incremented_poll_count)));
loop.active += @as(u32, @intFromBool(!this.flags.contains(.disable) and !this.flags.contains(.has_incremented_poll_count)));
this.flags.insert(.has_incremented_poll_count);
}
pub fn init(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, comptime Type: type, owner: *Type) *FilePoll {
return initWithOwner(vm, fd, flags, Owner.init(owner));
}
pub fn initWithOwner(vm: *JSC.VirtualMachine, fd: bun.FileDescriptor, flags: Flags.Struct, owner: Owner) *FilePoll {
var poll = vm.rareData().filePolls(vm).get();
poll.fd = @intCast(fd);
poll.flags = Flags.Set.init(flags);
poll.owner = owner;
poll.next_to_free = null;
if (KQueueGenerationNumber != u0) {
max_generation_number +%= 1;
poll.generation_number = max_generation_number;
}
return poll;
}
pub inline fn canRef(this: *const FilePoll) bool {
if (this.flags.contains(.disable))
return false;
return !this.flags.contains(.has_incremented_poll_count);
}
pub inline fn canUnref(this: *const FilePoll) bool {
return this.flags.contains(.has_incremented_poll_count);
}
/// Prevent a poll from keeping the process alive.
pub fn unref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (!this.canUnref())
return;
log("unref", .{});
this.deactivate(vm.event_loop_handle.?);
}
/// Allow a poll to keep the process alive.
pub fn ref(this: *FilePoll, vm: *JSC.VirtualMachine) void {
if (this.canRef())
return;
log("ref", .{});
this.activate(vm.event_loop_handle.?);
}
pub fn onTick(loop: *uws.Loop, tagged_pointer: ?*anyopaque) callconv(.C) void {
var tag = Pollable.from(tagged_pointer);
if (tag.tag() != @field(Pollable.Tag, "FilePoll"))
return;
var file_poll: *FilePoll = tag.as(FilePoll);
if (file_poll.flags.contains(.ignore_updates)) {
return;
}
if (comptime Environment.isMac)
onKQueueEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))])
else if (comptime Environment.isLinux)
onEpollEvent(file_poll, loop, &loop.ready_polls[@as(usize, @intCast(loop.current_ready_poll))]);
}
const Pollable = bun.TaggedPointerUnion(
.{
FilePoll,
Deactivated,
},
);
comptime {
@export(onTick, .{ .name = "Bun__internal_dispatch_ready_poll" });
}
const timeout = std.mem.zeroes(std.os.timespec);
const kevent = std.c.kevent;
const linux = std.os.linux;
pub fn register(this: *FilePoll, loop: *uws.Loop, flag: Flags, one_shot: bool) JSC.Maybe(void) {
return registerWithFd(this, loop, flag, one_shot, this.fd);
}
pub fn registerWithFd(this: *FilePoll, loop: *uws.Loop, flag: Flags, one_shot: bool, fd: u64) JSC.Maybe(void) {
const watcher_fd = loop.fd;
log("register: {s} ({d})", .{ @tagName(flag), fd });
std.debug.assert(fd != invalid_fd);
if (one_shot) {
this.flags.insert(.one_shot);
}
if (comptime Environment.isLinux) {
const one_shot_flag: u32 = if (!this.flags.contains(.one_shot)) 0 else linux.EPOLL.ONESHOT;
const flags: u32 = switch (flag) {
.process,
.readable,
=> linux.EPOLL.IN | linux.EPOLL.HUP | one_shot_flag,
.writable => linux.EPOLL.OUT | linux.EPOLL.HUP | linux.EPOLL.ERR | one_shot_flag,
else => unreachable,
};
var event = linux.epoll_event{ .events = flags, .data = .{ .u64 = @intFromPtr(Pollable.init(this).ptr()) } };
var op: u32 = if (this.isRegistered() or this.flags.contains(.needs_rearm)) linux.EPOLL.CTL_MOD else linux.EPOLL.CTL_ADD;
const ctl = linux.epoll_ctl(
watcher_fd,
op,
@intCast(fd),
&event,
);
this.flags.insert(.was_ever_registered);
if (JSC.Maybe(void).errnoSys(ctl, .epoll_ctl)) |errno| {
return errno;
}
} else if (comptime Environment.isMac) {
var changelist = std.mem.zeroes([2]std.os.system.kevent64_s);
const one_shot_flag: u16 = if (!this.flags.contains(.one_shot)) 0 else std.c.EV_ONESHOT;
changelist[0] = switch (flag) {
.readable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.writable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.process => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
.machport => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_ADD | one_shot_flag,
.ext = .{ this.generation_number, 0 },
},
else => unreachable,
};
// output events only include change errors
const KEVENT_FLAG_ERROR_EVENTS = 0x000002;
// The kevent() system call returns the number of events placed in
// the eventlist, up to the value given by nevents. If the time
// limit expires, then kevent() returns 0.
const rc = rc: {
while (true) {
const rc = std.os.system.kevent64(
watcher_fd,
&changelist,
1,
// The same array may be used for the changelist and eventlist.
&changelist,
// we set 0 here so that if we get an error on
// registration, it becomes errno
0,
KEVENT_FLAG_ERROR_EVENTS,
&timeout,
);
if (std.c.getErrno(rc) == .INTR) continue;
break :rc rc;
}
};
this.flags.insert(.was_ever_registered);
// If an error occurs while
// processing an element of the changelist and there is enough room
// in the eventlist, then the event will be placed in the eventlist
// with EV_ERROR set in flags and the system error in data.
if (changelist[0].flags == std.c.EV_ERROR and changelist[0].data != 0) {
return JSC.Maybe(void).errnoSys(changelist[0].data, .kevent).?;
// Otherwise, -1 will be returned, and errno will be set to
// indicate the error condition.
}
const errno = std.c.getErrno(rc);
if (errno != .SUCCESS) {
return JSC.Maybe(void){
.err = bun.sys.Error.fromCode(errno, .kqueue),
};
}
} else {
bun.todo(@src(), {});
}
if (this.canActivate())
this.activate(loop);
this.flags.insert(switch (flag) {
.readable => .poll_readable,
.process => if (comptime Environment.isLinux) .poll_readable else .poll_process,
.writable => .poll_writable,
.machport => .poll_machport,
else => unreachable,
});
this.flags.remove(.needs_rearm);
return JSC.Maybe(void).success;
}
const invalid_fd = bun.invalid_fd;
pub fn unregister(this: *FilePoll, loop: *uws.Loop, force_unregister: bool) JSC.Maybe(void) {
return this.unregisterWithFd(loop, this.fd, force_unregister);
}
pub fn unregisterWithFd(this: *FilePoll, loop: *uws.Loop, fd: bun.UFileDescriptor, force_unregister: bool) JSC.Maybe(void) {
if (!(this.flags.contains(.poll_readable) or this.flags.contains(.poll_writable) or this.flags.contains(.poll_process) or this.flags.contains(.poll_machport))) {
// no-op
return JSC.Maybe(void).success;
}
std.debug.assert(fd != invalid_fd);
const watcher_fd = loop.fd;
const flag: Flags = brk: {
if (this.flags.contains(.poll_readable))
break :brk .readable;
if (this.flags.contains(.poll_writable))
break :brk .writable;
if (this.flags.contains(.poll_process))
break :brk .process;
if (this.flags.contains(.poll_machport))
break :brk .machport;
return JSC.Maybe(void).success;
};
if (this.flags.contains(.needs_rearm) and !force_unregister) {
log("unregister: {s} ({d}) skipped due to needs_rearm", .{ @tagName(flag), fd });
this.flags.remove(.poll_process);
this.flags.remove(.poll_readable);
this.flags.remove(.poll_process);
this.flags.remove(.poll_machport);
return JSC.Maybe(void).success;
}
log("unregister: {s} ({d})", .{ @tagName(flag), fd });
if (comptime Environment.isLinux) {
const ctl = linux.epoll_ctl(
watcher_fd,
linux.EPOLL.CTL_DEL,
@intCast(fd),
null,
);
if (JSC.Maybe(void).errnoSys(ctl, .epoll_ctl)) |errno| {
return errno;
}
} else if (comptime Environment.isMac) {
var changelist = std.mem.zeroes([2]std.os.system.kevent64_s);
changelist[0] = switch (flag) {
.readable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_READ,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.machport => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_MACHPORT,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.writable => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_WRITE,
.data = 0,
.fflags = 0,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
.process => .{
.ident = @as(u64, @intCast(fd)),
.filter = std.os.system.EVFILT_PROC,
.data = 0,
.fflags = std.c.NOTE_EXIT,
.udata = @intFromPtr(Pollable.init(this).ptr()),
.flags = std.c.EV_DELETE,
.ext = .{ 0, 0 },
},
else => unreachable,
};
// output events only include change errors
const KEVENT_FLAG_ERROR_EVENTS = 0x000002;
// The kevent() system call returns the number of events placed in
// the eventlist, up to the value given by nevents. If the time
// limit expires, then kevent() returns 0.
const rc = std.os.system.kevent64(
watcher_fd,
&changelist,
1,
// The same array may be used for the changelist and eventlist.
&changelist,
1,
KEVENT_FLAG_ERROR_EVENTS,
&timeout,
);
// If an error occurs while
// processing an element of the changelist and there is enough room
// in the eventlist, then the event will be placed in the eventlist
// with EV_ERROR set in flags and the system error in data.
if (changelist[0].flags == std.c.EV_ERROR) {
return JSC.Maybe(void).errnoSys(changelist[0].data, .kevent).?;
// Otherwise, -1 will be returned, and errno will be set to
// indicate the error condition.
}
const errno = std.c.getErrno(rc);
switch (rc) {
std.math.minInt(@TypeOf(rc))...-1 => return JSC.Maybe(void).errnoSys(@intFromEnum(errno), .kevent).?,
else => {},
}
} else {
bun.todo(@src(), {});
}
this.flags.remove(.needs_rearm);
this.flags.remove(.one_shot);
// we don't support both right now
std.debug.assert(!(this.flags.contains(.poll_readable) and this.flags.contains(.poll_writable)));
this.flags.remove(.poll_readable);
this.flags.remove(.poll_writable);
this.flags.remove(.poll_process);
this.flags.remove(.poll_machport);
if (this.isActive())
this.deactivate(loop);
return JSC.Maybe(void).success;
}
};
pub const Strong = @import("./Strong.zig").Strong;
pub const BinaryType = enum {

View File

@@ -28,7 +28,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "webcore/config.h"
#include "ActiveDOMCallback.h"
#include "ScriptExecutionContext.h"

View File

@@ -1,9 +1,7 @@
#pragma once
#include "root.h"
#include "ZigGlobalObject.h"
#include "AsyncContextFrame.h"
#include "JavaScriptCore/InternalFieldTuple.h"
#include <JavaScriptCore/InternalFieldTuple.h>
using namespace JSC;
using namespace WebCore;
@@ -64,7 +62,7 @@ void AsyncContextFrame::visitChildrenImpl(JSCell* cell, Visitor& visitor)
DEFINE_VISIT_CHILDREN(AsyncContextFrame);
extern "C" EncodedJSValue AsyncContextFrame__withAsyncContextIfNeeded(JSGlobalObject* globalObject, EncodedJSValue callback)
extern "C" JSC::EncodedJSValue AsyncContextFrame__withAsyncContextIfNeeded(JSGlobalObject* globalObject, JSC::EncodedJSValue callback)
{
return JSValue::encode(AsyncContextFrame::withAsyncContextIfNeeded(globalObject, JSValue::decode(callback)));
}

View File

@@ -2,7 +2,7 @@
#include "root.h"
#include "BunClientData.h"
#include "JavaScriptCore/CallData.h"
#include <JavaScriptCore/CallData.h>
class AsyncContextFrame : public JSC::JSNonFinalObject {
public:

View File

@@ -1,51 +0,0 @@
// ----- THIS IS NOT WEBCORE ----
// It reuses the namespace.
// ----- THIS IS NOT WEBCORE ----
// Node.js buffer
#include "root.h"
#include "Buffer.h"
#include "JavaScriptCore/Uint8Array.h"
namespace WebCore {
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, JSC::JSUint8Array* array, size_t byteOffset, size_t length)
{
return adoptRef(*new Buffer(globalObject, array, byteOffset, length));
}
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, JSC::JSUint8Array* array)
{
return create(globalObject, array, 0, array->byteLength());
}
int32_t static write(WTF::StringView view, size_t offset, size_t length, BufferEncodingType encodingType)
{
}
Buffer::~Buffer()
{
}
Ref<Buffer> Buffer::createEmpty(JSC::JSGlobalObject* globalObject)
{
return adoptRef(*new Buffer(globalObject, nullptr, 0, 0));
}
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, UChar* ptr, size_t len, BufferEncodingType encoding)
{
}
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, LChar* ptr, size_t len, BufferEncodingType encoding)
{
}
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, WTF::StringView& str, BufferEncodingType encoding)
{
if (str.is8Bit()) {
}
}
Ref<Buffer> Buffer::create(JSC::JSGlobalObject* globalObject, WTF::String& str, BufferEncodingType encoding)
{
}
}

View File

@@ -1,50 +0,0 @@
#pragma once
// ----- THIS IS NOT WEBCORE ----
// It reuses the namespace.
// ----- THIS IS NOT WEBCORE ----
// Node.js buffer
#include "root.h"
#include "BufferEncodingType.h"
#include "JavaScriptCore/GenericTypedArrayView.h"
#include "JavaScriptCore/JSBase.h"
#include "headers-handwritten.h"
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromLength(JSC::JSGlobalObject* lexicalGlobalObject, int64_t length);
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, size_t length, void* ctx, JSTypedArrayBytesDeallocator bytesDeallocator);
extern "C" JSC::EncodedJSValue Bun__encoding__toString(const uint8_t* input, size_t len, JSC::JSGlobalObject* globalObject, Encoding encoding);
extern "C" JSC::EncodedJSValue Bun__encoding__toStringUTF8(const uint8_t* input, size_t len, JSC::JSGlobalObject* globalObject);
extern "C" bool Bun__Buffer_fill(ZigString*, void*, size_t, WebCore::BufferEncodingType);
namespace WebCore {
class Buffer final : public RefCounted<Buffer> {
public:
using Adaptor = JSC::JSUint8Array::Adaptor;
~Buffer();
static int32_t write(WTF::StringView view, size_t offset, size_t length, BufferEncodingType encodingType);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, JSC::JSUint8Array*, size_t byteOffset, size_t length);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, JSC::JSUint8Array*);
static Ref<Buffer> createEmpty(JSC::JSGlobalObject* globalObject);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, UChar* ptr, size_t len, BufferEncodingType encoding);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, LChar* ptr, size_t len, BufferEncodingType encoding);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, WTF::StringView&, BufferEncodingType encoding);
static Ref<Buffer> create(JSC::JSGlobalObject* globalObject, WTF::String&, BufferEncodingType encoding);
Buffer(JSC::JSGlobalObject* globalObject, JSC::JSUint8Array* array, size_t byteOffset,
size_t length)
: m_array(array)
{
}
JSC::JSUint8Array* m_array;
};
}

View File

@@ -4,21 +4,21 @@
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "JavaScriptCore/FastMallocAlignedMemoryAllocator.h"
#include "JavaScriptCore/HeapInlines.h"
#include "JavaScriptCore/IsoHeapCellType.h"
#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
// #include "JavaScriptCore/MarkingConstraint.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "JavaScriptCore/VM.h"
#include "wtf/MainThread.h"
#include <JavaScriptCore/FastMallocAlignedMemoryAllocator.h>
#include <JavaScriptCore/HeapInlines.h>
#include <JavaScriptCore/IsoHeapCellType.h>
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
// #include <JavaScriptCore/MarkingConstraint.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <JavaScriptCore/VM.h>
#include <wtf/MainThread.h>
#include "JSDOMConstructorBase.h"
#include "JSDOMBuiltinConstructorBase.h"
#include "BunGCOutputConstraint.h"
#include "WebCoreTypedArrayController.h"
#include "JavaScriptCore/JSCInlines.h"
#include <JavaScriptCore/JSCInlines.h>
#include "JSDOMWrapper.h"
#include <JavaScriptCore/DeferredWorkTimer.h>

View File

@@ -13,16 +13,15 @@ class DOMWrapperWorld;
#include "ExtendedDOMClientIsoSubspaces.h"
#include "ExtendedDOMIsoSubspaces.h"
#include "DOMIsoSubspaces.h"
// #include "DOMWrapperWorld.h"
#include "BunBuiltinNames.h"
// #include "WebCoreJSBuiltins.h"
// #include "WorkerThreadType.h"
#include "wtf/Function.h"
#include "wtf/HashSet.h"
#include "wtf/RefPtr.h"
#include "JavaScriptCore/WeakInlines.h"
#include "JavaScriptCore/IsoSubspacePerVM.h"
#include "wtf/StdLibExtras.h"
#include <wtf/Function.h>
#include <wtf/HashSet.h>
#include <wtf/RefPtr.h>
#include <JavaScriptCore/WeakInlines.h>
#include <JavaScriptCore/IsoSubspacePerVM.h>
#include <wtf/StdLibExtras.h>
#include "WebCoreJSBuiltins.h"
#include "JSCTaskScheduler.h"

View File

@@ -25,11 +25,11 @@
#include "config.h"
#include "JavaScriptCore/WeakInlines.h"
#include "JavaScriptCore/AbstractSlotVisitorInlines.h"
#include <JavaScriptCore/WeakInlines.h>
#include <JavaScriptCore/AbstractSlotVisitorInlines.h>
#include "JavaScriptCore/VM.h"
#include "JavaScriptCore/MarkingConstraint.h"
#include <JavaScriptCore/VM.h>
#include <JavaScriptCore/MarkingConstraint.h>
// namespace JSC {
@@ -134,10 +134,10 @@
#include "BunGCOutputConstraint.h"
#include "WebCoreJSClientData.h"
#include "JavaScriptCore/BlockDirectoryInlines.h"
#include "JavaScriptCore/HeapInlines.h"
#include "JavaScriptCore/MarkedBlockInlines.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include <JavaScriptCore/BlockDirectoryInlines.h>
#include <JavaScriptCore/HeapInlines.h>
#include <JavaScriptCore/MarkedBlockInlines.h>
#include <JavaScriptCore/SubspaceInlines.h>
namespace WebCore {

View File

@@ -8,7 +8,7 @@
#include "JSEventListener.h"
#include "JSEventTarget.h"
#include "JSWorker.h"
#include "JavaScriptCore/ObjectConstructor.h"
#include <JavaScriptCore/ObjectConstructor.h>
#include "JSFetchHeaders.h"
#include "JSURLSearchParams.h"

View File

@@ -5,9 +5,9 @@
#include "helpers.h"
#include "IDLTypes.h"
#include "DOMURL.h"
#include "JavaScriptCore/JSPromise.h"
#include "JavaScriptCore/JSBase.h"
#include "JavaScriptCore/BuiltinNames.h"
#include <JavaScriptCore/JSPromise.h>
#include <JavaScriptCore/JSBase.h>
#include <JavaScriptCore/BuiltinNames.h>
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include <JavaScriptCore/JSFunction.h>
@@ -20,7 +20,7 @@
#include "headers.h"
#include "BunObject.h"
#include "WebCoreJSBuiltins.h"
#include "JavaScriptCore/JSObject.h"
#include <JavaScriptCore/JSObject.h>
#include "DOMJITIDLConvert.h"
#include "DOMJITIDLType.h"
#include "DOMJITIDLTypeFilter.h"
@@ -46,7 +46,7 @@ static JSValue constructEnvObject(VM& vm, JSObject* object)
return jsCast<Zig::GlobalObject*>(object->globalObject())->processEnvObject();
}
static inline EncodedJSValue flattenArrayOfBuffersIntoArrayBuffer(JSGlobalObject* lexicalGlobalObject, JSValue arrayValue)
static inline JSC::EncodedJSValue flattenArrayOfBuffersIntoArrayBuffer(JSGlobalObject* lexicalGlobalObject, JSValue arrayValue)
{
auto& vm = lexicalGlobalObject->vm();
@@ -195,7 +195,7 @@ static JSValue constructPluginObject(VM& vm, JSObject* bunObject)
return pluginFunction;
}
extern "C" EncodedJSValue JSPasswordObject__create(JSGlobalObject*);
extern "C" JSC::EncodedJSValue JSPasswordObject__create(JSGlobalObject*);
static JSValue constructPasswordObject(VM& vm, JSObject* bunObject)
{
@@ -390,8 +390,8 @@ JSC_DEFINE_HOST_FUNCTION(functionBunSleep,
return JSC::JSValue::encode(promise);
}
extern "C" EncodedJSValue Bun__escapeHTML8(JSGlobalObject* globalObject, EncodedJSValue input, const LChar* ptr, size_t length);
extern "C" EncodedJSValue Bun__escapeHTML16(JSGlobalObject* globalObject, EncodedJSValue input, const UChar* ptr, size_t length);
extern "C" JSC::EncodedJSValue Bun__escapeHTML8(JSGlobalObject* globalObject, JSC::EncodedJSValue input, const LChar* ptr, size_t length);
extern "C" JSC::EncodedJSValue Bun__escapeHTML16(JSGlobalObject* globalObject, JSC::EncodedJSValue input, const UChar* ptr, size_t length);
// JSC_DEFINE_JIT_OPERATION(functionBunEscapeHTMLWithoutTypeCheck, JSC::EncodedJSValue, (JSC::JSGlobalObject * lexicalGlobalObject, JSObject* castedglobalObject, JSString* string))
// {
@@ -429,7 +429,7 @@ JSC_DEFINE_HOST_FUNCTION(functionBunEscapeHTML, (JSC::JSGlobalObject * lexicalGl
RELEASE_AND_RETURN(scope, JSValue::encode(string));
auto resolvedString = string->value(lexicalGlobalObject);
EncodedJSValue encodedInput = JSValue::encode(string);
JSC::EncodedJSValue encodedInput = JSValue::encode(string);
if (!resolvedString.is8Bit()) {
RELEASE_AND_RETURN(scope, Bun__escapeHTML16(lexicalGlobalObject, encodedInput, resolvedString.characters16(), length));
} else {

View File

@@ -1,359 +0,0 @@
// File generated via `make static-hash-table` / `make cpp`
static const struct CompactHashIndex bunObjectTableIndex[269] = {
{ 75, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 38, -1 },
{ -1, -1 },
{ 44, -1 },
{ -1, -1 },
{ -1, -1 },
{ 4, -1 },
{ -1, -1 },
{ 2, -1 },
{ 48, -1 },
{ 34, 261 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 71, -1 },
{ 79, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 60, -1 },
{ -1, -1 },
{ -1, -1 },
{ 11, 258 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 45, 264 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 67, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 59, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 47, 265 },
{ 32, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 70, -1 },
{ 65, -1 },
{ -1, -1 },
{ 14, -1 },
{ 23, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 43, -1 },
{ -1, -1 },
{ 52, -1 },
{ -1, -1 },
{ -1, -1 },
{ 37, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 64, -1 },
{ -1, -1 },
{ 20, 256 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 73, -1 },
{ -1, -1 },
{ 77, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 74, -1 },
{ 22, 259 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 53, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 40, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 29, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 63, -1 },
{ 35, 266 },
{ -1, -1 },
{ 33, -1 },
{ 54, -1 },
{ -1, -1 },
{ 26, -1 },
{ 15, -1 },
{ -1, -1 },
{ -1, -1 },
{ 6, -1 },
{ 10, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 18, -1 },
{ -1, -1 },
{ -1, -1 },
{ 0, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 5, -1 },
{ 16, -1 },
{ -1, -1 },
{ -1, -1 },
{ 24, -1 },
{ 1, -1 },
{ 31, 267 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 46, -1 },
{ -1, -1 },
{ -1, -1 },
{ 8, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 69, -1 },
{ -1, -1 },
{ 76, 268 },
{ -1, -1 },
{ 36, -1 },
{ -1, -1 },
{ -1, -1 },
{ 39, 260 },
{ -1, -1 },
{ -1, -1 },
{ 7, 262 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 66, -1 },
{ 3, -1 },
{ -1, -1 },
{ 61, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 28, -1 },
{ 19, 257 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 9, -1 },
{ -1, -1 },
{ -1, -1 },
{ 49, -1 },
{ 12, -1 },
{ -1, -1 },
{ 80, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 17, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 27, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 13, -1 },
{ -1, -1 },
{ -1, -1 },
{ 25, -1 },
{ -1, -1 },
{ -1, -1 },
{ 42, 263 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 21, -1 },
{ 30, -1 },
{ 41, -1 },
{ 50, -1 },
{ 51, -1 },
{ 55, -1 },
{ 56, -1 },
{ 57, -1 },
{ 58, -1 },
{ 62, -1 },
{ 68, -1 },
{ 72, -1 },
{ 78, -1 },
};
static const struct HashTableValue bunObjectTableValues[81] = {
{ "ArrayBufferSink"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_ArrayBufferSink } },
{ "CryptoHasher"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_CryptoHasher } },
{ "DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_mimalloc_dump, 1 } },
{ "FFI"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_FFI } },
{ "FileSystemRouter"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_FileSystemRouter } },
{ "MD4"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_MD4 } },
{ "MD5"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_MD5 } },
{ "SHA1"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA1 } },
{ "SHA224"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA224 } },
{ "SHA256"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA256 } },
{ "SHA384"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA384 } },
{ "SHA512"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA512 } },
{ "SHA512_256"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_SHA512_256 } },
{ "TOML"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_TOML } },
{ "Transpiler"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_Transpiler } },
{ "_Os"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback__Os, 1 } },
{ "_Path"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback__Path, 1 } },
{ "allocUnsafe"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_allocUnsafe, 1 } },
{ "argv"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_argv } },
{ "assetPrefix"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_assetPrefix } },
{ "build"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_build, 1 } },
{ "concatArrayBuffers"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionConcatTypedArrays, 1 } },
{ "connect"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_connect, 1 } },
{ "cwd"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_cwd } },
{ "deepEquals"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionBunDeepEquals, 2 } },
{ "deepMatch"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionBunDeepMatch, 2 } },
{ "deflateSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_deflateSync, 1 } },
{ "dns"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructDNSObject } },
{ "enableANSIColors"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_enableANSIColors } },
{ "env"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructEnvObject } },
{ "escapeHTML"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionBunEscapeHTML, 2 } },
{ "fetch"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, Bun__fetch, 1 } },
{ "file"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_file, 1 } },
{ "fileURLToPath"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionFileURLToPath, 1 } },
{ "fs"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_fs, 1 } },
{ "gc"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_gc, 1 } },
{ "generateHeapSnapshot"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_generateHeapSnapshot, 1 } },
{ "getImportedStyles"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_getImportedStyles, 1 } },
{ "gunzipSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_gunzipSync, 1 } },
{ "gzipSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_gzipSync, 1 } },
{ "hash"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_hash } },
{ "indexOfLine"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_indexOfLine, 1 } },
{ "inflateSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_inflateSync, 1 } },
{ "inspect"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_inspect } },
{ "isMainThread"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructIsMainThread } },
{ "jest"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_jest, 1 } },
{ "listen"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_listen, 1 } },
{ "main"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_main } },
{ "mmap"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_mmap, 1 } },
{ "nanoseconds"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionBunNanoseconds, 0 } },
{ "openInEditor"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_openInEditor, 1 } },
{ "origin"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_origin } },
{ "password"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPasswordObject } },
{ "pathToFileURL"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionPathToFileURL, 1 } },
{ "peek"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructBunPeekObject } },
{ "plugin"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructPluginObject } },
{ "readableStreamToArray"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToArrayCodeGenerator, 1 } },
{ "readableStreamToArrayBuffer"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToArrayBufferCodeGenerator, 1 } },
{ "readableStreamToBlob"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToBlobCodeGenerator, 1 } },
{ "readableStreamToFormData"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToFormDataCodeGenerator, 1 } },
{ "readableStreamToJSON"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToJSONCodeGenerator, 1 } },
{ "readableStreamToText"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, bunObjectReadableStreamToTextCodeGenerator, 1 } },
{ "registerMacro"_s, static_cast<unsigned>(PropertyAttribute::DontEnum|PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_registerMacro, 1 } },
{ "resolve"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_resolve, 1 } },
{ "resolveSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_resolveSync, 1 } },
{ "revision"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructBunRevision } },
{ "serve"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_serve, 1 } },
{ "sha"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_sha, 1 } },
{ "shrink"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_shrink, 1 } },
{ "sleep"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionBunSleep, 1 } },
{ "sleepSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_sleepSync, 1 } },
{ "spawn"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_spawn, 1 } },
{ "spawnSync"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_spawnSync, 1 } },
{ "stderr"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_stderr } },
{ "stdin"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_stdin } },
{ "stdout"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_stdout } },
{ "stringHashCode"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, functionHashCode, 1 } },
{ "unsafe"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, BunObject_getter_wrap_unsafe } },
{ "version"_s, static_cast<unsigned>(PropertyAttribute::ReadOnly|PropertyAttribute::DontDelete|PropertyAttribute::PropertyCallback), NoIntrinsic, { HashTableValue::LazyPropertyType, constructBunVersion } },
{ "which"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_which, 1 } },
{ "write"_s, static_cast<unsigned>(PropertyAttribute::DontDelete|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, BunObject_callback_write, 1 } },
};
static const struct HashTable bunObjectTable =
{ 81, 255, false, nullptr, bunObjectTableValues, bunObjectTableIndex };

View File

@@ -1,27 +1,27 @@
#include "BunPlugin.h"
#include "headers-handwritten.h"
#include "JavaScriptCore/CatchScope.h"
#include "JavaScriptCore/JSGlobalObject.h"
#include "JavaScriptCore/JSTypeInfo.h"
#include "JavaScriptCore/Structure.h"
#include <JavaScriptCore/CatchScope.h>
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSTypeInfo.h>
#include <JavaScriptCore/Structure.h>
#include "helpers.h"
#include "ZigGlobalObject.h"
#include "JavaScriptCore/JavaScript.h"
#include "JavaScriptCore/JSObjectInlines.h"
#include "wtf/text/WTFString.h"
#include "JavaScriptCore/JSCInlines.h"
#include "JavaScriptCore/StrongInlines.h"
#include <JavaScriptCore/JavaScript.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <wtf/text/WTFString.h>
#include <JavaScriptCore/JSCInlines.h>
#include "JavaScriptCore/ObjectConstructor.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "JavaScriptCore/RegExpObject.h"
#include "JavaScriptCore/JSPromise.h"
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <JavaScriptCore/RegExpObject.h>
#include <JavaScriptCore/JSMap.h>
#include <JavaScriptCore/JSPromise.h>
#include "BunClientData.h"
#include "isBuiltinModule.h"
#include "JavaScriptCore/RegularExpression.h"
#include "JavaScriptCore/JSMap.h"
#include "JavaScriptCore/JSMapInlines.h"
#include <JavaScriptCore/RegularExpression.h>
namespace Zig {
@@ -37,7 +37,7 @@ static bool isValidNamespaceString(String& namespaceString)
return namespaceRegex->match(namespaceString) > -1;
}
static EncodedJSValue jsFunctionAppendOnLoadPluginBody(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target, BunPlugin::Base& plugin, void* ctx, OnAppendPluginCallback callback)
static JSC::EncodedJSValue jsFunctionAppendOnLoadPluginBody(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target, BunPlugin::Base& plugin, void* ctx, OnAppendPluginCallback callback)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -147,7 +147,8 @@ static EncodedJSValue jsFunctionAppendVirtualModulePluginBody(JSC::JSGlobalObjec
}
global->requireMap()->remove(globalObject, moduleIdValue);
esmRegistry && esmRegistry->remove(globalObject, moduleIdValue);
if (esmRegistry)
esmRegistry->remove(globalObject, moduleIdValue);
// bool hasBeenRequired = global->requireMap()->has(globalObject, moduleIdValue);
// bool hasBeenImported = esmRegistry && esmRegistry->has(globalObject, moduleIdValue);
@@ -159,7 +160,7 @@ static EncodedJSValue jsFunctionAppendVirtualModulePluginBody(JSC::JSGlobalObjec
return JSValue::encode(jsUndefined());
}
static EncodedJSValue jsFunctionAppendOnResolvePluginBody(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target, BunPlugin::Base& plugin, void* ctx, OnAppendPluginCallback callback)
static JSC::EncodedJSValue jsFunctionAppendOnResolvePluginBody(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target, BunPlugin::Base& plugin, void* ctx, OnAppendPluginCallback callback)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -212,7 +213,7 @@ static EncodedJSValue jsFunctionAppendOnResolvePluginBody(JSC::JSGlobalObject* g
return JSValue::encode(jsUndefined());
}
static EncodedJSValue jsFunctionAppendOnResolvePluginGlobal(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
static JSC::EncodedJSValue jsFunctionAppendOnResolvePluginGlobal(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
{
Zig::GlobalObject* global = Zig::jsCast<Zig::GlobalObject*>(globalObject);
@@ -221,7 +222,7 @@ static EncodedJSValue jsFunctionAppendOnResolvePluginGlobal(JSC::JSGlobalObject*
return jsFunctionAppendOnResolvePluginBody(globalObject, callframe, target, plugins, global->bunVM(), callback);
}
static EncodedJSValue jsFunctionAppendOnLoadPluginGlobal(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
static JSC::EncodedJSValue jsFunctionAppendOnLoadPluginGlobal(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
{
Zig::GlobalObject* global = Zig::jsCast<Zig::GlobalObject*>(globalObject);
@@ -265,7 +266,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionAppendOnResolvePluginBrowser, (JSC::JSGlobalO
return jsFunctionAppendOnResolvePluginGlobal(globalObject, callframe, BunPluginTargetBrowser);
}
extern "C" EncodedJSValue jsFunctionBunPluginClear(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe)
extern "C" JSC::EncodedJSValue jsFunctionBunPluginClear(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe)
{
Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(globalObject);
global->onLoadPlugins.fileNamespace.clear();
@@ -278,7 +279,7 @@ extern "C" EncodedJSValue jsFunctionBunPluginClear(JSC::JSGlobalObject* globalOb
return JSValue::encode(jsUndefined());
}
extern "C" EncodedJSValue setupBunPlugin(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
extern "C" JSC::EncodedJSValue setupBunPlugin(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe, BunPluginTarget target)
{
JSC::VM& vm = globalObject->vm();
auto clientData = WebCore::clientData(vm);
@@ -365,7 +366,7 @@ extern "C" EncodedJSValue setupBunPlugin(JSC::JSGlobalObject* globalObject, JSC:
RELEASE_AND_RETURN(throwScope, JSValue::encode(jsUndefined()));
}
extern "C" EncodedJSValue jsFunctionBunPlugin(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe)
extern "C" JSC::EncodedJSValue jsFunctionBunPlugin(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callframe)
{
Zig::GlobalObject* global = reinterpret_cast<Zig::GlobalObject*>(globalObject);
return setupBunPlugin(globalObject, callframe, BunPluginTargetBun);

View File

@@ -2,8 +2,8 @@
#include "root.h"
#include "headers-handwritten.h"
#include "JavaScriptCore/JSGlobalObject.h"
#include "JavaScriptCore/Strong.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/Strong.h>
#include "helpers.h"
extern "C" JSC_DECLARE_HOST_FUNCTION(jsFunctionBunPlugin);

View File

@@ -1,10 +1,9 @@
#include "Process.h"
#include "JavaScriptCore/InternalFieldTuple.h"
#include "JavaScriptCore/JSMicrotask.h"
#include "JavaScriptCore/ObjectConstructor.h"
#include "JavaScriptCore/NumberPrototype.h"
#include "BunProcess.h"
#include <JavaScriptCore/InternalFieldTuple.h>
#include <JavaScriptCore/JSMicrotask.h>
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/NumberPrototype.h>
#include "node_api.h"
#include <dlfcn.h>
#include "ZigGlobalObject.h"
#include "headers.h"
#include "JSEnvironmentVariableMap.h"
@@ -16,9 +15,17 @@
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
#include <termios.h>
#ifndef WIN32
#include <errno.h>
#include <dlfcn.h>
#include <sys/ioctl.h>
#include <termios.h>
#else
#include <uv.h>
#include <io.h>
#include <fcntl.h>
#endif
#include "JSNextTickQueue.h"
#include "ProcessBindingUV.h"
#include "ProcessBindingNatives.h"
@@ -121,6 +128,32 @@ JSC_DEFINE_CUSTOM_SETTER(Process_defaultSetter,
static bool getWindowSize(int fd, size_t* width, size_t* height)
{
#if OS(WINDOWS)
CONSOLE_SCREEN_BUFFER_INFO csbi;
HANDLE handle = INVALID_HANDLE_VALUE;
switch (fd) {
case 0:
handle = GetStdHandle(STD_INPUT_HANDLE);
break;
case 1:
handle = GetStdHandle(STD_OUTPUT_HANDLE);
break;
case 2:
handle = GetStdHandle(STD_ERROR_HANDLE);
break;
default:
break;
}
if (handle == INVALID_HANDLE_VALUE)
return false;
if (!GetConsoleScreenBufferInfo(handle, &csbi))
return false;
*width = csbi.srWindow.Right - csbi.srWindow.Left + 1;
*height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
return true;
#else
struct winsize ws;
int err;
do
@@ -134,6 +167,7 @@ static bool getWindowSize(int fd, size_t* width, size_t* height)
*height = ws.ws_row;
return true;
#endif
}
JSC_DEFINE_HOST_FUNCTION(Process_functionInternalGetWindowSize,
@@ -203,13 +237,20 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
WTF::String filename = callFrame->uncheckedArgument(1).toWTFString(globalObject);
RETURN_IF_EXCEPTION(scope, {});
#if OS(WINDOWS)
CString utf8 = filename.utf8();
HMODULE handle = LoadLibraryA(utf8.data());
#else
CString utf8 = filename.utf8();
void* handle = dlopen(utf8.data(), RTLD_LAZY);
#endif
if (!handle) {
#if OS(WINDOWS)
WTF::String msg = makeString("LoadLibraryA failed with error code: "_s, GetLastError());
#else
WTF::String msg = WTF::String::fromUTF8(dlerror());
#endif
JSC::throwTypeError(globalObject, scope, msg);
return JSC::JSValue::encode(JSC::JSValue {});
}
@@ -230,13 +271,24 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
JSC::EncodedJSValue (*napi_register_module_v1)(JSC::JSGlobalObject* globalObject,
JSC::EncodedJSValue exports);
#if OS(WINDOWS)
#define dlsym GetProcAddress
#endif
napi_register_module_v1 = reinterpret_cast<JSC::EncodedJSValue (*)(JSC::JSGlobalObject*,
JSC::EncodedJSValue)>(
dlsym(handle, "napi_register_module_v1"));
#if OS(WINDOWS)
#undef dlsym
#endif
if (!napi_register_module_v1) {
#if OS(WINDOWS)
FreeLibrary(handle);
#else
dlclose(handle);
#endif
JSC::throwTypeError(globalObject, scope, "symbol 'napi_register_module_v1' not found in native module. Is this a Node API (napi) module?"_s);
return JSC::JSValue::encode(JSC::JSValue {});
}
@@ -247,6 +299,8 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionDlopen,
JSC_DEFINE_HOST_FUNCTION(Process_functionUmask,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
#if !OS(WINDOWS)
if (callFrame->argumentCount() == 0 || callFrame->argument(0).isUndefined()) {
mode_t currentMask = umask(0);
umask(currentMask);
@@ -279,6 +333,9 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionUmask,
}
return JSC::JSValue::encode(JSC::jsNumber(umask(newUmask)));
#else
return JSC::JSValue::encode(JSC::jsNumber(0));
#endif
}
extern "C" uint64_t Bun__readOriginTimer(void*);
@@ -439,7 +496,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionChdir,
return JSC::JSValue::encode(result);
}
#if !OS(WINDOWS)
static HashMap<String, int>* signalNameToNumberMap = nullptr;
static HashMap<int, String>* signalNumberToNameMap = nullptr;
@@ -657,14 +714,20 @@ static void onDidChangeListeners(EventEmitter& eventEmitter, const Identifier& e
}
}
}
#endif
void Process::emitSignalEvent(int signalNumber)
{
#if !OS(WINDOWS)
String signalName = signalNumberToNameMap->get(signalNumber);
Identifier signalNameIdentifier = Identifier::fromString(vm(), signalName);
MarkedArgumentBuffer args;
args.append(jsNumber(signalNumber));
wrapped().emitForBindings(signalNameIdentifier, args);
#else
UNUSED_PARAM(signalNumber);
#endif
}
Process::~Process()
@@ -782,7 +845,7 @@ static JSValue constructVersions(VM& vm, JSObject* processObject)
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(REPORTED_NODE_VERSION))));
object->putDirect(
vm, JSC::Identifier::fromString(vm, "bun"_s),
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(Bun__version + 1 /* prefix with v */))));
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(Bun__version + 1 /* remove "v" prefix */))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "webkit"_s),
JSC::JSValue(JSC::jsOwnedString(vm, makeAtomString(BUN_WEBKIT_VERSION))));
object->putDirect(vm, JSC::Identifier::fromString(vm, "boringssl"_s),
@@ -811,7 +874,11 @@ static JSValue constructVersions(VM& vm, JSObject* processObject)
JSC::JSValue(JSC::jsString(vm, makeString(Bun__versions_usockets))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "v8"_s), JSValue(JSC::jsString(vm, makeString("11.3.244.8-node.15"_s))), 0);
#if OS(WINDOWS)
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsString(vm, makeString(uv_version_string()))), 0);
#else
object->putDirect(vm, JSC::Identifier::fromString(vm, "uv"_s), JSValue(JSC::jsString(vm, makeString("1.46.0"_s))), 0);
#endif
object->putDirect(vm, JSC::Identifier::fromString(vm, "napi"_s), JSValue(JSC::jsString(vm, makeString("9"_s))), 0);
object->putDirect(vm, JSC::Identifier::fromString(vm, "modules"_s),
@@ -922,6 +989,10 @@ static JSValue constructStderr(VM& vm, JSObject* processObject)
return constructStdioWriteStream(globalObject, 2);
}
#if OS(WINDOWS)
#define STDIN_FILENO 0
#endif
static JSValue constructStdin(VM& vm, JSObject* processObject)
{
auto* globalObject = Bun__getDefaultGlobal();
@@ -973,7 +1044,11 @@ static JSValue constructPid(VM& vm, JSObject* processObject)
static JSValue constructPpid(VM& vm, JSObject* processObject)
{
#if OS(WINDOWS)
return jsUndefined();
#else
return jsNumber(getppid());
#endif
}
static JSValue constructArgv0(VM& vm, JSObject* processObject)
@@ -1002,13 +1077,9 @@ static JSValue constructArgv(VM& vm, JSObject* processObject)
static JSValue constructArch(VM& vm, JSObject* processObject)
{
#if defined(__x86_64__)
#if CPU(X86_64)
return JSC::jsString(vm, makeAtomString("x64"));
#elif defined(__i386__)
return JSC::jsString(vm, makeAtomString("x86"));
#elif defined(__arm__)
return JSC::jsString(vm, makeAtomString("arm"));
#elif defined(__aarch64__)
#elif CPU(ARM64)
return JSC::jsString(vm, makeAtomString("arm64"));
#else
#error "Unknown architecture"
@@ -1021,6 +1092,8 @@ static JSValue constructPlatform(VM& vm, JSObject* processObject)
return JSC::jsString(vm, makeAtomString("darwin"));
#elif defined(__linux__)
return JSC::jsString(vm, makeAtomString("linux"));
#elif OS(WINDOWS)
return JSC::jsString(vm, makeAtomString("win32"));
#else
#error "Unknown platform"
#endif
@@ -1052,6 +1125,28 @@ static JSValue constructEnv(VM& vm, JSObject* processObject)
return globalObject->processEnvObject();
}
#if OS(WINDOWS)
static int getuid()
{
return 0;
}
static int geteuid()
{
return 0;
}
static int getegid()
{
return 0;
}
static int getgid()
{
return 0;
}
#endif
JSC_DEFINE_HOST_FUNCTION(Process_functiongetuid, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
return JSValue::encode(jsNumber(getuid()));
@@ -1074,6 +1169,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functiongetgid, (JSGlobalObject * globalObject,
JSC_DEFINE_HOST_FUNCTION(Process_functiongetgroups, (JSGlobalObject * globalObject, CallFrame* callFrame))
{
#if !OS(WINDOWS)
auto& vm = globalObject->vm();
int ngroups = getgroups(0, nullptr);
auto throwScope = DECLARE_THROW_SCOPE(vm);
@@ -1100,6 +1196,9 @@ JSC_DEFINE_HOST_FUNCTION(Process_functiongetgroups, (JSGlobalObject * globalObje
groups->push(globalObject, jsNumber(egid));
return JSValue::encode(groups);
#else
return JSValue::encode(jsUndefined());
#endif
}
JSC_DEFINE_HOST_FUNCTION(Process_functionAssert, (JSGlobalObject * globalObject, CallFrame* callFrame))
@@ -1343,11 +1442,19 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionCpuUsage,
{
JSC::VM& vm = globalObject->vm();
auto throwScope = DECLARE_THROW_SCOPE(vm);
#if !OS(WINDOWS)
struct rusage rusage;
if (getrusage(RUSAGE_SELF, &rusage) != 0) {
throwSystemError(throwScope, globalObject, "Failed to get CPU usage"_s, "getrusage"_s, errno);
return JSValue::encode(jsUndefined());
}
#else
uv_rusage_t rusage;
if (uv_getrusage(&rusage) != 0) {
throwSystemError(throwScope, globalObject, "Failed to get CPU usage"_s, "uv_getrusage"_s, errno);
return JSValue::encode(jsUndefined());
}
#endif
auto* process = getProcessObject(globalObject, callFrame->thisValue());
@@ -1486,8 +1593,10 @@ int getRSS(size_t* rss)
err:
return EINVAL;
#elif OS(WINDOWS)
return uv_resident_set_memory(rss);
#else
#error "Unsupported platform"
#error "Unknown platform"
#endif
}
@@ -1559,15 +1668,15 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionOpenStdin, (JSGlobalObject * globalObje
}
auto throwScope = DECLARE_THROW_SCOPE(vm);
if (JSValue stdin = global->processObject()->getIfPropertyExists(globalObject, Identifier::fromString(vm, "stdin"_s))) {
if (JSValue stdinValue = global->processObject()->getIfPropertyExists(globalObject, Identifier::fromString(vm, "stdin"_s))) {
RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
if (!stdin.isObject()) {
if (!stdinValue.isObject()) {
throwTypeError(globalObject, throwScope, "stdin is not an object"_s);
return JSValue::encode(jsUndefined());
}
JSValue resumeValue = stdin.getObject()->getIfPropertyExists(globalObject, Identifier::fromString(vm, "resume"_s));
JSValue resumeValue = stdinValue.getObject()->getIfPropertyExists(globalObject, Identifier::fromString(vm, "resume"_s));
RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
if (!resumeValue.isUndefinedOrNull()) {
auto resumeFunction = jsDynamicCast<JSFunction*>(resumeValue);
@@ -1579,11 +1688,11 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionOpenStdin, (JSGlobalObject * globalObje
auto callData = getCallData(resumeFunction);
MarkedArgumentBuffer args;
JSC::call(globalObject, resumeFunction, callData, stdin, args);
JSC::call(globalObject, resumeFunction, callData, stdinValue, args);
RETURN_IF_EXCEPTION(throwScope, JSValue::encode(jsUndefined()));
}
RELEASE_AND_RETURN(throwScope, JSValue::encode(stdin));
RELEASE_AND_RETURN(throwScope, JSValue::encode(stdinValue));
}
RELEASE_AND_RETURN(throwScope, JSValue::encode(jsUndefined()));
@@ -1738,9 +1847,19 @@ JSC_DEFINE_CUSTOM_SETTER(setProcessDebugPort,
JSC_DEFINE_CUSTOM_GETTER(processTitle, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{
#if !OS(WINDOWS)
ZigString str;
Bun__Process__getTitle(globalObject, &str);
return JSValue::encode(Zig::toJSStringValue(str, globalObject));
#else
auto& vm = globalObject->vm();
char title[1024];
if (uv_get_process_title(title, sizeof(title)) != 0) {
return JSValue::encode(jsString(vm, String("bun"_s)));
}
return JSValue::encode(jsString(vm, WTF::String::fromUTF8(title)));
#endif
}
JSC_DEFINE_CUSTOM_SETTER(setProcessTitle,
@@ -1748,17 +1867,22 @@ JSC_DEFINE_CUSTOM_SETTER(setProcessTitle,
JSC::EncodedJSValue value, JSC::PropertyName))
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
JSC::JSObject* thisObject = JSC::jsDynamicCast<JSC::JSObject*>(JSValue::decode(thisValue));
JSC::JSString* jsString = JSC::jsDynamicCast<JSC::JSString*>(JSValue::decode(value));
if (!thisObject || !jsString) {
return false;
}
#if !OS(WINDOWS)
ZigString str = Zig::toZigString(jsString, globalObject);
Bun__Process__setTitle(globalObject, &str);
return true;
#else
WTF::String str = jsString->value(globalObject);
RETURN_IF_EXCEPTION(scope, false);
CString cstr = str.utf8();
return uv_set_process_title(cstr.data()) == 0;
#endif
}
JSC_DEFINE_HOST_FUNCTION(Process_functionCwd,
@@ -1786,7 +1910,12 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionReallyKill,
int signal = callFrame->argument(1).toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
#if !OS(WINDOWS)
int result = kill(pid, signal);
#else
int result = uv_kill(pid, signal);
#endif
if (result < 0) {
throwSystemError(scope, globalObject, "kill"_s, errno);
}
@@ -1806,7 +1935,7 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionKill,
}
JSC::JSValue signalValue = callFrame->argument(1);
#if !OS(WINDOWS)
int signal = SIGTERM;
if (signalValue.isNumber()) {
@@ -1829,6 +1958,21 @@ JSC_DEFINE_HOST_FUNCTION(Process_functionKill,
}
int result = kill(pid, signal);
#else
int signal = 1;
if (signalValue.isNumber()) {
signal = signalValue.toInt32(globalObject);
RETURN_IF_EXCEPTION(scope, {});
} else if (signalValue.isString()) {
throwTypeError(globalObject, scope, "TODO: implement this function with strings on Windows! Sorry!!"_s);
RETURN_IF_EXCEPTION(scope, {});
} else if (!signalValue.isUndefinedOrNull()) {
throwTypeError(globalObject, scope, "signal must be a string or number"_s);
return JSValue::encode(jsUndefined());
}
int result = uv_kill(pid, signal);
#endif
if (result < 0) {
throwSystemError(scope, globalObject, "kill"_s, errno);
@@ -1931,15 +2075,19 @@ extern "C" void Process__emitDisconnectEvent(Zig::GlobalObject* global)
_kill Process_functionReallyKill Function 2
@end
*/
#include "Process.lut.h"
const JSC::ClassInfo Process::s_info = { "Process"_s, &Base::s_info, &processObjectTable, nullptr,
CREATE_METHOD_TABLE(Process) };
#include "BunProcess.lut.h"
const JSC::ClassInfo Process::s_info
= { "Process"_s, &Base::s_info, &processObjectTable, nullptr,
CREATE_METHOD_TABLE(Process) };
void Process::finishCreation(JSC::VM& vm)
{
Base::finishCreation(vm);
#ifndef WIN32
wrapped().onDidChangeListener = &onDidChangeListeners;
#endif
m_cpuUsageStructure.initLater([](const JSC::LazyProperty<Process, JSC::Structure>::Initializer& init) {
init.set(constructCPUUsageStructure(init.vm, init.owner->globalObject()));

View File

@@ -1,9 +1,10 @@
#include "root.h"
#include "headers-handwritten.h"
#include "JavaScriptCore/JSCJSValueInlines.h"
#include <JavaScriptCore/JSCJSValueInlines.h>
#include "helpers.h"
#include "simdutf.h"
#include "wtf/Seconds.h"
#include <wtf/Seconds.h>
#include <wtf/text/ExternalStringImpl.h>
#include "GCDefferalContext.h"
#include <JavaScriptCore/JSONObject.h>
#include <wtf/text/AtomString.h>
@@ -266,7 +267,7 @@ extern "C" BunString BunString__createExternal(const char* bytes, size_t length,
return { BunStringTag::WTFStringImpl, { .wtf = &impl.leakRef() } };
}
extern "C" EncodedJSValue BunString__toJSON(
extern "C" JSC::EncodedJSValue BunString__toJSON(
JSC::JSGlobalObject* globalObject,
BunString* bunString)
{
@@ -279,7 +280,7 @@ extern "C" EncodedJSValue BunString__toJSON(
return JSC::JSValue::encode(result);
}
extern "C" EncodedJSValue BunString__createArray(
extern "C" JSC::EncodedJSValue BunString__createArray(
JSC::JSGlobalObject* globalObject,
const BunString* ptr, size_t length)
{

View File

@@ -32,26 +32,24 @@
#include "root.h"
#include "headers-handwritten.h"
#include "ZigGlobalObject.h"
#include "JavaScriptCore/JSSourceCode.h"
#include "JavaScriptCore/JSString.h"
#include "JavaScriptCore/JSValueInternal.h"
#include "JavaScriptCore/JSVirtualMachineInternal.h"
#include "JavaScriptCore/ObjectConstructor.h"
#include "JavaScriptCore/OptionsList.h"
#include "JavaScriptCore/ParserError.h"
#include "JavaScriptCore/ScriptExecutable.h"
#include "JavaScriptCore/SourceOrigin.h"
#include "JavaScriptCore/StackFrame.h"
#include "JavaScriptCore/StackVisitor.h"
#include <JavaScriptCore/JSSourceCode.h>
#include <JavaScriptCore/JSString.h>
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/OptionsList.h>
#include <JavaScriptCore/ParserError.h>
#include <JavaScriptCore/ScriptExecutable.h>
#include <JavaScriptCore/SourceOrigin.h>
#include <JavaScriptCore/StackFrame.h>
#include <JavaScriptCore/StackVisitor.h>
#include "BunClientData.h"
#include "JavaScriptCore/Identifier.h"
#include <JavaScriptCore/Identifier.h>
#include "ImportMetaObject.h"
#include "JavaScriptCore/TypedArrayInlines.h"
#include "JavaScriptCore/PropertyNameArray.h"
#include "JavaScriptCore/JSWeakMap.h"
#include "JavaScriptCore/JSWeakMapInlines.h"
#include "JavaScriptCore/JSWithScope.h"
#include <JavaScriptCore/TypedArrayInlines.h>
#include <JavaScriptCore/PropertyNameArray.h>
#include <JavaScriptCore/JSWeakMap.h>
#include <JavaScriptCore/JSWeakMapInlines.h>
#include <JavaScriptCore/JSWithScope.h>
#include <JavaScriptCore/DFGAbstractHeap.h>
#include <JavaScriptCore/Completion.h>
@@ -61,7 +59,7 @@
#include <JavaScriptCore/JSMapInlines.h>
#include <JavaScriptCore/GetterSetter.h>
#include "ZigSourceProvider.h"
#include "JavaScriptCore/FunctionPrototype.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include "CommonJSModuleRecord.h"
#include <JavaScriptCore/JSModuleNamespaceObject.h>
#include <JavaScriptCore/JSSourceCode.h>
@@ -322,7 +320,7 @@ JSC_DEFINE_CUSTOM_SETTER(setterPath,
return true;
}
extern "C" EncodedJSValue Resolver__propForRequireMainPaths(JSGlobalObject*);
extern "C" JSC::EncodedJSValue Resolver__propForRequireMainPaths(JSGlobalObject*);
JSC_DEFINE_CUSTOM_GETTER(getterPaths, (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, JSC::PropertyName))
{

View File

@@ -30,7 +30,7 @@
#include "root.h"
#include "ExceptionCode.h"
#include "wtf/text/WTFString.h"
#include <wtf/text/WTFString.h>
namespace WebCore {

View File

@@ -30,7 +30,7 @@
#include "config.h"
#include "DOMFormData.h"
#include "wtf/URLParser.h"
#include <wtf/URLParser.h>
namespace WebCore {

View File

@@ -32,7 +32,7 @@
// #include "PublicURLManager.h"
// #include "ResourceRequest.h"
#include "URLSearchParams.h"
// #include "wtf/MainThread.h"
// #include <wtf/MainThread.h>
namespace WebCore {

View File

@@ -30,8 +30,8 @@
#include "ExceptionOr.h"
#include "URLDecomposition.h"
#include "wtf/URL.h"
#include "wtf/WeakPtr.h"
#include <wtf/URL.h>
#include <wtf/WeakPtr.h>
namespace WebCore {

View File

@@ -2,7 +2,7 @@
#include "root.h"
#include "wtf/Forward.h"
#include <wtf/Forward.h>
namespace WebCore {

View File

@@ -26,7 +26,7 @@
#include "WebCoreJSClientData.h"
// #include "WindowProxy.h"
#include "ZigGlobalObject.h"
#include "wtf/MainThread.h"
#include <wtf/MainThread.h>
namespace WebCore {

View File

@@ -29,7 +29,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "root.h"
#include "ExceptionCode.h"
#include "wtf/text/WTFString.h"
#include <wtf/text/WTFString.h>
namespace WebCore {

View File

@@ -20,7 +20,7 @@
#include "root.h"
#include "wtf/EnumTraits.h"
#include <wtf/EnumTraits.h>
namespace WebCore {

View File

@@ -29,9 +29,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "root.h"
#include "Exception.h"
#include "wtf/CrossThreadCopier.h"
#include "wtf/Expected.h"
#include "wtf/StdLibExtras.h"
#include <wtf/CrossThreadCopier.h>
#include <wtf/Expected.h>
#include <wtf/StdLibExtras.h>
namespace WebCore {

View File

@@ -21,23 +21,23 @@
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include "JavaScriptCore/FunctionPrototype.h"
#include "JavaScriptCore/HeapAnalyzer.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/HeapAnalyzer.h>
#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
#include "JavaScriptCore/SlotVisitorMacros.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "wtf/GetPtr.h"
#include "wtf/PointerPreparations.h"
#include "wtf/URL.h"
#include "JavaScriptCore/BuiltinNames.h"
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include <wtf/URL.h>
#include <JavaScriptCore/BuiltinNames.h>
#include "JSBufferEncodingType.h"
#include "JavaScriptCore/JSBase.h"
#include <JavaScriptCore/JSBase.h>
#include "JSDOMURL.h"
#include "JavaScriptCore/JSNativeStdFunction.h"
#include "JavaScriptCore/GetterSetter.h"
#include <JavaScriptCore/JSNativeStdFunction.h>
#include <JavaScriptCore/GetterSetter.h>
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
@@ -47,7 +47,7 @@ namespace Zig {
using namespace JSC;
using namespace WebCore;
static EncodedJSValue functionRequireResolve(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame, const WTF::String& fromStr)
static JSC::EncodedJSValue functionRequireResolve(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame, const WTF::String& fromStr)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -148,7 +148,7 @@ JSC_DEFINE_HOST_FUNCTION(jsFunctionRequireResolve, (JSC::JSGlobalObject * global
return functionRequireResolve(globalObject, callFrame, fromStr);
}
extern "C" EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
extern "C" JSC::EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
@@ -236,7 +236,7 @@ extern "C" EncodedJSValue functionImportMeta__resolveSync(JSC::JSGlobalObject* g
return result;
}
extern "C" EncodedJSValue functionImportMeta__resolveSyncPrivate(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
extern "C" JSC::EncodedJSValue functionImportMeta__resolveSyncPrivate(JSC::JSGlobalObject* globalObject, JSC::CallFrame* callFrame)
{
JSC::VM& vm = globalObject->vm();
auto scope = DECLARE_THROW_SCOPE(globalObject->vm());
@@ -363,7 +363,7 @@ Zig::ImportMetaObject* ImportMetaObject::create(JSC::JSGlobalObject* jslobalObje
return Zig::ImportMetaObject::create(vm, globalObject, structure, view);
}
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_url, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName propertyName))
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_url, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
{
ImportMetaObject* thisObject = jsDynamicCast<ImportMetaObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))
@@ -371,7 +371,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_url, (JSGlobalObject * globalO
return JSValue::encode(thisObject->urlProperty.getInitializedOnMainThread(thisObject));
}
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_dir, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName propertyName))
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_dir, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
{
ImportMetaObject* thisObject = jsDynamicCast<ImportMetaObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))
@@ -379,7 +379,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_dir, (JSGlobalObject * globalO
return JSValue::encode(thisObject->dirProperty.getInitializedOnMainThread(thisObject));
}
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_file, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName propertyName))
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_file, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
{
ImportMetaObject* thisObject = jsDynamicCast<ImportMetaObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))
@@ -387,7 +387,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_file, (JSGlobalObject * global
return JSValue::encode(thisObject->fileProperty.getInitializedOnMainThread(thisObject));
}
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_path, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName propertyName))
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_path, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
{
ImportMetaObject* thisObject = jsDynamicCast<ImportMetaObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))
@@ -395,7 +395,7 @@ JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_path, (JSGlobalObject * global
return JSValue::encode(thisObject->pathProperty.getInitializedOnMainThread(thisObject));
}
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_require, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName propertyName))
JSC_DEFINE_CUSTOM_GETTER(jsImportMetaObjectGetter_require, (JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, PropertyName propertyName))
{
ImportMetaObject* thisObject = jsDynamicCast<ImportMetaObject*>(JSValue::decode(thisValue));
if (UNLIKELY(!thisObject))

View File

@@ -1,12 +1,12 @@
#include "InternalModuleRegistry.h"
#include "ZigGlobalObject.h"
#include "JavaScriptCore/BuiltinUtils.h"
#include "JavaScriptCore/JSFunction.h"
#include "JavaScriptCore/LazyProperty.h"
#include "JavaScriptCore/LazyPropertyInlines.h"
#include "JavaScriptCore/VMTrapsInlines.h"
#include "JavaScriptCore/JSModuleLoader.h"
#include <JavaScriptCore/BuiltinUtils.h>
#include <JavaScriptCore/JSFunction.h>
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
#include <JavaScriptCore/JSModuleLoader.h>
#include "InternalModuleRegistryConstants.h"
@@ -64,7 +64,6 @@ static void maybeAddCodeCoverage(JSC::VM& vm, const JSC::SourceCode& code)
return result;
#if BUN_DEBUG
#include "../../src/js/out/DebugPath.h"
#define ASSERT_INTERNAL_MODULE(result, moduleName) \
if (!result || !result.isCell() || !jsDynamicCast<JSObject*>(result)) { \
printf("Expected \"%s\" to export a JSObject. Bun is going to crash.", moduleName.utf8().data()); \
@@ -77,7 +76,7 @@ JSValue initializeInternalModuleFromDisk(
WTF::String fallback,
WTF::String urlString)
{
WTF::String file = makeString(BUN_DYNAMIC_JS_LOAD_PATH, "modules_dev/"_s, fileBase);
WTF::String file = makeString(BUN_DYNAMIC_JS_LOAD_PATH, "/"_s, fileBase);
if (auto contents = WTF::FileSystemImpl::readEntireFile(file)) {
auto string = WTF::String::fromUTF8(contents.value());
INTERNAL_MODULE_REGISTRY_GENERATE_(globalObject, vm, string, moduleName, urlString);
@@ -149,7 +148,7 @@ JSValue InternalModuleRegistry::requireId(JSGlobalObject* globalObject, VM& vm,
return value;
}
#include "../../../src/js/out/InternalModuleRegistry+createInternalModuleById.h"
#include "InternalModuleRegistry+createInternalModuleById.h"
// This is called like @getInternalField(@internalModuleRegistry, 1) ?? @createInternalModuleById(1)
// so we want to write it to the internal field when loaded.

View File

@@ -1,9 +1,9 @@
#pragma once
#include "root.h"
#include "JavaScriptCore/JSInternalFieldObjectImpl.h"
#include "JavaScriptCore/JSInternalFieldObjectImplInlines.h"
#include <JavaScriptCore/JSInternalFieldObjectImpl.h>
#include <JavaScriptCore/JSInternalFieldObjectImplInlines.h>
#include "BunClientData.h"
#include "../../../src/js/out/InternalModuleRegistry+numberOfModules.h"
#include "InternalModuleRegistry+numberOfModules.h"
namespace Bun {
using namespace JSC;
@@ -28,7 +28,7 @@ public:
}
enum Field : uint8_t {
#include "../../../src/js/out/InternalModuleRegistry+enum.h"
#include "InternalModuleRegistry+enum.h"
};
const WriteBarrier<Unknown>& internalField(Field field) const { return Base::internalField(static_cast<uint32_t>(field)); }

View File

@@ -19,8 +19,8 @@
#include "JSDOMWrapperCache.h"
#include "ScriptExecutionContext.h"
#include "WebCoreJSClientData.h"
#include "JavaScriptCore/FunctionPrototype.h"
#include "JavaScriptCore/HeapAnalyzer.h"
#include <JavaScriptCore/FunctionPrototype.h>
#include <JavaScriptCore/HeapAnalyzer.h>
#include <JavaScriptCore/JSFunction.h>
#include <JavaScriptCore/InternalFunction.h>
@@ -28,22 +28,26 @@
#include <JavaScriptCore/LazyClassStructureInlines.h>
#include <JavaScriptCore/FunctionPrototype.h>
#include "JavaScriptCore/JSDestructibleObjectHeapCellType.h"
#include "JavaScriptCore/SlotVisitorMacros.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "wtf/GetPtr.h"
#include "wtf/PointerPreparations.h"
#include "wtf/URL.h"
#include "wtf/text/WTFString.h"
#include "JavaScriptCore/BuiltinNames.h"
#include <JavaScriptCore/JSDestructibleObjectHeapCellType.h>
#include <JavaScriptCore/SlotVisitorMacros.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <wtf/GetPtr.h>
#include <wtf/PointerPreparations.h>
#include <wtf/URL.h>
#include <wtf/text/WTFString.h>
#include <JavaScriptCore/BuiltinNames.h>
#include "JSBufferEncodingType.h"
#include "JavaScriptCore/JSBase.h"
#include <JavaScriptCore/JSBase.h>
#if ENABLE(MEDIA_SOURCE)
#include "BufferMediaSource.h"
#include "JSMediaSource.h"
#endif
#ifdef WIN32
#include "musl-memmem.h"
#endif
#include <JavaScriptCore/DOMJITAbstractHeap.h>
#include "DOMJITIDLConvert.h"
#include "DOMJITIDLType.h"
@@ -51,8 +55,8 @@
#include "DOMJITHelpers.h"
#include <JavaScriptCore/DFGAbstractHeap.h>
// #include "JavaScriptCore/JSTypedArrayViewPrototype.h"
#include "JavaScriptCore/JSArrayBufferViewInlines.h"
// #include <JavaScriptCore/JSTypedArrayViewPrototype.h>
#include <JavaScriptCore/JSArrayBufferViewInlines.h>
using namespace JSC;
using namespace WebCore;
@@ -218,7 +222,7 @@ JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalO
namespace WebCore {
using namespace JSC;
static inline EncodedJSValue writeToBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSArrayBufferView* castedThis, JSString* str, uint32_t offset, uint32_t length, BufferEncodingType encoding)
static inline JSC::EncodedJSValue writeToBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSArrayBufferView* castedThis, JSString* str, uint32_t offset, uint32_t length, BufferEncodingType encoding)
{
if (UNLIKELY(str->length() == 0))
return JSC::JSValue::encode(JSC::jsNumber(0));
@@ -243,6 +247,9 @@ static inline EncodedJSValue writeToBuffer(JSC::JSGlobalObject* lexicalGlobalObj
}
break;
}
default: {
break;
}
}
return JSC::JSValue::encode(JSC::jsNumber(written));
@@ -271,7 +278,7 @@ static inline JSC::JSUint8Array* JSBuffer__bufferFromLengthAsArray(JSC::JSGlobal
RELEASE_AND_RETURN(throwScope, uint8Array);
}
extern "C" EncodedJSValue JSBuffer__bufferFromLength(JSC::JSGlobalObject* lexicalGlobalObject, int64_t length)
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromLength(JSC::JSGlobalObject* lexicalGlobalObject, int64_t length)
{
return JSC::JSValue::encode(JSBuffer__bufferFromLengthAsArray(lexicalGlobalObject, length));
}
@@ -310,18 +317,18 @@ EncodedJSValue JSBuffer__bufferFromPointerAndLength(JSC::JSGlobalObject* lexical
}
// new Buffer()
static inline EncodedJSValue constructBufferEmpty(JSGlobalObject* lexicalGlobalObject)
static inline JSC::EncodedJSValue constructBufferEmpty(JSGlobalObject* lexicalGlobalObject)
{
return JSBuffer__bufferFromLength(lexicalGlobalObject, 0);
}
// new Buffer(size)
static inline EncodedJSValue constructBufferFromLength(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
static inline JSC::EncodedJSValue constructBufferFromLength(JSGlobalObject* lexicalGlobalObject, CallFrame* callFrame)
{
return jsBufferConstructorFunction_allocUnsafeBody(lexicalGlobalObject, callFrame);
}
static EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject, JSString* str, WebCore::BufferEncodingType encoding)
static JSC::EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject, JSString* str, WebCore::BufferEncodingType encoding)
{
auto& vm = JSC::getVM(lexicalGlobalObject);
auto scope = DECLARE_THROW_SCOPE(vm);
@@ -345,6 +352,9 @@ static EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject,
result = JSBuffer__bufferFromPointerAndLength(lexicalGlobalObject, view.characters8(), view.length());
break;
}
default: {
break;
}
}
} else {
switch (encoding) {
@@ -364,6 +374,9 @@ static EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject,
result = JSBuffer__bufferFromPointerAndLength(lexicalGlobalObject, reinterpret_cast<const unsigned char*>(view.characters16()), view.length() * 2);
break;
}
default: {
break;
}
}
}
@@ -583,6 +596,9 @@ static inline JSC::EncodedJSValue jsBufferByteLengthFromStringAndEncoding(JSC::J
}
break;
}
default: {
break;
}
}
RELEASE_AND_RETURN(scope, JSC::JSValue::encode(JSC::jsNumber(written)));

View File

@@ -23,12 +23,18 @@
#include "root.h"
#include <JavaScriptCore/JSGlobalObject.h>
#include "wtf/NeverDestroyed.h"
#include <wtf/NeverDestroyed.h>
#include "BufferEncodingType.h"
#include "Buffer.h"
#include "headers-handwritten.h"
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromLength(JSC::JSGlobalObject* lexicalGlobalObject, int64_t length);
extern "C" JSC::EncodedJSValue JSBuffer__bufferFromPointerAndLengthAndDeinit(JSC::JSGlobalObject* lexicalGlobalObject, char* ptr, size_t length, void* ctx, JSTypedArrayBytesDeallocator bytesDeallocator);
extern "C" JSC::EncodedJSValue Bun__encoding__toString(const uint8_t* input, size_t len, JSC::JSGlobalObject* globalObject, Encoding encoding);
extern "C" JSC::EncodedJSValue Bun__encoding__toStringUTF8(const uint8_t* input, size_t len, JSC::JSGlobalObject* globalObject);
extern "C" bool Bun__Buffer_fill(ZigString*, void*, size_t, WebCore::BufferEncodingType);
extern "C" bool JSBuffer__isBuffer(JSC::JSGlobalObject*, JSC::EncodedJSValue);
void toBuffer(JSC::JSGlobalObject* lexicalGlobalObject, JSC::JSUint8Array* uint8Array);
JSC::JSValue makeBuffer(JSC::JSGlobalObject* lexicalGlobalObject, unsigned int byteLength);
JSC::JSValue makeBufferUnsafe(JSC::JSGlobalObject* lexicalGlobalObject, unsigned int byteLength);

View File

@@ -1,52 +0,0 @@
// File generated via `make static-hash-table` / `make cpp`
static const struct CompactHashIndex jsBufferConstructorTableIndex[33] = {
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 1, 32 },
{ 0, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 8, -1 },
{ 3, -1 },
{ -1, -1 },
{ 5, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 9, -1 },
{ -1, -1 },
{ 4, -1 },
{ -1, -1 },
{ 6, -1 },
{ -1, -1 },
{ -1, -1 },
{ -1, -1 },
{ 2, -1 },
{ -1, -1 },
{ 7, -1 },
};
static const struct HashTableValue jsBufferConstructorTableValues[10] = {
{ "alloc"_s, static_cast<unsigned>(PropertyAttribute::Constructable|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_alloc, 1 } },
{ "allocUnsafe"_s, static_cast<unsigned>(PropertyAttribute::Constructable|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_allocUnsafe, 1 } },
{ "allocUnsafeSlow"_s, static_cast<unsigned>(PropertyAttribute::Constructable|PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_allocUnsafeSlow, 1 } },
{ "byteLength"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_byteLength, 2 } },
{ "compare"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_compare, 2 } },
{ "concat"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_concat, 2 } },
{ "from"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferConstructorFromCodeGenerator, 1 } },
{ "isBuffer"_s, ((static_cast<unsigned>(PropertyAttribute::Builtin|PropertyAttribute::Function)) & ~PropertyAttribute::Function) | PropertyAttribute::Builtin, NoIntrinsic, { HashTableValue::BuiltinGeneratorType, jsBufferConstructorIsBufferCodeGenerator, 1 } },
{ "toBuffer"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_toBuffer, 1 } },
{ "isEncoding"_s, static_cast<unsigned>(PropertyAttribute::Function), NoIntrinsic, { HashTableValue::NativeFunctionType, jsBufferConstructorFunction_isEncoding, 1 } },
};
static const struct HashTable jsBufferConstructorTable =
{ 10, 31, false, nullptr, jsBufferConstructorTableValues, jsBufferConstructorTableIndex };

View File

@@ -18,8 +18,6 @@
Boston, MA 02110-1301, USA.
*/
#pragma once
#include "config.h"
#include "JSBufferEncodingType.h"

View File

@@ -1,7 +1,7 @@
#include "JSBufferList.h"
#include "JSBuffer.h"
#include "JavaScriptCore/Lookup.h"
#include "JavaScriptCore/ObjectConstructor.h"
#include <JavaScriptCore/Lookup.h>
#include <JavaScriptCore/ObjectConstructor.h>
#include "ZigGlobalObject.h"
#include "JSDOMOperation.h"
#include "headers.h"
@@ -346,50 +346,49 @@ static inline JSC::EncodedJSValue jsBufferListPrototypeFunction_consumeBody(JSC:
RELEASE_AND_RETURN(throwScope, JSC::JSValue::encode(castedThis->consume(vm, lexicalGlobalObject, n, hasString)));
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_push);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_push,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_push,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_pushBody>(*globalObject, *callFrame, "push");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_unshift);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_unshift,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_unshift,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_unshiftBody>(*globalObject, *callFrame, "unshift");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_shift);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_shift,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_shift,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_shiftBody>(*globalObject, *callFrame, "shift");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_clear);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_clear,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_clear,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_clearBody>(*globalObject, *callFrame, "clear");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_first);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_first,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_first,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_firstBody>(*globalObject, *callFrame, "first");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_concat);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_concat,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_concat,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_concatBody>(*globalObject, *callFrame, "concat");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_join);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_join,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_join,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_joinBody>(*globalObject, *callFrame, "join");
}
static JSC_DECLARE_HOST_FUNCTION(jsBufferListPrototypeFunction_consume);
static JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_consume,
JSC_DEFINE_HOST_FUNCTION(jsBufferListPrototypeFunction_consume,
(JSC::JSGlobalObject * globalObject, JSC::CallFrame* callFrame))
{
return IDLOperation<JSBufferList>::call<jsBufferListPrototypeFunction_consumeBody>(*globalObject, *callFrame, "consume");

View File

@@ -1,7 +1,7 @@
#pragma once
#include "root.h"
#include "wtf/Deque.h"
#include <wtf/Deque.h>
namespace WebCore {
using namespace JSC;
@@ -49,12 +49,12 @@ public:
inline size_t length() { return m_deque.size(); }
void push(JSC::VM& vm, JSC::JSValue v)
{
m_deque.append(WriteBarrier<Unknown>());
m_deque.append(WriteBarrier<JSC::Unknown>());
m_deque.last().set(vm, this, v);
}
void unshift(JSC::VM& vm, JSC::JSValue v)
{
m_deque.prepend(WriteBarrier<Unknown>());
m_deque.prepend(WriteBarrier<JSC::Unknown>());
m_deque.first().set(vm, this, v);
}
JSC::JSValue shift()
@@ -83,7 +83,7 @@ public:
JSC::JSValue _getString(JSC::VM&, JSC::JSGlobalObject*, size_t);
private:
Deque<WriteBarrier<Unknown>> m_deque;
Deque<WriteBarrier<JSC::Unknown>> m_deque;
};
class JSBufferListPrototype : public JSC::JSNonFinalObject {

View File

@@ -1,24 +1,24 @@
#include "JSBundlerPlugin.h"
#include "headers-handwritten.h"
#include "JavaScriptCore/CatchScope.h"
#include "JavaScriptCore/JSGlobalObject.h"
#include "JavaScriptCore/JSTypeInfo.h"
#include "JavaScriptCore/Structure.h"
#include <JavaScriptCore/CatchScope.h>
#include <JavaScriptCore/JSGlobalObject.h>
#include <JavaScriptCore/JSTypeInfo.h>
#include <JavaScriptCore/Structure.h>
#include "helpers.h"
#include "ZigGlobalObject.h"
#include "JavaScriptCore/JavaScript.h"
#include "JavaScriptCore/JSObjectInlines.h"
#include "wtf/text/WTFString.h"
#include "JavaScriptCore/JSCInlines.h"
#include <JavaScriptCore/JavaScript.h>
#include <JavaScriptCore/JSObjectInlines.h>
#include <wtf/text/WTFString.h>
#include <JavaScriptCore/JSCInlines.h>
#include "JavaScriptCore/ObjectConstructor.h"
#include "JavaScriptCore/SubspaceInlines.h"
#include "JavaScriptCore/RegExpObject.h"
#include "JavaScriptCore/JSPromise.h"
#include <JavaScriptCore/ObjectConstructor.h>
#include <JavaScriptCore/SubspaceInlines.h>
#include <JavaScriptCore/RegExpObject.h>
#include <JavaScriptCore/JSPromise.h>
#include "BunClientData.h"
#include "ModuleLoader.h"
#include "JavaScriptCore/RegularExpression.h"
#include <JavaScriptCore/RegularExpression.h>
#include <JavaScriptCore/LazyProperty.h>
#include <JavaScriptCore/LazyPropertyInlines.h>
#include <JavaScriptCore/VMTrapsInlines.h>
@@ -385,10 +385,10 @@ extern "C" Bun::JSBundlerPlugin* JSBundlerPlugin__create(Zig::GlobalObject* glob
target);
}
extern "C" EncodedJSValue JSBundlerPlugin__runSetupFunction(
extern "C" JSC::EncodedJSValue JSBundlerPlugin__runSetupFunction(
Bun::JSBundlerPlugin* plugin,
EncodedJSValue encodedSetupFunction,
EncodedJSValue encodedConfig)
JSC::EncodedJSValue encodedSetupFunction,
JSC::EncodedJSValue encodedConfig)
{
auto& vm = plugin->vm();
auto scope = DECLARE_CATCH_SCOPE(vm);

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