Skip to content

入门

🌐 Getting Started

克隆仓库

🌐 Clone Repository

bash
git clone -c core.longpaths=true git@github.com:oxc-project/oxc.git

建立项目

🌐 Set Up Project

安装 Rust

🌐 Install Rust

如果你还没有安装 Rust,请按照 官方说明 安装 Rust。

🌐 If you have not yet installed Rust, follow the official instruction and install Rust.

安装 Rust 后,在项目根目录下运行以下命令:

🌐 After installing Rust, run the following command on the project root:

bash
rustup show

rustup show 读取 ./rust-toolchain.toml 文件,并为此项目安装正确的 Rust 工具链和组件。

cargo binstall

开发 OXC 需要一些 Cargo 工具,建议使用 cargo binstall,它提供了一种低复杂度的机制来安装 Rust 二进制文件,比通过运行 cargo install 从源代码构建它们更快捷。

🌐 Some Cargo tools are required to develop OXC, and it is recommended to use cargo binstall, which provides a low-complexity mechanism to install rust binaries and is faster way than building them from source by running cargo install.

bash
cargo install cargo-binstall

你也可以下载预编译的二进制文件并将其保存在 ~/.cargo/bin 中。

🌐 You can also download the pre-compiled binary and save it in ~/.cargo/bin.

just

OXC 使用 just,这是一种方便的方法来保存和运行特定项目的命令:

🌐 OXC utilizes just, which is a handy way to save and run project-specific commands:

bash
cargo binstall just -y

安装 CMake

🌐 Install CMake

通过从官方网站下载来安装CMake。

🌐 Install CMake by downloading from the official website.

Homebrew 用户也可以选择使用以下方式安装:

bash
brew install cmake

安装 pnpm

🌐 Install pnpm

按照官方网站上的说明安装 pnpm(一个 Node.js 的包管理器,类似于 npm)。

🌐 Install pnpm (a package manager for node.js, similar to npm) by following instructions from the official website.

依赖

🌐 Dependencies

在项目根目录的 justfile 中运行以下命令以安装依赖:

🌐 Run the following command in justfile at the project root to install dependencies:

bash
just init

你可以通过运行 just 来查看可用命令列表。

🌐 You can see the list of available commands by running just.

你可以运行 just ready(或者简称 just r)来确保整个项目能够正确构建和运行。

🌐 You can run just ready (or, just r in short) to make sure the whole project builds and runs correctly.

macOS:更快的编译

🌐 macOS: Faster Compilation

macOS 有一个名为 XProtect 的防病毒功能,它会在可执行文件首次运行时扫描是否含有恶意软件。这可能会显著减慢 Rust 的构建速度,尤其是构建脚本和测试可执行文件。你可以通过在系统设置中将终端添加为“开发者工具”来加快编译速度:

🌐 macOS has an antivirus feature called XProtect that scans executables for malware on first run. This can significantly slow down Rust builds, especially build scripts and test executables. You can speed up compilation by adding Terminal as a "developer tool" in System Settings:

  1. 打开系统设置 > 隐私与安全 > 开发者工具
  2. 添加你的终端应用(终端、iTerm 等)
  3. 重启终端应用

注意: 这会禁用操作系统的安全功能。只有在你能接受这种权衡时才这样做。

更多详情:https://nnethercote.github.io/2025/09/04/faster-rust-builds-on-mac.html

🌐 More details: https://nnethercote.github.io/2025/09/04/faster-rust-builds-on-mac.html