如何在 Linux 上安装 AppFlowy 构建依赖并从源码首次构建应用
【免费下载链接】AppFlowyBring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.项目地址: https://gitcode.com/GitHub_Trending/ap/AppFlowy
AppFlowy 的 Linux 桌面版由 Flutter 前端与 Rust 后端两部分组成:Rust 侧的dart-fficrate 编译出动态库libdart_ffi.so供 Flutter 侧链接,再由flutter build linux打包整个应用。本文面向 Linux x86_64 环境,目标是完成一次从源码到可运行产物的首次构建:安装构建依赖(Rust、Flutter 指定版本、系统开发库),然后执行仓库自带的 cargo-make 构建链。构建成功后,会在appflowy_flutter/product/下生成 AppFlowy 的 Linux 产品目录。
准备条件
仓库提供了一键依赖安装脚本 install_linux.sh,但它对系统已有环境有如下要求:
- Flutter SDK 必须已安装且在 PATH 中。脚本不会安装 Flutter,它只负责把 Flutter 切换到指定版本并做检查;
- 包管理器为 apt-get 或 dnf。脚本对系统库的安装只覆盖这两种包管理器,其他发行版会提示手动安装;
- git 可用(脚本内部用 git 切换 Flutter 版本);
- 具备 sudo 权限,脚本中的系统库安装步骤会调用
sudo apt-get/sudo dnf。
另外,仓库通过 rust-toolchain.toml 固定了 Rust 工具链:
[toolchain] channel = "1.85" components = ["clippy", "rustfmt"]即进入该目录构建时使用的 Rust 版本为 1.85(rustup 会根据此文件选用对应工具链)。
安装构建依赖
在仓库根目录执行:
bash scripts/install_dev_env/install_linux.sh脚本必须从仓库根目录运行,因为它内部使用相对路径(.githooks目录、cd frontend)。各步骤的行为和副作用如下,执行前需要知道:
Rust 安装(交互式)。脚本询问
Do you want to install Rust? [y/N],未安装 Rust 时选择Y,等价于执行:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source $HOME/.cargo/env rustup toolchain install stable rustup default stable已有 Rust 环境可选择跳过。
Flutter 版本切换。脚本检查
flutter --version,若不是 3.27.4,会在 Flutter SDK 所在目录执行git checkout 3.27.4。注意这会改变你系统中 Flutter SDK 的检出状态,然后执行:flutter config --enable-linux-desktop flutter doctorflutter doctor用于检查并暴露环境中的其他问题,脚本注释中说明其用途是修复flutter doctor报告的项。系统开发库安装(需要 sudo)。apt 与 dnf 的包名不同:
# apt 系(Debian/Ubuntu) sudo apt-get install keybinder-3.0-dev sudo apt-get install libnotify-dev sudo apt-get install libmpv-dev mpv # dnf 系(Fedora/RHEL) sudo dnf install keybinder3-devel sudo dnf install libnotify-dev sudo dnf install libmpv-dev mpv脚本注释说明
libmpv-dev mpv是为 Video Block 支持安装;其他发行版会提示please install ... manually。git hooks 配置(提交规范相关,非构建必需)。脚本会设置
git config core.hooksPath .githooks,并从上游下载go-gitlint_1.1.0_linux_x86_64.tar.gz解压gitlint到.githooks/目录。这属于贡献者提交校验流程,脚本把它和构建依赖放在一起执行。cargo-make 与 duckscript。进入
frontend/目录后安装:cargo install --force cargo-make cargo install --force --locked duckscript_cli前置依赖检查。脚本最后执行:
cargo make appflowy-flutter-deps-tools对应 env.toml 中的任务链:
rustup target add x86_64-unknown-linux-gnu,以及安装 protobuf 的 Dart 编译器插件(当protoc-gen-dart不在 PATH 中时执行dart pub global activate protoc_plugin 21.1.2,见 protobuf.toml)。
执行首次构建
依赖就绪后,在frontend/目录执行开发版(debug)构建:
cd frontend cargo make --profile development-linux-x86_64 appflowy-linux-dev--profile development-linux-x86_64不是可省略的:Makefile.toml 中该 profile 提供了构建任务检查所必需的环境变量(TARGET_OS、RUST_COMPILE_TARGET、CRATE_TYPE、BUILD_FLAG等),任务env_check的条件就是这些变量已设置。x86_64 profile 的关键取值为RUST_COMPILE_TARGET = "x86_64-unknown-linux-gnu"、BUILD_FLAG = "debug"、LIB_EXT = "so"、LINUX_ARCH = "x64"。
appflowy-linux-dev任务链按顺序执行(定义见 flutter.toml 与 desktop.toml):
编译 Rust 核心库。在
rust-lib/下执行:RUSTFLAGS="--cfg tokio_unstable" cargo build --package=dart-ffi \ --target x86_64-unknown-linux-gnu --features "dart"完成后,产物拷贝步骤会把
rust-lib/target/x86_64-unknown-linux-gnu/debug/libdart_ffi.so与rust-lib/dart-ffi/binding.h复制到appflowy_flutter/linux/flutter/dart_ffi/目录,并打印:🚀 🚀 🚀 AppFlowy-Core build success代码生成,执行
./scripts/code_generation/generate.sh。Flutter 构建,在
appflowy_flutter/下执行:flutter pub get flutter packages pub get flutter build linux --debug --verbose产物归集,把
appflowy_flutter/build/linux/x64/debug/bundle目录拷贝到产品目录。
验证构建结果
任务链全部完成后,检查以下位置(文档中任务脚本实际写入/输出的路径):
- 核心库阶段打印的
AppFlowy-Core build success信息; appflowy_flutter/linux/flutter/dart_ffi/下存在libdart_ffi.so和binding.h;- Flutter 构建产物目录
appflowy_flutter/build/linux/x64/debug/bundle; - 最终产品目录
appflowy_flutter/product/0.11.4/linux/Debug/AppFlowy,其中0.11.4来自 Makefile.toml 中的APPFLOWY_VERSION = "0.11.4"(未显式传APP_VERSION时任务链以该值填充)。
如果某一步失败,cargo make会因on_error_task = "catch"触发restore-crate-type恢复任务,把rust-lib/dart-ffi/Cargo.toml的 crate type 改回staticlib,随后中止——因此报错后直接重试即可,无需手动还原该文件。
常见问题与限制
flutter命令找不到:脚本没有安装 Flutter 的职责,需要按 Flutter 官方安装说明先装好 SDK 并加入 PATH,再重跑脚本完成 3.27.4 版本切换与其余依赖安装。apt/dnf 之外的包管理器:脚本会打印
Your system is not supported, please install keybinder3 manually.(libnotify、libmpv 同理),需按发行版方式手动安装对应的开发库。aarch64 Linux:本文路径是 x86_64。仓库也提供了
development-linux-aarch64profile,与 x86_64 的差异是FLUTTER_DESKTOP_FEATURES = "dart,openssl_vendored",RUST_COMPILE_TARGET = "aarch64-unknown-linux-gnu",对应命令把 profile 换成development-linux-aarch64即可。想要 release 版产物:可选分支是使用
appflowy-linux任务(release 核心库 + release 构建):cargo make --profile production-linux-x86_64 appflowy-linux产物会归集到
appflowy_flutter/product/0.11.4/linux/Release/AppFlowy。
仓库中与本文相关的文件:依赖脚本 install_linux.sh、任务定义 Makefile.toml 及 scripts/makefile 下的desktop.toml、flutter.toml、env.toml、protobuf.toml、工具链固定 rust-toolchain.toml。
【免费下载链接】AppFlowyBring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.项目地址: https://gitcode.com/GitHub_Trending/ap/AppFlowy
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考