Tauri 将Tauri添加到Cargo项目中

2023-10-17 14:58 更新

接下来,我们将添加必要的项,将我们的Cargo项目转换为Tauri项目。首先,我们需要在Cargo清单(Cargo.toml)中添加依赖项,以便Cargo在构建时知道拉取这些依赖项。

Cargo.toml​:

[package]
name = "hello-tauri-webdriver"
version = "0.1.0"
edition = "2021"
rust-version = "1.56"

# Needed to set up some things for Tauri at build time
[build-dependencies]
tauri-build = "1"

# The actual Tauri dependency, along with `custom-protocol` to serve the pages.
[dependencies]
tauri = { version = "1", features = ["custom-protocol"] }

# Make --release build a binary that is small (opt-level = "s") and fast (lto = true).
# This is completely optional, but shows that testing the application as close to the
# typical release settings is possible. Note: this will slow down compilation.
[profile.release]
incremental = false
codegen-units = 1
panic = "abort"
opt-level = "s"
lto = true

正如你可能已经注意到的,我们添加了一个[build-dependency]。为了使用构建依赖项,我们必须在构建脚本中使用它。我们将在`build.rs`中创建一个构建脚本。

build.rs​:

fn main() {
// Only watch the `dist/` directory for recompiling, preventing unnecessary
// changes when we change files in other project subdirectories.
println!("cargo:rerun-if-changed=dist");

// Run the Tauri build-time helpers
tauri_build::build()
}

现在,我们的Cargo项目已经知道如何使用所有这些设置来引入和构建Tauri的依赖项。让我们通过在实际项目代码中设置Tauri来完成这个极简示例的Tauri应用程序。我们将编辑src/main.rs文件,以添加Tauri功能。

src/main.rs​:

fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("unable to run Tauri application");
}

相当简单,对吧?


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

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号