Tauri Cargo.toml

2024-02-18 17:27 更新

Cargo 清单文件用于声明您的应用程序依赖、应用元数据和其他 Rust 相关功能。 若您不需要 Rust 进行后端开发,您可能不需要修改此文件。 但了解它的存在意义及其功能还是很重要的。

下方是一个 Tauri 项目的示例 文件:​Cargo.toml

[package]
name = "app"
version = "0.1.0"
description = "A Tauri App"
authors = ["you"]
license = ""
repository = ""
default-run = "app"
edition = "2021"
rust-version = "1.57"

[build-dependencies]
tauri-build = { version = "1.0.0" }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0", features = [ "api-all" ] }

[features]
# by default Tauri runs in production mode
# when `tauri dev` runs it is executed with `cargo run --no-default-features` if `devPath` is an URL
default = [ "custom-protocol" ]
# this feature is used for production builds where `devPath` points to the filesystem
# DO NOT remove this
custom-protocol = [ "tauri/custom-protocol" ]

您要注意的最主要部分是 及 依赖。 Generally, they must both be on the latest minor versions as the Tauri CLI, but this is not strictly required. 如果你在运行你的应用时遇到问题,应检查 和 是否是最新的次要版本上。tauri-buildtauritauritauri-cli

Cargo 版本号使用语义化版本(SemVer)控制。 运行 指令将拉取最新可用的语义版本依赖。 For example, if you specify as the version for , Cargo will detect and download version because it is the latest Semver-compatible version available. 当出现突破性更改时,Tauri 将更新主要版本号。 你能够安全地升级到最新的次要版本和补丁版本,而不必担心你的代码中会有破坏性改变。cargo update1.0.0tauri-build1.0.4

如果要使用特定的 crate 版本,可以通过在依赖项的版本号前面加上来使用精确的版本:=

tauri-bution = Power version = "=1.0.0" }

另外一件需要注意的事情是依赖项的部分。执行 以及 会基于你在 中的属性 设置需要开启的功能进行自动管理。features=[]tauritauri devtauri buildtauri.conf.json"allowlist"

当您构建应用程序时,将生成 文件。此文件主要用于确保在开发过程中跨计算机使用相同的依赖项(类似于 Node.js 或 )。由于您正在开发 Tauri 应用程序,因此应将此文件提交到您的源存储库(只有 Rust 库应该省略提交此文件)。Cargo.lockyarn.lockpackage-lock.json

要了解更多有关 的信息,您可以参阅其官方文档。Cargo.toml


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号