在本页
从源代码构建 Deno
以下是从源代码构建 Deno 的说明。 如果您只想使用 Deno,您可以下载预构建的可执行文件(更多信息请参阅Getting Started
章节)。
克隆仓库 Jump to heading
Deno 使用子模块,因此您必须记住使用 --recurse-submodules
进行克隆。
Linux(Debian)/Mac/WSL
git clone --recurse-submodules https://github.com/denoland/deno.git
Windows:
-
启用“开发者模式”(否则符号链接将需要管理员权限)。
-
确保您正在使用 git 版本 2.19.2.windows.1 或更高版本。
-
在检出之前设置
core.symlinks=true
git config --global core.symlinks true git clone --recurse-submodules https://github.com/denoland/deno.git
先决条件 Jump to heading
Rust Jump to heading
Deno 需要特定版本的 Rust。 Deno 可能不支持在其他版本或 Rust Nightly 版本上构建。 特定版本所需的 Rust 版本在 rust-toolchain.toml
文件中指定。
更新或安装 Rust。 检查 Rust 是否已正确安装/更新
rustc -V
cargo -V
原生编译器和链接器 Jump to heading
Deno 的许多组件需要原生编译器来构建优化的原生函数。
Linux(Debian)/WSL Jump to heading
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
./llvm.sh 17
apt install --install-recommends -y cmake libglib2.0-dev
Mac Jump to heading
Mac 用户必须安装 XCode Command Line Tools。(XCode 已经包含了 XCode Command Line Tools。 运行 xcode-select --install
以在不安装 XCode 的情况下安装它。)
CMake 也是必需的,但不随 Command Line Tools 一起提供。
brew install cmake
Mac M1/M2 Jump to heading
对于 Apple aarch64 用户,必须安装 lld
。
brew install llvm lld
# Add /opt/homebrew/opt/llvm/bin/ to $PATH
Windows Jump to heading
-
获取带有“使用 C++ 的桌面开发”工具包的 VS Community 2019,并确保选择以下列出的必需工具以及所有 C++ 工具。
- Visual C++ tools for CMake
- Windows 10 SDK (10.0.17763.0)
- Testing tools core features - Build Tools
- Visual C++ ATL for x86 and x64
- Visual C++ MFC for x86 and x64
- C++/CLI support
- VC++ 2015.3 v14.00 (v140) toolset for desktop
-
Enable "Debugging Tools for Windows".
- 转到“控制面板”→“程序”→“程序和功能”
- 选择“Windows Software Development Kit - Windows 10”
- →“更改”→“更改”→选中“Debugging Tools For Windows”→“更改”→“完成”。
- 或使用:Debugging Tools for Windows(注意:它将下载文件,您应该手动安装
X64 Debuggers And Tools-x64_en-us.msi
文件。)
Protobuf 编译器 Jump to heading
构建 Deno 需要 Protocol Buffers compiler。
Linux(Debian)/WSL Jump to heading
apt install -y protobuf-compiler
protoc --version # Ensure compiler version is 3+
Mac Jump to heading
brew install protobuf
protoc --version # Ensure compiler version is 3+
Windows Jump to heading
Windows 用户可以从 GitHub 下载最新的二进制版本。
Python 3 Jump to heading
构建 Deno Jump to heading
构建 Deno 最简单的方法是使用 V8 的预编译版本。
对于 WSL,请确保您在 .wslconfig
中分配了足够的内存。 建议您至少分配 16GB。
cargo build -vv
但是,如果您正在进行较低级别的 V8 开发,或者使用没有 V8 预编译版本的平台,您可能还想从源代码构建 Deno 和 V8
V8_FROM_SOURCE=1 cargo build -vv
从源代码构建 V8 时,可能需要更多依赖项。 有关 V8 构建的更多详细信息,请参阅 rusty_v8 的 README。
构建 Jump to heading
使用 Cargo 构建
# Build:
cargo build -vv
# Build errors? Ensure you have latest main and try building again, or if that doesn't work try:
cargo clean && cargo build -vv
# Run:
./target/debug/deno run tests/testdata/run/002_hello.ts
运行测试 Jump to heading
Deno 有一套全面的测试套件,用 Rust 和 TypeScript 编写。 Rust 测试可以在构建过程中使用以下命令运行
cargo test -vv
TypeScript 测试可以使用以下命令运行
# Run all unit/tests:
target/debug/deno test -A --unstable --lock=tools/deno.lock.json --config tests/config/deno.json tests/unit
# Run a specific test:
target/debug/deno test -A --unstable --lock=tools/deno.lock.json --config tests/config/deno.json tests/unit/os_test.ts
使用多个 Crates Jump to heading
如果一个变更集跨越多个 Deno crates,您可能希望一起构建多个 crates。 建议您将所有必需的 crates 并排放置检出。 例如
- denoland/
- deno/
- deno_core/
- deno_ast/
- ...
然后您可以使用 Cargo 的 patch 功能来覆盖默认的依赖路径
cargo build --config 'patch.crates-io.deno_ast.path="../deno_ast"'
如果您正在处理一个变更集几天,您可能更喜欢将 patch 添加到您的 Cargo.toml
文件中(只需确保在暂存您的更改之前删除它)
[patch.crates-io]
deno_ast = { path = "../deno_ast" }
这将从本地路径构建 deno_ast
crate,并链接到该版本,而不是从 crates.io
获取。
注意:Cargo.toml
中依赖项的版本与您磁盘上依赖项的版本匹配非常重要。
使用 cargo search <dependency_name>
检查版本。