Tauri 將Tauri添加到Cargo項(xiàng)目中

2023-10-17 14:58 更新

接下來(lái),我們將添加必要的項(xiàng),將我們的Cargo項(xiàng)目轉(zhuǎn)換為Tauri項(xiàng)目。首先,我們需要在Cargo清單(Cargo.toml)中添加依賴項(xiàng),以便Cargo在構(gòu)建時(shí)知道拉取這些依賴項(xiàng)。

?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

正如你可能已經(jīng)注意到的,我們添加了一個(gè)[build-dependency]。為了使用構(gòu)建依賴項(xiàng),我們必須在構(gòu)建腳本中使用它。我們將在`build.rs`中創(chuàng)建一個(gè)構(gòu)建腳本。

?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()
}

現(xiàn)在,我們的Cargo項(xiàng)目已經(jīng)知道如何使用所有這些設(shè)置來(lái)引入和構(gòu)建Tauri的依賴項(xiàng)。讓我們通過(guò)在實(shí)際項(xiàng)目代碼中設(shè)置Tauri來(lái)完成這個(gè)極簡(jiǎn)示例的Tauri應(yīng)用程序。我們將編輯src/main.rs文件,以添加Tauri功能。

?src/main.rs?:

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

相當(dāng)簡(jiǎn)單,對(duì)吧?


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)