Skip to content

Commit 60a3f18

Browse files
committed
globaldata
1 parent 4b7a05d commit 60a3f18

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1548
-150
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/calendar/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ std = ["icu_provider/std", "icu_locid/std"]
5252
serde = ["dep:serde", "zerovec/serde", "tinystr/serde", "icu_provider/serde"]
5353
datagen = ["serde", "dep:databake", "zerovec/databake", "tinystr/databake"]
5454
bench = []
55+
data = []
5556

5657
[package.metadata.cargo-all-features]
5758
# Bench feature gets tested separately and is only relevant for CI

components/calendar/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of ICU4X. For terms of use, please see the file
2+
// called LICENSE at the top level of the ICU4X source tree
3+
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
fn main() {
6+
if std::env::var("CARGO_FEATURE_DATA").is_ok() {
7+
match std::env::var("ICU4X_DATA_DIR") {
8+
Ok(path) => println!("cargo:rustc-env=MACROS_RS={}/macros.rs", path),
9+
Err(_) => println!("cargo:rustc-env=MACROS_RS=../data/macros.rs"),
10+
}
11+
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
12+
}
13+
}

components/calendar/data/any.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
impl_any_provider ! (BakedDataProvider) ;

components/calendar/data/macros.rs

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

components/calendar/data/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
include ! ("macros.rs") ; # [clippy :: msrv = "1.61"] pub struct BakedDataProvider ; impl_data_provider ! (BakedDataProvider) ;

components/calendar/src/any_calendar.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ impl AnyCalendar {
480480
functions: [
481481
Self::try_new_for_locale_unstable,
482482
try_new_for_locale_with_any_provider,
483-
try_new_for_locale_with_buffer_provider
483+
try_new_for_locale_with_buffer_provider,
484+
try_new_for_locale,
484485
]
485486
);
486487

components/calendar/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,17 @@ pub use iso::Iso;
153153

154154
#[doc(no_inline)]
155155
pub use CalendarError as Error;
156+
157+
#[cfg(feature = "data")]
158+
#[doc(hidden)]
159+
#[derive(Debug)]
160+
#[allow(clippy::exhaustive_structs)]
161+
pub struct BakedProvider;
162+
#[cfg(feature = "data")]
163+
mod isolate {
164+
use crate as icu_calendar;
165+
include!(core::env!("MACROS_RS"));
166+
impl_calendar_japanese_v1!(super::BakedProvider);
167+
impl_calendar_japanext_v1!(super::BakedProvider);
168+
impl_datetime_week_data_v1!(super::BakedProvider);
169+
}

components/collator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ criterion = "0.4"
5454
std = ["icu_collections/std", "icu_locid/std", "icu_normalizer/std", "icu_properties/std", "icu_provider/std"]
5555
serde = ["dep:serde", "zerovec/serde", "icu_properties/serde", "icu_normalizer/serde", "icu_collections/serde", "icu_provider/serde"]
5656
datagen = ["serde", "dep:databake", "zerovec/databake", "icu_properties/datagen", "icu_normalizer/datagen", "icu_collections/databake"]
57+
data = ["icu_normalizer/data"]
5758

5859
[[test]]
5960
name = "tests"

components/collator/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of ICU4X. For terms of use, please see the file
2+
// called LICENSE at the top level of the ICU4X source tree
3+
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
fn main() {
6+
if std::env::var("CARGO_FEATURE_DATA").is_ok() {
7+
match std::env::var("ICU4X_DATA_DIR") {
8+
Ok(path) => println!("cargo:rustc-env=MACROS_RS={}/macros.rs", path),
9+
Err(_) => println!("cargo:rustc-env=MACROS_RS=../data/macros.rs"),
10+
}
11+
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
12+
}
13+
}

components/collator/data/any.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
impl_any_provider ! (BakedDataProvider) ;

components/collator/data/macros.rs

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

components/collator/data/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
include ! ("macros.rs") ; # [clippy :: msrv = "1.61"] pub struct BakedDataProvider ; impl_data_provider ! (BakedDataProvider) ;

