Rust应用打包工具tauri-bundler的使用,高效构建跨平台桌面应用安装包
Rust应用打包工具tauri-bundler的使用,高效构建跨平台桌面应用安装包
关于tauri-bundler
tauri-bundler是一个用于将Rust可执行文件打包成特定操作系统应用包的工具。它是从cargo-bundle分叉而来,现在作为Tauri CLI使用的库。
配置
Tauri会自动从tauri.conf.json > bundle
对象加载配置,但这个库不依赖它,也可以用于非Tauri应用。
通用设置
这些设置适用于所有(或大多数)操作系统的打包:
name
: 构建应用的名称。如果未设置,则使用Cargo.toml
中的name
值identifier
: [必需] 唯一标识应用的字符串,采用反向DNS格式(如"com.example.appname"
)icon
: [可选] 应用使用的图标,可以是文件路径或glob模式数组version
: [可选] 应用版本。如果未设置,则使用Cargo.toml
中的version
值resources
: [可选] 将被复制到包资源部分的文件或目录列表copyright
: [可选] 与应用关联的版权字符串category
: [可选] 应用类别描述short_description
: [可选] 应用的简短单行描述long_description
: [可选] 应用的多行详细描述
Debian特定设置
这些设置仅在打包deb
包时使用:
depends
: 表示此包依赖的其他包的字符串列表
Mac OS X特定设置
这些设置仅在打包app
和dmg
包时使用:
frameworks
: 需要与app捆绑的Mac OS X框架列表minimum_system_version
: 表示捆绑应用支持的最低Mac OS X版本license
: DMG包的许可证文件路径exception_domain
: 用于macOS .app包的异常域provider_short_name
: 如果Apple ID连接到多个团队,需指定用于公证应用的团队提供者短名称
示例 tauri.conf.json
{
"productName": "Your Awesome App",
"version": "0.1.0",
"identifier": "com.my.app",
"app": {},
"bundle": {
"active": true,
"shortDescription": "",
"longDescription": "",
"copyright": "Copyright (c) You 2021. All rights reserved.",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": ["./assets/**/*.png"],
"deb": {
"depends": ["debian-dependency1", "debian-dependency2"]
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "10.11",
"license": "./LICENSE"
},
"externalBin": ["./sidecar-app"]
}
}
完整示例代码
以下是一个完整的Tauri应用配置示例,展示了如何使用tauri-bundler打包跨平台桌面应用:
// Cargo.toml
[package]
name = "my-tauri-app"
version = "0.1.0"
edition = "2021"
[dependencies]
tauri = { version = "1.0", features = ["api-all"] }
[build-dependencies]
tauri-build = { version = "1.0" }
// src/main.rs
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
// tauri.conf.json
{
"build": {
"distDir": "../dist",
"devPath": "http://localhost:3000",
"beforeDevCommand": "",
"beforeBuildCommand": ""
},
"ctx": {},
"tauri": {
"bundle": {
"active": true,
"targets": "all",
"identifier": "com.example.myapp",
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": ["assets/**/*"],
"externalBin": [],
"copyright": "",
"category": "DeveloperTool",
"shortDescription": "My awesome Tauri app",
"longDescription": "",
"deb": {
"depends": []
},
"macOS": {
"frameworks": [],
"minimumSystemVersion": "",
"license": null,
"exceptionDomain": "",
"signingIdentity": null,
"providerShortName": null,
"entitlements": null
},
"windows": {
"certificateThumbprint": null,
"digestAlgorithm": "sha256",
"timestampUrl": ""
}
},
"updater": {
"active": false
},
"allowlist": {
"all": true
},
"windows": [
{
"title": "My Tauri App",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
],
"security": {
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'"
}
}
}
安装
在项目目录中运行以下Cargo命令安装tauri-bundler:
cargo add tauri-bundler
或者在Cargo.toml中添加:
tauri-bundler = "2.6.0"
许可证
© 2017 - present, George Burton, Tauri-Apps Organization
本程序根据Apache Software License或MIT License的条款授权。
1 回复