mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
refactor(build): use cargo_toml instead of toml_edit for perf [TRI-023]
This commit is contained in:
parent
63921fada4
commit
9b4c47c4f8
@ -22,7 +22,7 @@ quote = { version = "1", optional = true }
|
||||
tauri-codegen = { version = "1.0.0-beta.4", path = "../tauri-codegen", optional = true }
|
||||
serde_json = "1.0"
|
||||
tauri-utils = { version = "1.0.0-beta.0", path = "../tauri-utils", features = [ "build" ] }
|
||||
toml_edit = "0.5"
|
||||
cargo_toml = "0.10"
|
||||
|
||||
[target."cfg(windows)".dependencies]
|
||||
winres = "0.1"
|
||||
|
@ -105,49 +105,30 @@ pub fn build() {
|
||||
#[allow(unused_variables)]
|
||||
pub fn try_build(attributes: Attributes) -> Result<()> {
|
||||
use anyhow::anyhow;
|
||||
use cargo_toml::{Dependency, Manifest};
|
||||
use std::fs::read_to_string;
|
||||
use tauri_utils::config::Config;
|
||||
use toml_edit::{Document, Item, Table, Value};
|
||||
|
||||
println!("cargo:rerun-if-changed=tauri.conf.json");
|
||||
println!("cargo:rerun-if-changed=src/Cargo.toml");
|
||||
|
||||
let config: Config = serde_json::from_str(&read_to_string("tauri.conf.json")?)?;
|
||||
|
||||
let mut features = Vec::new();
|
||||
let mut manifest: Document = read_to_string("Cargo.toml")?.parse::<Document>()?;
|
||||
let dependencies = manifest
|
||||
.as_table_mut()
|
||||
.entry("dependencies")
|
||||
.or_insert(Item::Table(Table::new()))
|
||||
.as_table_mut()
|
||||
.expect("manifest dependencies isn't a table");
|
||||
let tauri_item = dependencies.entry("tauri").or_insert(Item::None);
|
||||
if let Some(tauri) = tauri_item.as_table_mut() {
|
||||
if let Item::Value(Value::Array(f)) = tauri.entry("features").or_insert(Item::None) {
|
||||
for feat in f.iter() {
|
||||
if let Value::String(feature) = feat {
|
||||
features.push(feature.value().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Some(Value::InlineTable(table)) = tauri_item.as_value_mut() {
|
||||
if let Some(Value::Array(f)) = table.get("features") {
|
||||
for feat in f.iter() {
|
||||
if let Value::String(feature) = feat {
|
||||
features.push(feature.value().to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut manifest = Manifest::from_path("Cargo.toml")?;
|
||||
if let Some(tauri) = manifest.dependencies.remove("tauri") {
|
||||
let mut features = match tauri {
|
||||
Dependency::Simple(_) => Vec::new(),
|
||||
Dependency::Detailed(dep) => dep.features,
|
||||
};
|
||||
features.sort();
|
||||
|
||||
features.sort();
|
||||
let expected_features = config.tauri.features();
|
||||
if features != expected_features {
|
||||
return Err(anyhow!("
|
||||
let expected_features = config.tauri.features();
|
||||
if features != expected_features {
|
||||
return Err(anyhow!("
|
||||
The `tauri` dependency features on the `Cargo.toml` file does not match the allowlist defined under `tauri.conf.json`.
|
||||
Please run `tauri dev` or `tauri build` or set it to {:?}.
|
||||
", expected_features));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
|
Loading…
Reference in New Issue
Block a user