跳到内容
Tauri

RPM

本指南涵盖了如何分发和管理 RPM 软件包,包括检索软件包信息、配置脚本、设置依赖项以及签署软件包。

glibc 等核心库经常破坏与旧系统的兼容性。因此,您必须使用您打算支持的最旧的基础系统来构建您的 Tauri 应用程序。像 Ubuntu 18.04 这样的相对较旧的系统比 Ubuntu 22.04 更适合,因为在 Ubuntu 22.04 上编译的二进制文件对 glibc 版本的​​要求更高,因此在旧系统上运行时,您将面临诸如 /usr/lib/libc.so.6: version 'GLIBC_2.33' not found 之类的运行时错误。我们建议使用 Docker 容器或 GitHub Actions 为 Linux 构建您的 Tauri 应用程序。

有关更多信息,请参阅问题 tauri-apps/tauri#1355rust-lang/rust#57497,以及 AppImage 指南

Tauri 允许您通过添加脚本、设置依赖项、添加许可证、包含自定义文件等方式配置 RPM 包。有关可配置选项的详细信息,请参阅:RpmConfig

RPM 包管理器允许您在软件包安装或卸载之前或之后运行脚本。例如,您可以使用这些脚本在安装软件包后启动服务。

以下是如何添加这些脚本的示例

  1. 在您项目的 src-tauri 目录中创建一个名为 scripts 的文件夹。
终端窗口
mkdir src-tauri/scripts
  1. 在该文件夹中创建脚本文件。
终端窗口
touch src-tauri/scripts/postinstall.sh \
touch src-tauri/scripts/preinstall.sh \
touch src-tauri/scripts/preremove.sh \
touch src-tauri/scripts/postremove.sh

现在如果我们查看 /src-tauri/scripts,我们将看到

终端窗口
ls src-tauri/scripts/
postinstall.sh postremove.sh preinstall.sh preremove.sh
  1. 向脚本添加一些内容
preinstall.sh
echo "-------------"
echo "This is pre"
echo "Install Value: $1"
echo "Upgrade Value: $1"
echo "Uninstall Value: $1"
echo "-------------"
postinstall.sh
echo "-------------"
echo "This is post"
echo "Install Value: $1"
echo "Upgrade Value: $1"
echo "Uninstall Value: $1"
echo "-------------"
preremove.sh
echo "-------------"
echo "This is preun"
echo "Install Value: $1"
echo "Upgrade Value: $1"
echo "Uninstall Value: $1"
echo "-------------"
postremove.sh
echo "-------------"
echo "This is postun"
echo "Install Value: $1"
echo "Upgrade Value: $1"
echo "Uninstall Value: $1"
echo "-------------"
  1. 将脚本添加到 tauri.conf.json 文件中
tauri.conf.json
{
"bundle": {
"linux": {
"rpm": {
"epoch": 0,
"files": {},
"release": "1",
// add the script here
"preInstallScript": "/path/to/your/project/src-tauri/scripts/prescript.sh",
"postInstallScript": "/path/to/your/project/src-tauri/scripts/postscript.sh",
"preRemoveScript": "/path/to/your/project/src-tauri/scripts/prescript.sh",
"postRemoveScript": "/path/to/your/project/src-tauri/scripts/postscript.sh"
}
}
}
}
  • conflict: 如果软件包与另一个软件包冲突,则阻止安装。例如,如果您更新应用程序所依赖的 RPM 软件包,并且新版本与您的应用程序不兼容。

  • provides: 列出您的应用程序提供的 RPM 依赖项。

  • depends: 列出您的应用程序运行所需的 RPM 依赖项。

  • files: 指定要包含在软件包中的文件。

  • obsoletes: 列出您的应用程序过时的 RPM 依赖项。

  • desktopTemplate: 为软件包添加自定义桌面文件。

  • epoch: 定义基于版本号的加权依赖项。

要使用这些选项,请将以下内容添加到您的 tauri.conf.json

tauri.conf.json
{
"bundle": {
"linux": {
"rpm": {
"postRemoveScript": "/path/to/your/project/src-tauri/scripts/postscript.sh",
"conflicts": ["oldLib.rpm"],
"depends": ["newLib.rpm"],
"obsoletes": ["veryoldLib.rpm"],
"provides": ["coolLib.rpm"],
"desktopTemplate": "/path/to/your/project/src-tauri/desktop-template.desktop"
}
}
}
}

要为软件包添加许可证,请将以下内容添加到 src-tauri/cargo.tomlsrc-tauri/tauri.conf.json 文件中

src-tauri/cargo.toml
[package]
name = "tauri-app"
version = "0.0.0"
description = "A Tauri App"
authors = ["you"]
edition = "2021"
license = "MIT" # add the license here
# ... rest of the file

对于 src-tauri/tauri.conf.json

src-tauri/tauri.conf.json
{
"bundle": {
"licenseFile": "../LICENSE", // put the path to the license file here
"license": "MIT" // add the license here
}
}

要构建 RPM 包,您可以使用以下命令

npm run tauri build

此命令将在 src-tauri/target/release/bundle/rpm 目录中构建 RPM 包。

Tauri 允许您在构建过程中使用系统中的密钥签署软件包。为此,您需要生成一个 GPG 密钥。

要生成 GPG 密钥,您可以使用以下命令

终端窗口
gpg --gen-key

按照说明生成密钥。

生成密钥后,您需要将其添加到您的环境变量中。您可以通过将其添加到 .bashrc 或 .zshrc 文件中,或者直接在终端中导出它来完成此操作

终端窗口
export TAURI_SIGNING_RPM_KEY=$(cat /home/johndoe/my_super_private.key)