components/collator/src/comparison.rs

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,55 @@ impl Collator {
8989
+ DataProvider<CanonicalDecompositionDataV1Marker>
9090
+ DataProvider<CanonicalDecompositionTablesV1Marker>
9191
+ ?Sized,
92+
{
93+
Self::try_new_unstable_internal(data_provider, data_provider, locale, options)
94+
}
95+
96+
/// ✨ **Enabled with the `"data"` feature.**
97+
///
98+
/// Creates a new instance using built-in data.
99+
///
100+
/// For details on the behavior of this function, see: [`Self::try_new_unstable`]
101+
///
102+
/// [📚 Help choosing a constructor](icu_provider::constructors)
103+
#[cfg(feature = "data")]
104+
pub fn try_new<D>(locale: &DataLocale, options: CollatorOptions) -> Result<Self, CollatorError>
105+
where
106+
D: DataProvider<CollationSpecialPrimariesV1Marker>
107+
+ DataProvider<CollationDataV1Marker>
108+
+ DataProvider<CollationDiacriticsV1Marker>
109+
+ DataProvider<CollationJamoV1Marker>
110+
+ DataProvider<CollationMetadataV1Marker>
111+
+ DataProvider<CollationReorderingV1Marker>
112+
+ DataProvider<CanonicalDecompositionDataV1Marker>
113+
+ DataProvider<CanonicalDecompositionTablesV1Marker>
114+
+ ?Sized,
115+
{
116+
Self::try_new_unstable_internal(
117+
&crate::BakedProvider,
118+
&icu_normalizer::BakedProvider,
119+
locale,
120+
options,
121+
)
122+
}
123+
124+
fn try_new_unstable_internal<D1, D2>(
125+
data_provider: &D1,
126+
normalizer_data_provider: &D2,
127+
locale: &DataLocale,
128+
options: CollatorOptions,
129+
) -> Result<Self, CollatorError>
130+
where
131+
D1: DataProvider<CollationSpecialPrimariesV1Marker>
132+
+ DataProvider<CollationDataV1Marker>
133+
+ DataProvider<CollationDiacriticsV1Marker>
134+
+ DataProvider<CollationJamoV1Marker>
135+
+ DataProvider<CollationMetadataV1Marker>
136+
+ DataProvider<CollationReorderingV1Marker>
137+
+ ?Sized,
138+
D2: DataProvider<CanonicalDecompositionDataV1Marker>
139+
+ DataProvider<CanonicalDecompositionTablesV1Marker>
140+
+ ?Sized,
92141
{
93142
let req = DataRequest {
94143
locale,
@@ -154,10 +203,13 @@ impl Collator {
154203
}
155204

156205
let decompositions: DataPayload<CanonicalDecompositionDataV1Marker> =
157-
data_provider.load(Default::default())?.take_payload()?;
206+
normalizer_data_provider
207+
.load(Default::default())?
208+
.take_payload()?;
158209

159-
let tables: DataPayload<CanonicalDecompositionTablesV1Marker> =
160-
data_provider.load(Default::default())?.take_payload()?;
210+
let tables: DataPayload<CanonicalDecompositionTablesV1Marker> = normalizer_data_provider
211+
.load(Default::default())?
212+
.take_payload()?;
161213

162214
let mut altered_defaults = CollatorOptionsBitField::new();
163215

@@ -206,7 +258,12 @@ impl Collator {
206258
icu_provider::gen_any_buffer_constructors!(
207259
locale: include,
208260
options: CollatorOptions,
209-
error: CollatorError
261+
error: CollatorError,
262+
functions: [
263+
Self::try_new_unstable,
264+
try_new_with_any_provider,
265+
try_new_with_buffer_provider,
266+
]
210267
);
211268

212269
/// Compare potentially ill-formed UTF-16 slices. Unpaired surrogates

components/collator/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,3 +330,17 @@ pub use options::Strength;
330330

331331
#[doc(no_inline)]
332332
pub use CollatorError as Error;
333+
334+
#[cfg(feature = "data")]
335+
pub(crate) struct BakedProvider;
336+
#[cfg(feature = "data")]
337+
mod isolate {
338+
use crate as icu_collator;
339+
include!(core::env!("MACROS_RS"));
340+
impl_collator_data_v1!(super::BakedProvider);
341+
impl_collator_dia_v1!(super::BakedProvider);
342+
impl_collator_jamo_v1!(super::BakedProvider);
343+
impl_collator_meta_v1!(super::BakedProvider);
344+
impl_collator_prim_v1!(super::BakedProvider);
345+
impl_collator_reord_v1!(super::BakedProvider);
346+
}

components/datetime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ datagen = [
9494
]
9595
experimental = ["dep:litemap"]
9696
bench = ["serde"]
97+
data = ["icu_calendar/data", "icu_decimal/data", "icu_plurals/data"]
9798

9899
[lib]
99100
path = "src/lib.rs"

components/datetime/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// This file is part of ICU4X. For terms of use, please see the file
2+
// called LICENSE at the top level of the ICU4X source tree
3+
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4+
5+
fn main() {
6+
if std::env::var("CARGO_FEATURE_DATA").is_ok() {
7+
match std::env::var("ICU4X_DATA_DIR") {
8+
Ok(path) => println!("cargo:rustc-env=MACROS_RS={}/macros.rs", path),
9+
Err(_) => println!("cargo:rustc-env=MACROS_RS=../data/macros.rs"),
10+
}
11+
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
12+
}
13+
}

components/datetime/data/any.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
impl_any_provider ! (BakedDataProvider) ;

components/datetime/data/macros.rs

Lines changed: 2 additions & 0 deletions
Large diffs are not rendered by default.

components/datetime/data/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated
2+
include ! ("macros.rs") ; # [clippy :: msrv = "1.61"] pub struct BakedDataProvider ; impl_data_provider ! (BakedDataProvider) ;

0 commit comments

Comments
 (0)