From be89e2e22b0d1bf44ff604346947deb2623a0ae0 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 5 Oct 2023 10:29:22 -0700 Subject: [PATCH] Remove syn from baked_exporter --- Cargo.lock | 2 +- provider/datagen/Cargo.toml | 4 ++-- provider/datagen/src/baked_exporter.rs | 27 +++++++++++++------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6e630659979..b435dfa255e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1460,12 +1460,12 @@ dependencies = [ "ndarray", "once_cell", "postcard", + "proc-macro2", "rayon", "serde", "serde-aux", "serde_json", "simple_logger", - "syn 2.0.37", "tinystr", "toml", "twox-hash", diff --git a/provider/datagen/Cargo.toml b/provider/datagen/Cargo.toml index 2a1b5117d00..6ee644e6f1c 100644 --- a/provider/datagen/Cargo.toml +++ b/provider/datagen/Cargo.toml @@ -70,7 +70,7 @@ icu_provider_blob = { workspace = true, features = ["export"], optional = true } icu_provider_fs = { workspace = true, features = ["export"], optional = true } crlify = { workspace = true, optional = true } databake = { workspace = true, optional = true} -syn = {version = "2", features = ["parsing"], optional = true } +proc-macro2 = {version = "1", optional = true } # Other external dependencies displaydoc = { version = "0.2.3", default-features = false } @@ -103,7 +103,7 @@ simple_logger = { version = "4.1.0", default-features = false } [features] default = ["bin", "use_wasm", "networking", "legacy_api", "rayon", "fs_exporter", "blob_exporter", "baked_exporter"] -baked_exporter = ["dep:crlify", "dep:databake", "dep:syn"] +baked_exporter = ["dep:crlify", "dep:databake", "dep:proc-macro2"] blob_exporter = ["dep:icu_provider_blob"] fs_exporter = ["dep:icu_provider_fs"] legacy_api = ["fs_exporter", "blob_exporter", "baked_exporter"] diff --git a/provider/datagen/src/baked_exporter.rs b/provider/datagen/src/baked_exporter.rs index 2bf0dfdcfe3..7c60bbf1ffe 100644 --- a/provider/datagen/src/baked_exporter.rs +++ b/provider/datagen/src/baked_exporter.rs @@ -276,11 +276,12 @@ impl BakedExporter { &self, body: TokenStream, key: DataKey, - marker: syn::Path, + marker: TokenStream, ) -> Result<(), DataError> { + let marker_string = marker.to_string(); let doc = format!( " Implement `DataProvider<{}>` on the given struct using the data", - marker.segments.iter().next_back().unwrap().ident + marker.into_iter().last().unwrap() ); let ident = Self::ident(key); @@ -308,7 +309,7 @@ impl BakedExporter { self.impl_data .lock() .expect("poison") - .insert(key, quote!(#marker).to_string()); + .insert(key, marker_string); Ok(()) } @@ -346,9 +347,7 @@ impl DataExporter for BakedExporter { key: DataKey, payload: &DataPayload, ) -> Result<(), DataError> { - let marker = - syn::parse2::(crate::registry::key_to_marker_bake(key, &self.dependencies)) - .unwrap(); + let marker = crate::registry::key_to_marker_bake(key, &self.dependencies); let singleton_ident = format!("SINGLETON_{}", Self::ident(key).to_ascii_uppercase()) .parse::() @@ -410,12 +409,12 @@ impl BakedExporter { key: DataKey, fallback_mode: Option, ) -> Result<(), DataError> { - let marker = - syn::parse2::(crate::registry::key_to_marker_bake(key, &self.dependencies)) - .unwrap(); + let marker = crate::registry::key_to_marker_bake(key, &self.dependencies); - let (struct_type, into_data_payload) = if marker.segments.iter().next_back().unwrap().ident - == "DateSkeletonPatternsV1Marker" + let (struct_type, into_data_payload) = if marker + .to_string() + .trim() + .ends_with("DateSkeletonPatternsV1Marker") { ( quote! { @@ -459,7 +458,7 @@ impl BakedExporter { for (bake, locales) in values { let first_locale = locales.iter().next().unwrap(); - let anchor = syn::parse_str::( + let anchor = proc_macro2::Ident::new( &first_locale .chars() .flat_map(|ch| { @@ -473,8 +472,8 @@ impl BakedExporter { } }) .collect::(), - ) - .unwrap(); + proc_macro2::Span::call_site(), + ); let bake = bake.parse::().unwrap(); statics.push(quote! { static #anchor: #struct_type = #bake; }); map.extend(locales.into_iter().map(|l| (l, anchor.clone())));