Linux 套件
Linux 的 Tauri 應用程式會透過 Debian 套件 (.deb
檔案) 或 AppImage (.AppImage
檔案) 來發行。預設情況下,Tauri CLI 會自動將您的應用程式程式碼打包成這些格式。請注意,.deb
和 .AppImage
套件只能在 Linux 上建立,因為跨編譯目前還無法使用。
macOS 和 Linux 上的 GUI 應用程式不會繼承殼 dotfiles (.bashrc
、.bash_profile
、.zshrc
等) 中的 $PATH
。查看 Tauri 的 fix-path-env-rs crate 以修正此問題。
若要將 Tauri 應用程式建置並打包成單一可執行檔,只需執行下列指令
- npm
- Yarn
- pnpm
- bun
- Cargo
npm run tauri build
yarn tauri build
pnpm tauri build
bunx tauri build
cargo tauri build
它會建置您的前端 (若已設定,請參閱 beforeBuildCommand
),編譯 Rust 二進制檔,收集所有外部二進制檔和資源,最後產生整齊的特定平台套件和安裝程式。
限制
glibc 等核心函式庫經常與舊系統中斷相容性。因此,您必須使用您打算支援的最舊基礎系統來建置 Tauri 應用程式。相較於 Ubuntu 22.04,較舊的系統(例如 Ubuntu 18.04)更為合適,因為在 Ubuntu 22.04 上編譯的二進制檔對 glibc 版本的要求較高,因此在舊系統上執行時,您會遇到執行時期錯誤,例如 /usr/lib/libc.so.6: version 'GLIBC_2.33' not found
。我們建議使用 Docker 容器或 GitHub Actions 來為 Linux 建置 Tauri 應用程式。
請參閱議題 tauri-apps/tauri#1355 和 rust-lang/rust#57497,以及 AppImage 指南 以取得更多資訊。
Debian
由 Tauri 捆綁器產生的 stock Debian 套件包含您將應用程式傳送至基於 Debian 的 Linux distribution 所需的一切,定義應用程式的圖示、產生一個 Desktop 檔案,並指定相依性 libwebkit2gtk-4.0-37
和 libgtk-3-0
,以及如果您的應用程式使用系統托盤,則指定 libappindicator3-1
。
自訂檔案
如果您需要更多控制權,Tauri 會公開 Debian 套件的幾個組態。
如果您的應用程式相依於其他系統相依性,您可以在 tauri.conf.json > tauri > bundle > deb > depends
中指定它們。
若要將自訂檔案包含在 Debian 套件中,您可以在 tauri.conf.json > tauri > bundle > deb > files
中提供檔案或資料夾清單。組態物件會將 Debian 套件中的路徑對應至檔案系統中檔案的路徑,相對於 tauri.conf.json
檔案。以下是組態範例
{
"tauri": {
"bundle": {
"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
}
}
}
}
}
如果您需要以跨平台的方式捆綁檔案,請查看 Tauri 的 資源 和 sidecar 機制。
AppImage
AppImage 是一種 distribution 格式,它不依賴於系統已安裝的套件,而是捆綁應用程式所需的所有相依性和檔案。因此,輸出檔案較大,但由於它支援許多 Linux distribution,且可以在不安裝的情況下執行,因此較容易 distribution。使用者只需讓檔案可執行 (chmod a+x MyProject.AppImage
) 即可執行它 (./MyProject.AppImage
)。
AppImage 很方便,如果您無法製作針對 distribution 的套件管理員的套件,它可以簡化 distribution 程序。不過,您應該小心使用它,因為檔案大小會從 2-6MB 範圍增加到 70MB 以上。
如果您的應用程式播放音訊/影片,您需要啟用 tauri.conf.json > tauri > bundle > appimage > bundleMediaFramework
。這會增加 AppImage 軟體包的大小,以包含媒體播放所需的額外 gstreamer
檔案。此標記目前僅支援 Ubuntu 建置系統。
跨編譯用於 ARM 基礎裝置的 Tauri 應用程式
本指南說明如何跨編譯您的 Tauri 應用程式以供 ARM 基礎裝置使用,例如 Raspberry Pi。由於 RAM 有限,可能無法直接在裝置上編譯,因此我們將探討兩種方法:在 Windows 上使用 Linux 或 WSL 手動編譯,以及使用 GitHub Action 自動跨編譯。
手動編譯
當您不需要頻繁編譯應用程式,並且偏好一次性設定時,手動編譯是合適的。請按照下列步驟操作
先決條件
AppImages 只能在 ARM 裝置上建置。若要避免 Tauri 建置它,您可以在 src-tauri 資料夾中自訂 tauri.conf.json。調整「targets」陣列,僅包含 ARM 基礎裝置所需的平台。例如
"targets": ["deb", "nsis", "msi", "app", "dmg", "updater"],
或者,您可以在呼叫 tauri build
時使用 --bundles
標籤。
- 對於 Windows,請使用 wsl 設定指南 在 WSL 上安裝 Debian。
- 在 Linux 上,建置機器需要 GLIBC 版本等於或舊於目標裝置。使用以下指令檢查:
ldd --version
。 - 本指南使用基於 Debian/Ubuntu 的 Linux 發行版,因為顯示的指令使用
apt
套件管理員,且已在 Debian 11 上進行測試。
交叉編譯
現在,讓我們為 ARM 交叉編譯 Tauri 應用程式
安裝 Rust 目標以符合您的所需架構
- 對於 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:
開啟或建立檔案
<project-root>/.cargo/config.toml
,並依序加入以下組態[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 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 上的完整檔案看起來類似於此
按一下以查看 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 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
進行這些變更後,透過重新執行步驟 4 中的指令,驗證套件管理員中是否仍已啟用 armhf/arm64 架構。
更新套件資訊:
sudo apt-get update && sudo apt-get upgrade -y
。為您選擇的架構安裝必要的 webkitgtk 函式庫
- 對於 ARMv7:
sudo apt install libwebkit2gtk-4.0-dev:armhf
- 對於 ARMv8 (ARM64):
sudo apt install libwebkit2gtk-4.0-dev:arm64
- 對於 ARMv7:
安裝 OpenSSL 或使用供應商版本
這並非總是必要的,因此您可能想先進行,並檢查您是否看到類似 找不到 OpenSSL 開發標頭
的錯誤。
- 在系統範圍內安裝開發標頭
- 對於 ARMv7:
sudo apt install libssl-dev:armhf
- 對於 ARMv8 (ARM64):
sudo apt install libssl-dev:arm64
- 對於 ARMv7:
- 或為 OpenSSL Rust crate 啟用
vendor
功能,這會影響使用相同次要版本的所有其他 Rust 相依性。您可以透過將此內容新增到Cargo.toml
檔案中的相依性區段來執行此動作
openssl-sys = {version = "0.9", features = ["vendored"]}
根據您選擇的架構,將
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:
為您想要的 ARM 版本建置應用程式
- 對於 ARMv7:
cargo tauri build --target armv7-unknown-linux-gnueabihf
- 對於 ARMv8 (ARM64):
cargo tauri build --target aarch64-unknown-linux-gnu
根據您是要為 ARMv7 或 ARMv8 (ARM64) 交叉編譯 Tauri 應用程式,選擇適當的指令集。請注意,具體步驟可能會因您的 Linux 發行版和設定而異。
實驗性:使用 GitHub Action 自動交叉編譯
對於 GitHub 上的自動化 ARM 可執行檔建置,我們將使用 arm-runner-action,由 Paul Guyot 建立。
AppImages 只能在 ARM 裝置上建置。若要避免 Tauri 建置它,您可以在 src-tauri 資料夾中自訂 tauri.conf.json。調整「targets」陣列,僅包含 ARM 基礎裝置所需的平台。例如
"targets": ["deb", "nsis", "msi", "app", "dmg", "updater"],
或者,您可以在呼叫 tauri build
時使用 --bundles
標籤。
設定
按照 arm-runner-action 儲存庫 README 中的說明設定 GitHub Action。如果您不熟悉 GitHub Actions,請先閱讀 GitHub Actions 指南。
自訂 GitHub Action YAML 中的最後一個步驟,以產生 .deb
檔案,而非 .img
檔案
name: Raspberry Pi compile
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pguyot/arm-runner-action@v2.5.2
with:
base_image: https://dietpi.com/downloads/images/DietPi_RPi-ARMv8-Bullseye.7z
cpu: cortex-a53
bind_mount_repository: true
image_additional_mb: 10240
optimize_image: false
commands: |
# Rust complains (rightly) that $HOME doesn't match eid home
export HOME=/root
# Workaround to CI worker being stuck on Updating crates.io index
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
# Install setup prerequisites
apt-get update -y --allow-releaseinfo-change
apt-get upgrade -y
apt-get autoremove -y
apt-get install curl
curl https://sh.rustup.rs -sSf | sh -s -- -y
. "$HOME/.cargo/env"
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash
# Install framework specific packages
apt-get install -y nodejs
npm install next@latest react@latest react-dom@latest eslint-config-next@latest
# Install build tools and tauri-cli requirements
apt-get install -y libwebkit2gtk-4.0-dev build-essential wget libssl-dev libgtk-3-dev libayatana-appindicator3-dev librsvg2-dev
cargo install tauri-cli
# Install frontend dependencies
npm install
# Build the application
cargo tauri build
- name: Upload deb bundle
uses: actions/upload-artifact@v3
with:
name: Debian Bundle
path: ${{ github.workspace }}/target/release/bundle/deb/tauri_1.4_arm64.deb
調整 path
變數,以符合您的應用程式版本和名稱:${{ github.workspace }}/target/release/bundle/deb/[name]_[version]_arm64.deb
。