Use toml_edit instead of toml (#7327)
# Objective Fixes #5675. Replace `toml` with `toml_edit` ## Solution Replace `toml` with `toml_edit`. This conveniently also removes the `serde` dependency from `bevy_macro_utils`, which may speed up cold compilation by removing the serde bottleneck from most of the macro crates in the engine.
This commit is contained in:
parent
7a176ae0a8
commit
5f18033dd3
@ -9,6 +9,6 @@ license = "MIT OR Apache-2.0"
|
||||
keywords = ["bevy"]
|
||||
|
||||
[dependencies]
|
||||
toml = "0.5.8"
|
||||
toml_edit = "0.17"
|
||||
syn = "1.0"
|
||||
quote = "1.0"
|
||||
|
@ -12,10 +12,10 @@ use proc_macro::TokenStream;
|
||||
use quote::{quote, quote_spanned};
|
||||
use std::{env, path::PathBuf};
|
||||
use syn::spanned::Spanned;
|
||||
use toml::{map::Map, Value};
|
||||
use toml_edit::{Document, Item};
|
||||
|
||||
pub struct BevyManifest {
|
||||
manifest: Map<String, Value>,
|
||||
manifest: Document,
|
||||
}
|
||||
|
||||
impl Default for BevyManifest {
|
||||
@ -26,7 +26,7 @@ impl Default for BevyManifest {
|
||||
.map(|mut path| {
|
||||
path.push("Cargo.toml");
|
||||
let manifest = std::fs::read_to_string(path).unwrap();
|
||||
toml::from_str(&manifest).unwrap()
|
||||
manifest.parse::<Document>().unwrap()
|
||||
})
|
||||
.unwrap(),
|
||||
}
|
||||
@ -37,18 +37,15 @@ const BEVY_INTERNAL: &str = "bevy_internal";
|
||||
|
||||
impl BevyManifest {
|
||||
pub fn maybe_get_path(&self, name: &str) -> Option<syn::Path> {
|
||||
fn dep_package(dep: &Value) -> Option<&str> {
|
||||
fn dep_package(dep: &Item) -> Option<&str> {
|
||||
if dep.as_str().is_some() {
|
||||
None
|
||||
} else {
|
||||
dep.as_table()
|
||||
.unwrap()
|
||||
.get("package")
|
||||
.map(|name| name.as_str().unwrap())
|
||||
dep.get("package").map(|name| name.as_str().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
let find_in_deps = |deps: &Map<String, Value>| -> Option<syn::Path> {
|
||||
let find_in_deps = |deps: &Item| -> Option<syn::Path> {
|
||||
let package = if let Some(dep) = deps.get(name) {
|
||||
return Some(Self::parse_str(dep_package(dep).unwrap_or(name)));
|
||||
} else if let Some(dep) = deps.get(BEVY) {
|
||||
@ -66,14 +63,8 @@ impl BevyManifest {
|
||||
Some(path)
|
||||
};
|
||||
|
||||
let deps = self
|
||||
.manifest
|
||||
.get("dependencies")
|
||||
.map(|deps| deps.as_table().unwrap());
|
||||
let deps_dev = self
|
||||
.manifest
|
||||
.get("dev-dependencies")
|
||||
.map(|deps| deps.as_table().unwrap());
|
||||
let deps = self.manifest.get("dependencies");
|
||||
let deps_dev = self.manifest.get("dev-dependencies");
|
||||
|
||||
deps.and_then(find_in_deps)
|
||||
.or_else(|| deps_dev.and_then(find_in_deps))
|
||||
|
@ -7,7 +7,7 @@ publish = false
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[dependencies]
|
||||
toml = "0.5"
|
||||
toml_edit = "0.17"
|
||||
tera = "1.15"
|
||||
serde = { version = "1.0", features = [ "derive" ] }
|
||||
bitflags = "1.3"
|
||||
|
@ -3,7 +3,7 @@ use std::{cmp::Ordering, collections::HashMap, fs::File};
|
||||
use bitflags::bitflags;
|
||||
use serde::Serialize;
|
||||
use tera::{Context, Tera};
|
||||
use toml::Value;
|
||||
use toml_edit::Document;
|
||||
|
||||
bitflags! {
|
||||
struct Command: u32 {
|
||||
@ -89,7 +89,7 @@ impl PartialOrd for Example {
|
||||
|
||||
fn parse_examples(panic_on_missing: bool) -> Vec<Example> {
|
||||
let manifest_file = std::fs::read_to_string("Cargo.toml").unwrap();
|
||||
let manifest: HashMap<String, Value> = toml::from_str(&manifest_file).unwrap();
|
||||
let manifest = manifest_file.parse::<Document>().unwrap();
|
||||
let metadatas = manifest
|
||||
.get("package")
|
||||
.unwrap()
|
||||
@ -99,11 +99,11 @@ fn parse_examples(panic_on_missing: bool) -> Vec<Example> {
|
||||
.clone();
|
||||
|
||||
manifest["example"]
|
||||
.as_array()
|
||||
.as_array_of_tables()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.flat_map(|val| {
|
||||
let technical_name = val["name"].as_str().unwrap().to_string();
|
||||
let technical_name = val.get("name").unwrap().as_str().unwrap().to_string();
|
||||
if panic_on_missing && metadatas.get(&technical_name).is_none() {
|
||||
panic!("Missing metadata for example {technical_name}");
|
||||
}
|
||||
@ -132,7 +132,7 @@ fn parse_examples(panic_on_missing: bool) -> Vec<Example> {
|
||||
|
||||
fn parse_categories() -> HashMap<String, String> {
|
||||
let manifest_file = std::fs::read_to_string("Cargo.toml").unwrap();
|
||||
let manifest: HashMap<String, Value> = toml::from_str(&manifest_file).unwrap();
|
||||
let manifest = manifest_file.parse::<Document>().unwrap();
|
||||
manifest
|
||||
.get("package")
|
||||
.unwrap()
|
||||
@ -140,7 +140,7 @@ fn parse_categories() -> HashMap<String, String> {
|
||||
.as_ref()
|
||||
.unwrap()["category"]
|
||||
.clone()
|
||||
.as_array()
|
||||
.as_array_of_tables()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.map(|v| {
|
||||
|
Loading…
Reference in New Issue
Block a user