diff --git a/CHANGELOG.md b/CHANGELOG.md index 43609aef150..1ac586323f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - CLDR 44 compatibility fixes (https://github.com/unicode-org/icu4x/pull/4134, https://github.com/unicode-org/icu4x/pull/4156, https://github.com/unicode-org/icu4x/pull/4158) - Fix `supported_locales` for collator keys (https://github.com/unicode-org/icu4x/pull/4169) - CLI: Fix behavior of `--segmenter-lstm-root` such that it does not override `icuexportdata-root` (https://github.com/unicode-org/icu4x/pull/4277) + - Make datagen work without `CARGO_PKG_RUST_VERSION` environment variable (https://github.com/unicode-org/icu4x/pull/4292) - Utilities - `databake` - Add implementations for `BTreeSet`, `BTreeMap` (https://github.com/unicode-org/icu4x/pull/4268, https://github.com/unicode-org/icu4x/pull/4274) diff --git a/provider/datagen/src/baked_exporter.rs b/provider/datagen/src/baked_exporter.rs index 9165820018c..70314255efe 100644 --- a/provider/datagen/src/baked_exporter.rs +++ b/provider/datagen/src/baked_exporter.rs @@ -109,7 +109,16 @@ macro_rules! move_out { // TokenStream isn't Send/Sync type SyncTokenStream = String; -const MSRV: &str = std::env!("CARGO_PKG_RUST_VERSION"); +// Produces an MSRV clippy annotation if the `CARGO_PKG_RUST_VERSION` is set. +fn maybe_msrv() -> TokenStream { + std::option_env!("CARGO_PKG_RUST_VERSION") + .map(|msrv| { + quote! { + #[clippy::msrv = #msrv] + } + }) + .unwrap_or_default() +} /// Options for configuring the output of [`BakedExporter`]. #[non_exhaustive] @@ -288,6 +297,8 @@ impl BakedExporter { let prefixed_macro_ident = format!("__impl_{ident}").parse::().unwrap(); + let maybe_msrv = maybe_msrv(); + self.write_to_file( PathBuf::from(format!("macros/{}.rs.data", ident)), quote! { @@ -298,7 +309,7 @@ impl BakedExporter { #[macro_export] macro_rules! #prefixed_macro_ident { ($provider:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv const _: () = <$provider>::MUST_USE_MAKE_PROVIDER_MACRO; #body } @@ -355,15 +366,17 @@ impl DataExporter for BakedExporter { let bake = payload.tokenize(&self.dependencies); + let maybe_msrv = maybe_msrv(); + self.write_impl_macro(quote! { - #[clippy::msrv = #MSRV] + #maybe_msrv impl $provider { // Exposing singleton structs as consts allows us to get rid of fallibility #[doc(hidden)] pub const #singleton_ident: &'static <#marker as icu_provider::DataMarker>::Yokeable = &#bake; } - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::DataProvider<#marker> for $provider { fn load( &self, @@ -450,6 +463,8 @@ impl BakedExporter { .remove(&key) .unwrap_or_default(); + let maybe_msrv = maybe_msrv(); + let body = if values.is_empty() { quote!(Err(icu_provider::DataErrorKind::MissingLocale.with_req(<#marker as icu_provider::KeyedDataMarker>::KEY, req))) } else { @@ -559,7 +574,7 @@ impl BakedExporter { self.write_impl_macro( quote! { - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::DataProvider<#marker> for $provider { fn load( &self, @@ -624,6 +639,8 @@ impl BakedExporter { ) })); + let maybe_msrv = maybe_msrv(); + // macros.rs is the interface for built-in data. It exposes one macro per data key. self.write_to_file( PathBuf::from("macros.rs"), @@ -643,7 +660,7 @@ impl BakedExporter { #[macro_export] macro_rules! __make_provider { ($name:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv impl $name { #[doc(hidden)] #[allow(dead_code)] @@ -686,7 +703,7 @@ impl BakedExporter { #[allow(unused_macros)] macro_rules! impl_any_provider { ($provider:ty) => { - #[clippy::msrv = #MSRV] + #maybe_msrv impl icu_provider::AnyProvider for $provider { fn load_any(&self, key: icu_provider::DataKey, req: icu_provider::DataRequest) -> Result { match key.hashed() { @@ -703,7 +720,7 @@ impl BakedExporter { } // For backwards compatibility - #[clippy::msrv = #MSRV] + #maybe_msrv pub struct BakedDataProvider; impl_data_provider!(BakedDataProvider); },