Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions src/content/docs/zh-cn/distribute/debian.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
---
title: Debian
sidebar:
order: 1
i18nReady: true
---

import ShowSolution from '@components/ShowSolution.astro';
import { Steps } from '@astrojs/starlight/components';

由 Tauri 打包器生成的标准 Debian 软件包包含了将应用程序发布到基于 Debian 的 Linux 发行版所需的一切,包括定义应用程序图标、生成桌面文件以及指定依赖项 `libwebkit2gtk-4.1-0` 和 `libgtk-3-0` ,如果你的应用程序使用系统托盘,还需要指定 `libappindicator3-1` 。
:::note

macOS 和 Linux 上的 GUI 应用程序不会继承来自你的 shell 配置文件中的 `$PATH` ( `.bashrc`,`.bash_profile`, `.zshrc` , `etc`)。查看 Tauri 的 [fix-path-env-rs](https://github.com/tauri-apps/fix-path-env-rs) 包来解决这个问题。

:::

## Limitations (限制)

核心库如 glibc 经常与旧系统不兼容。因此,你必须使用你打算支持的最旧的基础系统来构建你的 Tauri 应用,该系统还提供 Tauri v2 所需的 WebKitGTK 4.1 包。Ubuntu 22.04 和 Debian 12 是合适的基准示例,因为它们从标准软件仓库提供 `libwebkit2gtk-4.1-dev` 。在更新的基础系统上构建可能会提高你的应用所需的最低 glibc 版本,因此当在旧系统上运行时,你可能会遇到类似 `/usr/lib/libc.so.6: version 'GLIBC_2.33' not found` 的运行时错误。我们建议使用 Docker 容器或 GitHub Actions 来为 Linux 构建你的 Tauri 应用。

有关更多信息,请参阅问题 [tauri-apps/tauri#1355](https://github.com/tauri-apps/tauri/issues/1355) and [rust-lang/rust#57497](https://github.com/rust-lang/rust/issues/57497),以及 [AppImage guide](https://docs.appimage.org/reference/best-practices.html#binaries-compiled-on-old-enough-base-system) 指南。

## Custom Files (自定义文件)

Tauri 为 Debian 软件包提供了一些配置选项,以便你在需要更多控制时使用。

如果你的应用依赖于额外的系统依赖项,你可以在 `tauri.conf.json > bundle > linux > deb` 中指定它们。

要在 Debian 软件包中包含自定义文件,你可以在 `tauri.conf.json > bundle > linux > deb > files` 中提供一个文件或文件夹的列表。配置对象将 Debian 软件包中的路径映射到相对于 `tauri.conf.json` 文件在你的文件系统上的路径。以下是一个配置示例:

```json
{
"bundle": {
"linux": {
"deb": {
"files": {
"/usr/share/README.md": "../README.md", // copies the README.md file to /usr/share/README.md
"/usr/share/assets": "../assets/" // copies the entire assets directory to /usr/share/assets
}
}
}
}
}
```

## Cross-Compiling for ARM-based Devices (为基于 ARM 的设备交叉编译)

本指南涵盖手动编译。查看我们的 [GitHub Action guide](/distribute/pipelines/github/#arm-runner-compilation) 指南,了解一个利用 QEMU 构建应用的示例工作流程。这会慢得多,但也将能够构建 AppImages。

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

<Steps>

1. #### 为你的目标架构安装 Rust 目标
- For ARMv7 (32-bit): `rustup target add armv7-unknown-linux-gnueabihf`
- For ARMv8 (ARM64, 64-bit): `rustup target add aarch64-unknown-linux-gnu`

2. #### 安装你选择的架构对应的链接器
- For ARMv7: `sudo apt install gcc-arm-linux-gnueabihf`
- For ARMv8 (ARM64): `sudo apt install gcc-aarch64-linux-gnu`

3. #### 打开或创建文件 `<project-root>/.cargo/config.toml` 并相应添加以下配置

```toml
[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
```

4. #### 在包管理器中启用相应的架构
- For ARMv7: `sudo dpkg --add-architecture armhf`
- For ARMv8 (ARM64): `sudo dpkg --add-architecture arm64`

5. #### 调整包源

在 Debian 上,这一步可能不是必需的,但在其他发行版上,你可能需要编辑/etc/apt/sources.list以包含 ARM 架构变体。例如,在 Ubuntu 22.04 上,将以下行添加到文件底部(请将 jammy 替换为你的 Ubuntu 版本的代号):

```
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 上的完整文件看起来类似于这样:

<ShowSolution>

```
# 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 universe
deb [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 multiverse
deb [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 multiverse

deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security universe
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security multiverse

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
```

</ShowSolution>

6. #### 更新包信息: `sudo apt-get update && sudo apt-get upgrade -y`

7. #### 为你的选择架构安装所需的 webkitgtk 库
- For ARMv7: `sudo apt install libwebkit2gtk-4.1-dev:armhf`
- For ARMv8 (ARM64): `sudo apt install libwebkit2gtk-4.1-dev:arm64`

8. #### 安装 OpenSSL 或使用内置版本

这并非总是必需的,因此你可能想先进行操作,然后检查是否出现类似 `Failed to find OpenSSL development headers` 的错误。
- 要么在系统范围内安装开发头文件:
- For ARMv7: `sudo apt install libssl-dev:armhf`
- For ARMv8 (ARM64): `sudo apt install libssl-dev:arm64`
- 或者启用 OpenSSL Rust 包的供应商功能,这将影响所有使用相同次要版本的 Rust 依赖项。你可以通过在 `Cargo.toml` 文件的依赖项部分添加以下内容来实现:

```toml
openssl-sys = {version = "0.9", features = ["vendored"]}
```

9. #### 根据你选择的架构,将 `PKG_CONFIG_SYSROOT_DIR` 设置到相应的目录
- For ARMv7: `export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf/`
- For ARMv8 (ARM64): `export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/`

10. #### 为你的目标 ARM 版本构建应用程序
- For ARMv7: cargo tauri build --target armv7-unknown-linux-gnueabihf
- For ARMv8 (ARM64): cargo tauri build --target aarch64-unknown-linux-gnu

根据你是否希望为 ARMv7 或 ARMv8(ARM64)交叉编译你的 Tauri 应用程序,选择相应的指令集。请注意,具体步骤可能会因你的 Linux 发行版和配置而异。

</Steps>
Loading