Skip to content

Commit

Permalink
per-crate data
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed May 31, 2023
1 parent 7cd340d commit 0a0baa8
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 142 deletions.
9 changes: 0 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ members = [
"provider/core",
"provider/datagen",
"provider/fs",
"provider/globaldata",
"provider/macros",
"provider/repodata",
"provider/testdata",
Expand Down
6 changes: 3 additions & 3 deletions components/icu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ experimental = [
"icu_relativetime",
"icu_compactdecimal",
]
globaldata = [
"icu_list/globaldata",
"icu_plurals/globaldata",
data = [
"icu_list/data",
"icu_plurals/data",
]

[package.metadata.cargo-all-features]
Expand Down
7 changes: 3 additions & 4 deletions components/list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ categories = ["internationalization"]
# Keep this in sync with other crates unless there are exceptions
include = [
"src/**/*",
"data/macros.rs",
"examples/**/*",
"benches/**/*",
"tests/**/*",
"Cargo.toml",
"LICENSE",
"README.md"
"README.md",
]

[package.metadata.docs.rs]
Expand All @@ -34,8 +35,6 @@ icu_provider = { version = "1.2.0", path = "../../provider/core", features = ["m
regex-automata = { version = "0.2", default-features = false }
writeable = { version = "0.5.1", path = "../../utils/writeable" }

icu_globaldata = { version = "1.2.0", path = "../../provider/globaldata", optional = true }

databake = { version = "0.1.3", path = "../../utils/databake", optional = true, features = ["derive"]}
deduplicating_array = { version = "0.1.3", path = "../../utils/deduplicating_array", optional = true }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
Expand All @@ -53,7 +52,7 @@ serde = ["dep:deduplicating_array", "dep:serde", "icu_provider/serde"]
serde_human = ["serde", "regex-automata/alloc"]
datagen = ["serde", "std", "dep:databake", "regex-automata/alloc"]
bench = []
globaldata = ["dep:icu_globaldata"]
data = []

[package.metadata.cargo-all-features]
# Bench feature gets tested separately and is only relevant for CI
Expand Down
13 changes: 13 additions & 0 deletions components/list/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

fn main() {
if std::env::var("CARGO_FEATURE_DATA").is_ok() {
match std::env::var("ICU4X_DATA_DIR") {
Ok(path) => println!("cargo:rustc-env=MACROS_RS={}/macros.rs", path),
Err(_) => println!("cargo:rustc-env=MACROS_RS=../data/macros.rs"),
}
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
}
}
File renamed without changes.
2 changes: 2 additions & 0 deletions components/list/data/macros.rs

Large diffs are not rendered by default.

File renamed without changes.
13 changes: 9 additions & 4 deletions components/list/src/list_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ use writeable::*;
#[cfg(doc)]
extern crate writeable;

#[cfg(feature = "data")]
mod data {
include!(core::env!("MACROS_RS"));
}

/// A formatter that renders sequences of items in an i18n-friendly way. See the
/// [crate-level documentation](crate) for more details.
#[derive(Debug)]
Expand All @@ -25,16 +30,16 @@ macro_rules! constructor {
#[doc = concat!("Creates a new [`ListFormatter`] that produces a ", $doc, "-type list.\n\nSee the [CLDR spec]",
"(https://unicode.org/reports/tr35/tr35-general.html#ListPatterns) for an explanation of the different types.\n\n",
"[📚 Help choosing a constructor](icu_provider::constructors)\n\n")]
#[cfg(feature = "globaldata")]
#[cfg(feature = "data")]
pub fn $name(
locale: &DataLocale,
length: ListLength,
) -> Result<Self, ListError> {
struct ListDataProvider;
use crate as icu_list;
icu_globaldata::impl_list_and_v1!(ListDataProvider);
icu_globaldata::impl_list_or_v1!(ListDataProvider);
icu_globaldata::impl_list_unit_v1!(ListDataProvider);
data::impl_list_and_v1!(ListDataProvider);
data::impl_list_or_v1!(ListDataProvider);
data::impl_list_unit_v1!(ListDataProvider);

Self::$name_data(&ListDataProvider, locale, length)
}
Expand Down
5 changes: 2 additions & 3 deletions components/plurals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ categories = ["internationalization"]
# Keep this in sync with other crates unless there are exceptions
include = [
"src/**/*",
"data/macros.rs",
"examples/**/*",
"benches/**/*",
"tests/**/*",
Expand All @@ -35,8 +36,6 @@ icu_locid = { version = "1.2.0", path = "../locid" }
icu_provider = { version = "1.2.0", path = "../../provider/core", features = ["macros"] }
zerovec = { version = "0.9.4", path = "../../utils/zerovec", features = ["yoke"] }

icu_globaldata = { version = "1.2.0", path = "../../provider/globaldata", optional = true }

databake = { version = "0.1.3", path = "../../utils/databake", features = ["derive"], optional = true}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

Expand All @@ -55,7 +54,7 @@ serde = ["dep:serde", "zerovec/serde", "icu_locid/serde", "icu_provider/serde"]
datagen = ["serde", "zerovec/databake", "dep:databake"]
experimental = []
bench = ["serde"]
globaldata = ["dep:icu_globaldata"]
data = []

[lib]
path = "src/lib.rs"
Expand Down
13 changes: 13 additions & 0 deletions components/plurals/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

fn main() {
if std::env::var("CARGO_FEATURE_DATA").is_ok() {
match std::env::var("ICU4X_DATA_DIR") {
Ok(path) => println!("cargo:rustc-env=MACROS_RS={}/macros.rs", path),
Err(_) => println!("cargo:rustc-env=MACROS_RS=../data/macros.rs"),
}
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
}
}
2 changes: 2 additions & 0 deletions components/plurals/data/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated
impl_any_provider ! (BakedDataProvider) ;
2 changes: 2 additions & 0 deletions components/plurals/data/macros.rs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions components/plurals/data/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated
include ! ("macros.rs") ; # [clippy :: msrv = "1.61"] pub struct BakedDataProvider ; impl_data_provider ! (BakedDataProvider) ;
15 changes: 10 additions & 5 deletions components/plurals/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ mod operands;
pub mod provider;
pub mod rules;

#[cfg(feature = "data")]
mod data {
include!(core::env!("MACROS_RS"));
}

use core::cmp::{Ord, PartialOrd};
pub use error::PluralsError;
use icu_provider::prelude::*;
Expand Down Expand Up @@ -348,7 +353,7 @@ impl PluralRules {
///
/// [`type`]: PluralRuleType
/// [`data provider`]: icu_provider
#[cfg(feature = "globaldata")]
#[cfg(feature = "data")]
pub fn try_new(locale: &DataLocale, rule_type: PluralRuleType) -> Result<Self, PluralsError> {
match rule_type {
PluralRuleType::Cardinal => Self::try_new_cardinal(locale),
Expand Down Expand Up @@ -443,11 +448,11 @@ impl PluralRules {
///
/// [`One`]: PluralCategory::One
/// [`Other`]: PluralCategory::Other
#[cfg(feature = "globaldata")]
#[cfg(feature = "data")]
pub fn try_new_cardinal(locale: &DataLocale) -> Result<Self, PluralsError> {
struct PluralDataProvider;
use crate as icu_plurals;
icu_globaldata::impl_plurals_cardinal_v1!(PluralDataProvider);
data::impl_plurals_cardinal_v1!(PluralDataProvider);

Self::try_new_cardinal_unstable(&PluralDataProvider, locale)
}
Expand Down Expand Up @@ -550,11 +555,11 @@ impl PluralRules {
/// [`Two`]: PluralCategory::Two
/// [`Few`]: PluralCategory::Few
/// [`Other`]: PluralCategory::Other
#[cfg(feature = "globaldata")]
#[cfg(feature = "data")]
pub fn try_new_ordinal(locale: &DataLocale) -> Result<Self, PluralsError> {
struct PluralDataProvider;
use crate as icu_plurals;
icu_globaldata::impl_plurals_ordinal_v1!(PluralDataProvider);
data::impl_plurals_ordinal_v1!(PluralDataProvider);

Self::try_new_ordinal_unstable(&PluralDataProvider, locale)
}
Expand Down
2 changes: 1 addition & 1 deletion ffi/ecma402/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ all-features = true

[dependencies]
ecma402_traits = "0.2.0"
icu = { version = "1.2.0", path = "../../components/icu", features = ["std", "globaldata"] }
icu = { version = "1.2.0", path = "../../components/icu", features = ["std", "data"] }
icu_provider = { version = "1.2.0", path = "../../provider/core" }
writeable = { version = "0.5.1", path = "../../utils/writeable" }

Expand Down
6 changes: 6 additions & 0 deletions ffi/gn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ rustflags = []
[gn.package.libm."0.2.6"]
rustflags = []

[gn.package.icu_list."1.2.0"]
rustflags = []

[gn.package.icu_plurals."1.2.0"]
rustflags = []

# Build cargo-gnaw with the checked-in lockfile
[workspace]
members = ["third_party_tools/fuchsia/tools/cargo-gnaw"]
33 changes: 0 additions & 33 deletions provider/globaldata/Cargo.toml

This file was deleted.

51 changes: 0 additions & 51 deletions provider/globaldata/LICENSE

This file was deleted.

7 changes: 0 additions & 7 deletions provider/globaldata/README.md

This file was deleted.

11 changes: 0 additions & 11 deletions provider/globaldata/build.rs

This file was deleted.

2 changes: 0 additions & 2 deletions provider/globaldata/data/macros.rs

This file was deleted.

8 changes: 0 additions & 8 deletions provider/globaldata/src/lib.rs

This file was deleted.

9 changes: 9 additions & 0 deletions tools/make/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ args = [
"--overwrite",
]

[tasks.baked-data]
description = "Builds baked data for each component."
category = "ICU4X Data"
script_runner = "@duckscript"
script = """
exec cargo run -p icu_datagen -- --keys list/and@1 list/or@1 list/unit@1 --locales full --format mod --overwrite --out components/list/data --use-separate-crates
exec cargo run -p icu_datagen -- --keys plurals/ordinal@1 plurals/cardinal@1 --locales full --format mod --overwrite --out components/plurals/data --use-separate-crates
"""

[tasks.download-repo-sources]
description = "Download fresh CLDR JSON and icuexportdata, overwriting the existing CLDR JSON/icuexportdata."
category = "ICU4X Data"
Expand Down

0 comments on commit 0a0baa8

Please sign in to comment.