贡献者指南

开发环境

师成师成· 更新于 2026-09-28· 阅读 9 分钟· 0 次阅读

登录后可跨设备保存划线和私人笔记登录

开发环境

本节介绍如何开始 DataFusion 的开发工作。

快速开始

若要以最快的方式搭建可用的本地环境,请在仓库根目录执行以下步骤:

# 1. Install Rust (https://rust-lang.org/tools/install/) and verify the active toolchain with
rustup show

# 2. Install protoc 3.15+ (see details below)
protoc --version

# 3. Download test data used by examples and many tests
git submodule update --init --recursive

# 4. Build the workspace
cargo build

# 5. Verify that Rust integration tests can be run
cargo test -p datafusion --test parquet_integration

# 6. Verify that sqllogictests can run
cargo test --profile=ci --test sqllogictests

注意事项:

  • 固定使用的 Rust 版本在 rust-toolchain.toml 中定义。
  • 需要安装 protoc 才能从源码编译 DataFusion。
  • 某些测试和示例依赖本地已存在的 git 子模块数据。

Windows 环境设置

wget https://az792536.vo.msecnd.net/vms/VMBuild_20190311/VirtualBox/MSEdge/MSEdge.Win10.VirtualBox.zip
choco install -y git rustup.install visualcpp-build-tools
git-bash.exe
cargo build

开发容器设置

DataFusion 支持 dev containers,可用于在隔离环境中开发 DataFusion,无论是本地环境还是远程环境均可。使用开发容器开发 DataFusion 并非强制要求,但在本地开发可能存在困难的场景下(例如使用 Windows 和 WSL2、硬件较旧的机器等),它会非常有用。

有关 IDE 对开发容器支持的具体细节,请参阅 Visual Studio Code、IntelliJ IDEA、Rust Rover 以及 GitHub Codespaces 的文档。

protoc 安装

从源码编译 DataFusion 需要已安装 protobuf 编译器 protoc。

在大多数平台上,可以通过系统的包管理器进行安装。例如:

# Ubuntu
$ sudo apt install -y protobuf-compiler

# Fedora
$ dnf install -y protobuf-devel

# Arch Linux
$ pacman -S protobuf

# macOS
$ brew install protobuf

你需要确认安装的版本是 3.15 或更高,该版本支持显式的字段存在性(field presence)。更早的版本可能会编译失败。

$ protoc --version
libprotoc 3.15.0

或者,也可以从发布页面下载二进制发行版,或从源码构建。

引导环境

DataFusion 使用 Rust 编写,采用了标准的 Rust 工具链:

  • rustup update stable DataFusion 通常使用最新稳定版 Rust,但在新 Rust 工具链发布时可能会稍有滞后

    • 查看 rust-toolchain.toml 文件中当前固定(pin)的工具链版本
    • 这可能会导致一些问题,例如指定的工具链没有安装 rust-analyzer 组件,此时只需手动安装即可,例如 rustup component add --toolchain 1.98.1 rust-analyzer
  • cargo build

  • cargo fmt 用于格式化代码

  • 等等

测试环境设置:

  • git submodule init
  • git submodule update --init --remote --recursive
  • cargo test 运行测试

请注意,运行 cargo test 需要大量内存资源,因为 cargo 默认会并行运行大量测试。如果遇到测试缓慢或系统卡死的问题,可以通过改为运行 cargo test -- --test-threads=1 来显著降低内存占用。更多信息参见此 issue。

格式化说明:

或一次性全部运行:

调试:

cargo build 和 cargo test 所使用的标准 dev profile 会禁用交互式调试器所需的变量级 DWARF 调试信息。

如果需要用调试器单步调试代码,请使用以下命令构建:

CARGO_PROFILE_DEV_DEBUG=2 cargo build

或者,你也可以在 IDE 中将 CARGO_PROFILE_DEV_DEBUG=2 设置为环境变量。

这将启用源码级调试所需的额外调试信息。

更多详情请参见 DataFusion 的 Cargo.toml 配置。

评论

登录后参与评论

正在加载评论…