Bun

建置 Windows

此文件說明 Windows 的建置程序。如果您遇到問題,請加入我們的 Discord 中的 #windows 頻道 以尋求協助。

強烈建議使用 PowerShell 7 (pwsh.exe),而不是預設的 powershell.exe

先決條件

啟用腳本

預設情況下,會封鎖執行未驗證的腳本。

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted

系統相依性

  • Bun 1.1 或更新版本。我們使用 Bun 來執行其自己的程式碼產生器。
irm bun.sh/install.ps1 | iex
  • Visual Studio,並具有「使用 C++ 進行桌面開發」的工作負載。
    • 如果尚未安裝,請從此安裝程式安裝 Git 和 CMake。

在 Visual Studio 之後,您需要以下項目

  • LLVM 16
  • Go
  • Rust
  • NASM
  • Perl
  • Ruby
  • Node.js

Zig 編譯器會在建置過程中自動下載、安裝和更新。

可以使用 Scoop 輕鬆安裝這些剩餘的工具

irm https://get.scoop.sh | iex
scoop install nodejs-lts go rust nasm ruby perl
# scoop seems to be buggy if you install llvm and the rest at the same time
scoop llvm@16.0.6

如果您打算在本地建置 WebKit(選用),您應該安裝這些套件

scoop install make cygwin python

從這裡開始,預期您會使用 PowerShell Terminal,其中包含 .\scripts\env.ps1 原始碼。此指令碼可在 Bun 存放庫中取得,並可透過執行它來載入

.\scripts\env.ps1

要驗證,您可以檢查 MSVC 專用命令列,例如 mt.exe

Get-Command mt

不建議將 ninja / cmake 安裝到您的全域路徑,因為您可能會遇到在未提供 .\scripts\env.ps1 原始碼的情況下嘗試建置 bun 的情況。

建置

bun install
.\scripts\env.ps1
.\scripts\update-submodules.ps1 # this syncs git submodule state
.\scripts\all-dependencies.ps1 # this builds all dependencies
.\scripts\make-old-js.ps1 # runs some old code generators

# Configure build environment
cmake -Bbuild -GNinja -DCMAKE_BUILD_TYPE=Debug

# Build bun
ninja -Cbuild

如果成功,您應該在 build 資料夾中有一個 bun-debug.exe

.\build\bun-debug.exe --revision

您應該將其新增到 $Env:PATH。最簡單的方法是開啟開始功能表,輸入「路徑」,然後導覽環境變數功能表,將 C:\.....\bun\build 新增到使用者環境變數 PATH。然後您應該重新啟動您的編輯器(如果它仍然沒有更新,請登出並重新登入)。

額外路徑

  • WebKit 已解壓縮到 build/bun-webkit
  • Zig 已解壓縮到 .cache/zig/zig.exe

測試

您可以使用 bun test 或使用包裝器指令碼 packages\bun-internal-test 來執行測試套件。內部測試套件是一個包裝器 cli,用於在 bun.exe 的個別執行個體中執行每個測試檔案,以防止測試執行器中的崩潰停止整個套件。

# Setup
bun i --cwd packages\bun-internal-test

# Run the entire test suite with reporter
# the package.json script "test" uses "build/bun-debug.exe" by default
bun run test

# Run an individual test file:
bun-debug test node\fs
bun-debug test "C:\bun\test\js\bun\resolve\import-meta.test.js"

疑難排解

.rc 檔案無法建置

llvm-rc.exe 很奇怪。不要使用它。使用 rc.exe,為此,請確保您在 Visual Studio dev 終端機中,檢查 rc /? 以確保它是 Microsoft Resource Compiler

無法寫入輸出「bun-debug.exe」:存取遭拒

如果 bun-debug.exe 已經開啟,您無法覆寫它。您可能有正在執行的執行個體,可能在 vscode 除錯器中?