本文档描述了 Windows 的构建过程。如果遇到问题,请加入 我们 Discord 上的 #contributing 频道 以寻求帮助。
强烈建议使用 PowerShell 7 (pwsh.exe) 而不是默认的 powershell.exe。
先决条件
启用脚本
默认情况下,运行未经验证的脚本会被阻止。
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted系统依赖项
Bun v1.1 或更高版本。我们使用 Bun 运行其自身的代码生成器。
irm bun.com/install.ps1 | iexVisual Studio,并安装“使用 C++ 的桌面开发”工作负载。安装时,请确保也安装 Git,如果尚未安装 Git for Windows。
Visual Studio 可以通过向导图形化安装,也可以通过 WinGet 安装
winget install "Visual Studio Community 2022" --override "--add Microsoft.VisualStudio.Workload.NativeDesktop Microsoft.VisualStudio.Component.Git " -s msstore安装 Visual Studio 后,您需要以下组件
- LLVM 19.1.7
- Go
- Rust
- NASM
- Perl
- Ruby
- Node.js
- Ccache
注意 – Zig 编译器将由构建过程自动下载、安装和更新。
Scoop 可以轻松安装这些剩余的工具。
irm https://get.scoop.sh | iexscoop install nodejs-lts go rust nasm ruby perl ccache# scoop seems to be buggy if you install llvm and the rest at the same timescoop install llvm@19.1.7请不要使用 WinGet/其他包管理器安装这些工具,因为您很可能会安装 Strawberry Perl 而不是更精简的 Perl 安装。Strawberry Perl 包含许多其他实用程序,它们会安装到 $Env:PATH 中,这将与 MSVC 冲突并破坏构建。
如果您打算在本地构建 WebKit(可选),您应该安装这些包
scoop install make cygwin python从现在开始,您需要使用已源化 .\scripts\vs-shell.ps1 的 PowerShell 终端。此脚本位于 Bun 仓库中,可以通过执行它来加载
.\scripts\vs-shell.ps1为了验证,您可以检查仅 MSVC 的命令行工具,例如 mt.exe
Get-Command mt不建议将 ninja / cmake 安装到您的全局路径中,因为您可能会遇到在未源化 `.\scripts\vs-shell.ps1` 的情况下尝试构建 bun 的情况。
构建
bun run build
# after the initial `bun run build` you can use the following to buildninja -Cbuild/debug如果成功,您应该在 build/debug 文件夹中找到 bun-debug.exe。
.\build\debug\bun-debug.exe --revision您应该将其添加到 $Env:PATH。最简单的方法是打开开始菜单,输入“Path”,然后导航到环境变量菜单,将 C:\.....\bun\build\debug 添加到用户环境变量 PATH 中。然后您应该重新启动您的编辑器(如果它仍然没有更新,请注销并重新登录)。
额外路径
- WebKit 被提取到
build/debug/cache/webkit/ - Zig 被提取到
build/debug/cache/zig/bin/zig.exe
测试
您可以使用 bun test <path> 或包装脚本 bun node:test <path> 运行测试套件。bun node:test 命令在 bun.exe 的单独实例中运行每个测试文件,以防止测试运行程序中的崩溃导致整个套件停止。
# Setupbun i --cwd packages\bun-internal-test
# Run the entire test suite with reporter
# the package.json script "test" uses "build/debug/bun-debug.exe" by defaultbun run test
# Run an individual test file:bun-debug test node\fsbun-debug test "C:\bun\test\js\bun\resolve\import-meta.test.js"故障排除
.rc 文件构建失败
llvm-rc.exe 很奇怪。不要使用它。使用 rc.exe,为此请确保您在 Visual Studio 开发终端中,检查 rc /? 以确保它是 Microsoft Resource Compiler。
写入输出 'bun-debug.exe' 失败:权限被拒绝
如果 bun-debug.exe 已经打开,您将无法覆盖它。您可能有一个正在运行的实例,也许在 vscode 调试器中?