如果您的密钥有密码,您可以将其添加到环境变量中

终端窗口
export TAURI_SIGNING_RPM_KEY_PASSPHRASE=password

现在您可以使用以下命令构建软件包

npm run tauri build

在验证签名之前,您需要创建并将公钥导入到 RPM 数据库中

终端窗口
gpg --export -a 'Tauri-App' > RPM-GPG-KEY-Tauri-App
终端窗口
sudo rpm --import RPM-GPG-KEY-Tauri-App

现在密钥已导入,我们必须编辑 ~/.rpmmacros 文件以使用该密钥。

~/.rpmmacros
%_signature gpg
%_gpg_path /home/johndoe/.gnupg
%_gpg_name Tauri-App
%_gpgbin /usr/bin/gpg2
%__gpg_sign_cmd %{__gpg} \
gpg --force-v3-sigs --digest-algo=sha1 --batch --no-verbose --no-armor \
--passphrase-fd 3 --no-secmem-warning -u "%{_gpg_name}" \
-sbo %{__signature_filename} %{__plaintext_filename}

最后,您可以使用以下命令验证软件包

终端窗口
rpm -v --checksig tauri-app-0.0.0-1.x86_64.rpm

在本节中,我们将介绍如何通过检查软件包内容和获取软件包信息来调试 RPM 软件包。

要获取有关您的软件包的信息,例如版本、发布和架构,请使用以下命令

终端窗口
rpm -qip package_name.rpm

例如,如果您想获取软件包的名称、版本、发布、架构和大小,请使用以下命令

终端窗口
rpm -qp --queryformat '[%{NAME} %{VERSION} %{RELEASE} %{ARCH} %{SIZE}\n]' package_name.rpm

要检查软件包的内容,请使用以下命令

终端窗口
rpm -qlp package_name.rpm

此命令将列出软件包中包含的所有文件。

要调试安装后/安装前/卸载后/卸载前脚本,请使用以下命令

终端窗口
rpm -qp --scripts package_name.rpm

此命令将打印脚本内容。

要检查软件包的依赖项,请使用以下命令

终端窗口
rpm -qp --requires package_name.rpm

要列出依赖于特定包的包,请使用以下命令

终端窗口
rpm -q --whatrequires package_name.rpm

如果在安装 RPM 软件包期间遇到问题,可以使用 -vv(非常详细)选项来获取详细输出

终端窗口
rpm -ivvh package_name.rpm

或对于已安装的软件包

终端窗口
rpm -Uvvh package_name.rpm

本指南涵盖手动编译。请查看我们的 GitHub Action 指南,了解利用 QEMU 构建应用程序的示例工作流程。这将慢得多,但也能构建 AppImages。

当您不需要频繁编译应用程序并希望一次性设置时,手动编译是合适的。以下步骤要求您使用基于 Debian/Ubuntu 的 Linux 发行版。

    • 对于 ARMv7 (32 位): rustup target add armv7-unknown-linux-gnueabihf
    • 对于 ARMv8 (ARM64, 64 位): rustup target add aarch64-unknown-linux-gnu
    • 对于 ARMv7: sudo apt install gcc-arm-linux-gnueabihf
    • 对于 ARMv8 (ARM64): sudo apt install gcc-aarch64-linux-gnu
  1. [target.armv7-unknown-linux-gnueabihf]
    linker = "arm-linux-gnueabihf-gcc"
    [target.aarch64-unknown-linux-gnu]
    linker = "aarch64-linux-gnu-gcc"
    • 对于 ARMv7: sudo dpkg --add-architecture armhf
    • 对于 ARMv8 (ARM64): sudo dpkg --add-architecture arm64
  2. 在 Debian 上,此步骤可能不需要,但在其他发行版上,您可能需要编辑 /etc/apt/sources.list 以包含 ARM 架构变体。例如,在 Ubuntu 22.04 上,将这些行添加到文件底部(请记住用您的 Ubuntu 版本的代号替换 jammy)

    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy universe
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universe
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiverse
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universe
    deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse

    然后,为了防止主软件包出现问题,您必须将正确的主架构添加到文件之前包含的所有其他行中。对于标准 64 位系统,您需要添加 [arch=amd64],Ubuntu 22.04 上的完整文件如下所示

    • 对于 ARMv7: sudo apt install libwebkit2gtk-4.1-dev:armhf
    • 对于 ARMv8 (ARM64): sudo apt install libwebkit2gtk-4.1-dev:arm64
  3. 这并非总是必需的,因此您可能希望首先继续并检查是否看到诸如 Failed to find OpenSSL development headers 之类的错误。

    • 要么在系统范围内安装开发头文件
      • 对于 ARMv7: sudo apt install libssl-dev:armhf
      • 对于 ARMv8 (ARM64): sudo apt install libssl-dev:arm64
    • 或者为 OpenSSL Rust crate 启用 vendor 特性,这将影响所有其他使用相同次要版本的 Rust 依赖项。您可以通过将其添加到 Cargo.toml 文件的依赖项部分来做到这一点
    openssl-sys = {version = "0.9", features = ["vendored"]}
    • 对于 ARMv7: export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf/
    • 对于 ARMv8 (ARM64): export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/
    • 对于 ARMv7: cargo tauri build —target armv7-unknown-linux-gnueabihf
    • 对于 ARMv8 (ARM64): cargo tauri build —target aarch64-unknown-linux-gnu

    根据您是想为 ARMv7 还是 ARMv8 (ARM64) 交叉编译 Tauri 应用程序,选择适当的说明集。请注意,具体步骤可能因您的 Linux 发行版和设置而异。


© 2025 Tauri 贡献者。CC-BY / MIT