转速
本指南介绍如何分发和管理 RPM 包,包括检索包信息、配置脚本、设置依赖和签名包。
🌐 This guide covers how to distribute and manage RPM packages, including retrieving package information, configuring scripts, setting dependencies, and signing packages.
🌐 Limitations
核心库例如 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 应用。
🌐 Core libraries such as glibc frequently break compatibility with older systems. For this reason, you must build your Tauri application using the oldest base system you intend to support. A relatively old system such as Ubuntu 18.04 is more suited than Ubuntu 22.04, as the binary compiled on Ubuntu 22.04 will have a higher requirement of the glibc version, so when running on an older system, you will face a runtime error like /usr/lib/libc.so.6: version 'GLIBC_2.33' not found. We recommend using a Docker container or GitHub Actions to build your Tauri application for Linux.
请参阅问题 tauri-apps/tauri#1355 和 rust-lang/rust#57497,以及 AppImage 指南 获取更多信息。
🌐 See the issues tauri-apps/tauri#1355 and rust-lang/rust#57497, in addition to the AppImage guide for more information.
🌐 Configuring the RPM package
Tauri 允许你通过添加脚本、设置依赖、添加许可证、包含自定义文件等方式来配置 RPM 包。 有关可配置选项的详细信息,请参阅: RpmConfig。
🌐 Tauri allows you to configure the RPM package by adding scripts, setting dependencies, adding a license, including custom files, and more. For detailed information about configurable options, please refer to: RpmConfig.
🌐 Add post, pre-install/remove script to the package
RPM 软件包管理器允许你在软件包安装或移除之前或之后运行脚本。例如,你可以使用这些脚本在软件包安装后启动服务。
🌐 The RPM package manager allows you to run scripts before or after the installation or removal of the package. For example, you can use these scripts to start a service after the package is installed.
以下是如何添加这些脚本的示例:
🌐 Here’s an example of how to add these scripts:
- 在你的项目的
src-tauri目录中创建一个名为scripts的文件夹。
mkdir src-tauri/scripts- 在文件夹中创建脚本文件。
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,我们会看到:
🌐 Now if we look inside /src-tauri/scripts we will see:
ls src-tauri/scripts/postinstall.sh postremove.sh preinstall.sh preremove.sh- 向脚本添加一些内容
echo "-------------"echo "This is pre"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"echo "-------------"echo "This is post"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"echo "-------------"echo "This is preun"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"echo "-------------"echo "This is postun"echo "Install Value: $1"echo "Upgrade Value: $1"echo "Uninstall Value: $1"echo "-------------"- 将脚本添加到
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" } } }}🌐 Setting the Conflict, Provides, Depends, Files, Obsoletes, DesktopTemplate, and Epoch
- 冲突:如果与另一个软件包冲突,则阻止安装该软件包。例如,如果你更新你的应用依赖的 RPM 软件包,而新版本与你的应用不兼容。
- 提供:列出你的应用提供的 RPM 依赖。
- depends:列出你的应用运行所需的 RPM 依赖。
- files: 指定要包含在包中的文件。
- 废弃:列出你的应用废弃的 RPM 依赖。
- desktopTemplate:向包中添加自定义桌面文件。
- epoch:根据版本号定义加权依赖。
要使用这些选项,请将以下内容添加到你的 tauri.conf.json :
🌐 To use these options, add the following to your 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" } } }}🌐 Add a license to the package
要向包中添加许可证,请将以下内容添加到 src-tauri/cargo.toml 或 src-tauri/tauri.conf.json 文件中:
🌐 To add a license to the package, add the following to the src-tauri/cargo.toml or in the src-tauri/tauri.conf.json file:
[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
🌐 And for src-tauri/tauri.conf.json
{ "bundle": { "licenseFile": "../LICENSE", // put the path to the license file here "license": "MIT" // add the license here }}🌐 Building the RPM package
要构建 RPM 包,你可以使用以下命令:
🌐 To build the RPM package, you can use the following command:
npm run tauri buildyarn tauri buildpnpm tauri builddeno task tauri buildbun tauri buildcargo tauri build此命令将在 src-tauri/target/release/bundle/rpm 目录中构建 RPM 包。
🌐 This command will build the RPM package in the src-tauri/target/release/bundle/rpm directory.
🌐 Signing the RPM package
Tauri 允许你在构建过程中使用系统中的密钥对包进行签名。要做到这一点,你需要生成一个 GPG 密钥。
🌐 Tauri allows you to sign the package with the key you have in your system during the build process. To do this, you will need to generate a GPG key.
🌐 Generate a GPG key
要生成 GPG 密钥,你可以使用以下命令:
🌐 To generate a GPG key you can use the following command:
gpg --gen-key按照说明生成密钥。
🌐 Follow the instruction to generate the key.
一旦生成了密钥,你需要将其添加到你的环境变量中。你可以通过将以下内容添加到你的 .bashrc 或 .zshrc 文件中,或者直接在终端中导出它来完成:
🌐 Once the key is generated, you will need to add it to your environment variable. You can do this by adding the following to your .bashrc or .zshrc file or just export it in the terminal:
export TAURI_SIGNING_RPM_KEY=$(cat /home/johndoe/my_super_private.key)如果你有密钥的密码,你可以将其添加到环境变量中:
🌐 If you have a passphrase for the key, you can add it to the environment variable:
export TAURI_SIGNING_RPM_KEY_PASSPHRASE=password现在你可以使用以下命令构建包:
🌐 Now you can build the package with the following command:
npm run tauri buildyarn tauri buildpnpm tauri builddeno task tauri buildbun tauri buildcargo tauri build🌐 Verify the signature
在验证签名之前,你需要创建公钥并将其导入 RPM 数据库:
🌐 Before verifying the signature, you will need to create and import the public key to the RPM database:
gpg --export -a 'Tauri-App' > RPM-GPG-KEY-Tauri-Appsudo rpm --import RPM-GPG-KEY-Tauri-App现在密钥已经导入,我们必须编辑 ~/.rpmmacros 文件以使用该密钥。
🌐 Now that the key is imported, we have to edit the ~/.rpmmacros file to utilize the key.
%_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}最后,你可以使用以下命令验证包:
🌐 Finally, you can verify the package using the following command:
rpm -v --checksig tauri-app-0.0.0-1.x86_64.rpm🌐 Debugging the RPM package
在本节中,我们将通过检查软件包的内容和获取有关软件包的信息来了解如何调试 RPM 软件包。
🌐 In this section, we will see how to debug the RPM package by checking the content of the package and getting information about the package.
🌐 Getting information about the package
要获取有关你的软件包的信息,例如版本、发行版和架构,请使用以下命令:
🌐 To get information about your package, such as the version, release, and architecture, use the following command:
rpm -qip package_name.rpm🌐 Query specific information about the package
例如,如果你想获取包的名称、版本、发布、架构和大小,请使用以下命令:
🌐 For example, if you want to get the name, version, release, architecture, and size of the package, use the following command:
rpm -qp --queryformat '[%{NAME} %{VERSION} %{RELEASE} %{ARCH} %{SIZE}\n]' package_name.rpm🌐 Checking the content of the package
要检查包的内容,请使用以下命令:
🌐 To check the content of the package, use the following command:
rpm -qlp package_name.rpm此命令将列出包中包含的所有文件。
🌐 This command will list all the files that are included in the package.
🌐 Debugging scripts
要调试安装后/安装前/删除脚本,请使用以下命令:
🌐 To debug post/pre-install/remove scripts, use the following command:
rpm -qp --scripts package_name.rpm此命令将打印脚本的内容。
🌐 This command will print the content of the scripts.
🌐 Checking dependencies
要检查包的依赖,请使用以下命令:
🌐 To check the dependencies of the package, use the following command:
rpm -qp --requires package_name.rpm🌐 List packages that depend on a specific package
要列出依赖于特定包的包,请使用以下命令:
🌐 To list the packages that depend on a specific package, use the following command:
rpm -q --whatrequires package_name.rpm🌐 Debugging Installation Issues
如果在安装 RPM 包时遇到问题,
你可以使用 -vv(非常详细)选项来获取详细输出:
🌐 If you encounter issues during the installation of an RPM package,
you can use the -vv (very verbose) option to get detailed output:
rpm -ivvh package_name.rpm或者对于已安装的软件包:
🌐 Or for an already installed package:
rpm -Uvvh package_name.rpm🌐 Cross-Compiling for ARM-based Devices
本指南涵盖手动编译。查看我们的 GitHub Action 指南 以获取一个示例工作流程,该流程利用 QEMU 构建应用。这将会慢得多,但也能够构建 AppImages。
🌐 This guide covers manual compilation. Check out our GitHub Action guide for an example workflow that leverages QEMU to build the app. This will be much slower but will also be able to build AppImages.
手动编译适用于当你不需要频繁编译应用并且更偏好一次性设置的情况。以下步骤假设你使用的是基于 Debian/Ubuntu 的 Linux 发行版。
🌐 Manual compilation is suitable when you don’t need to compile your application frequently and prefer a one-time setup. The following steps expect you to use a Linux distribution based on Debian/Ubuntu.
-
- 针对 ARMv7(32 位):
rustup target add armv7-unknown-linux-gnueabihf - 对于 ARMv8(ARM64,64 位):
rustup target add aarch64-unknown-linux-gnu
- 针对 ARMv7(32 位):
-
- 对于 ARMv7:
sudo apt install gcc-arm-linux-gnueabihf - 针对 ARMv8(ARM64):
sudo apt install gcc-aarch64-linux-gnu
- 对于 ARMv7:
-
[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
- 对于 ARMv7:
-
在 Debian 上,这一步通常不是必需的,但在其他发行版上,你可能需要编辑 /etc/apt/sources.list 以包含 ARM 架构的变体。例如,在 Ubuntu 22.04 上,将这些行添加到文件底部(记得将 jammy 替换为你 Ubuntu 版本的代号):
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse然后,为了防止主软件包出现问题,你必须将正确的主架构添加到文件之前包含的所有其他行。对于标准的64位系统,你需要添加 [arch=amd64],在 Ubuntu 22.04 上完整的文件看起来类似这样:
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to# newer versions of the distribution.deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy main restricted# deb-src http://archive.ubuntu.com/ubuntu/ jammy main restricted## Major bug fix updates produced after the final release of the## distribution.deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team. Also, please note that software in universe WILL NOT receive any## review or updates from the Ubuntu security team.deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy universe# deb-src http://archive.ubuntu.com/ubuntu/ jammy universedeb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates universe# deb-src http://archive.ubuntu.com/ubuntu/ jammy-updates universe## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu## team, and may not be under a free licence. Please satisfy yourself as to## your rights to use the software. Also, please note that software in## multiverse WILL NOT receive any review or updates from the Ubuntu## security team.deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy multiverse# deb-src http://archive.ubuntu.com/ubuntu/ jammy multiversedeb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse## N.B. software from this repository may not have been tested as## extensively as that contained in the main release, although it includes## newer versions of some applications which may provide useful features.## Also, please note that software in backports WILL NOT receive any review## or updates from the Ubuntu security team.deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse# deb-src http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiversedeb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security main restricted# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricteddeb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security universe# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universedeb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security multiverse# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiversedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricteddeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universedeb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse -
- 对于 ARMv7:
sudo apt install libwebkit2gtk-4.1-dev:armhf - 针对 ARMv8(ARM64):
sudo apt install libwebkit2gtk-4.1-dev:arm64
- 对于 ARMv7:
-
这并不总是必须的,所以你可能想先继续操作,然后检查是否出现像
Failed to find OpenSSL development headers这样的错误。- 要么在整个系统中安装开发头文件:
- 对于 ARMv7:
sudo apt install libssl-dev:armhf - 针对 ARMv8(ARM64):
sudo apt install libssl-dev:arm64
- 对于 ARMv7:
- 或者启用 OpenSSL Rust crate 的供应商功能,这将影响所有使用相同次版本的其他 Rust 依赖。你可以通过在你的
Cargo.toml文件的依赖部分添加以下内容来实现:
openssl-sys = {version = "0.9", features = ["vendored"]} - 要么在整个系统中安装开发头文件:
-
根据你选择的架构,将
Section titled “根据你选择的架构,将 PKG_CONFIG_SYSROOT_DIR 设置为适当的目录”PKG_CONFIG_SYSROOT_DIR设置为适当的目录- 对于 ARMv7:
export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf/ - 针对 ARMv8(ARM64):
export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/
- 对于 ARMv7:
-
- 对于 ARMv7:cargo tauri build —target armv7-unknown-linux-gnueabihf
- 对于 ARMv8 (ARM64):cargo tauri build —target aarch64-unknown-linux-gnu
根据你是否想为 ARMv7 或 ARMv8(ARM64)交叉编译你的 Tauri 应用,选择相应的指令集。请注意,具体步骤可能因你的 Linux 发行版和设置而异。
Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站