Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baked data for icu_plurals, icu_timezone #3462

Merged
merged 19 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ jobs:
with:
key: download-cache
path: /tmp/icu4x-source-cache
- name: Install rustfmt
run: rustup component add rustfmt

# Actual job
- name: Run `cargo make ci-job-full-datagen`
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ members = [
"components/locid_transform",
"components/locid",
"components/normalizer",
"components/plurals/data",
"components/plurals",
"components/properties",
"components/segmenter",
"components/timezone/data",
"components/timezone",
"experimental/bies",
"experimental/casemapping",
Expand Down
3 changes: 3 additions & 0 deletions components/plurals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ zerovec = { version = "0.9.4", path = "../../utils/zerovec", features = ["yoke"]
databake = { version = "0.1.3", path = "../../utils/databake", features = ["derive"], optional = true}
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }

icu_plurals_data = { version = "43", path = "data", optional = true }

[dev-dependencies]
criterion = "0.4"
icu = { path = "../icu" }
Expand All @@ -53,6 +55,7 @@ serde = ["dep:serde", "zerovec/serde", "icu_locid/serde", "icu_provider/serde"]
datagen = ["serde", "zerovec/databake", "dep:databake"]
experimental = []
bench = ["serde"]
data = ["dep:icu_plurals_data"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted elsewhere, we need to bikeshed the feature name (not a landing blocker)


[lib]
path = "src/lib.rs"
Expand Down
5 changes: 2 additions & 3 deletions components/plurals/README.md

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

28 changes: 28 additions & 0 deletions components/plurals/data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is part of ICU4X. For terms of use, please see the file
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see, you implemented separate crates but distributed them inside the individual components instead of in a centralized location

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's please not block on where in the repo these will live

# called LICENSE at the top level of the ICU4X source tree
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
[package]
name = "icu_plurals_data"
version = "43.0.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: how about starting at "0.1.0" and incrementing to "0.1.1", "0.1.2", ... for CLDR updates and new data structs and "0.2.0" when there is a breaking data struct change. Then it's clearly a different versioning scheme than the rest of ICU4X.

(Maybe put new data structs also in a new channel, like breaking changes, so that minor releases are reserved for CLDR and we can continue to update old channels if desired)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we bikeshed versioning later?

description = "Data for the icu_plurals crate"
rust-version = "1.61.0"
authors = ["The ICU4X Project Developers"]
edition = "2021"
readme = "README.md"
repository = "https://github.com/unicode-org/icu4x"
homepage = "https://icu4x.unicode.org"
license = "Unicode-DFS-2016"
categories = ["internationalization"]
# Keep this in sync with other crates unless there are exceptions
include = [
"data/**/*",
"src/**/*",
"examples/**/*",
"benches/**/*",
"tests/**/*",
"Cargo.toml",
"LICENSE",
"README.md"
]

[dependencies]
51 changes: 51 additions & 0 deletions components/plurals/data/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
UNICODE, INC. LICENSE AGREEMENT - DATA FILES AND SOFTWARE

See Terms of Use <https://www.unicode.org/copyright.html>
for definitions of Unicode Inc.’s Data Files and Software.

NOTICE TO USER: Carefully read the following legal agreement.
BY DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING UNICODE INC.'S
DATA FILES ("DATA FILES"), AND/OR SOFTWARE ("SOFTWARE"),
YOU UNEQUIVOCALLY ACCEPT, AND AGREE TO BE BOUND BY, ALL OF THE
TERMS AND CONDITIONS OF THIS AGREEMENT.
IF YOU DO NOT AGREE, DO NOT DOWNLOAD, INSTALL, COPY, DISTRIBUTE OR USE
THE DATA FILES OR SOFTWARE.

COPYRIGHT AND PERMISSION NOTICE

Copyright © 1991-2022 Unicode, Inc. All rights reserved.
Distributed under the Terms of Use in https://www.unicode.org/copyright.html.

Permission is hereby granted, free of charge, to any person obtaining
a copy of the Unicode data files and any associated documentation
(the "Data Files") or Unicode software and any associated documentation
(the "Software") to deal in the Data Files or Software
without restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, and/or sell copies of
the Data Files or Software, and to permit persons to whom the Data Files
or Software are furnished to do so, provided that either
(a) this copyright and permission notice appear with all copies
of the Data Files or Software, or
(b) this copyright and permission notice appear in associated
Documentation.

THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THE DATA FILES OR SOFTWARE.

Except as contained in this notice, the name of a copyright holder
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in these Data Files or Software without prior
written authorization of the copyright holder.


Portions of ICU4X may have been adapted from ICU4C and/or ICU4J.
ICU 1.8.1 to ICU 57.1 © 1995-2016 International Business Machines Corporation and others.
7 changes: 7 additions & 0 deletions components/plurals/data/README.md

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

12 changes: 12 additions & 0 deletions components/plurals/data/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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() {
robertbastian marked this conversation as resolved.
Show resolved Hide resolved
if std::env::var("ICU4X_DATA_DIR").is_ok() {
println!("cargo:rustc-cfg=icu4x_custom_data");
}
println!("cargo:rerun-if-env-changed=ICU4X_DATA_DIR");
}
}
24 changes: 24 additions & 0 deletions components/plurals/data/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"keys": {
"Explicit": [
"plurals/ordinal@1",
"plurals/cardinal@1"
]
},
"locales": {
"CldrSet": [
"modern"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to discuss the CldrSet to use (doesn't need to block this PR)

]
},
"cldr": "Latest",
"icu_export": "Latest",
"segmenter_lstm": "Latest",
"export": {
"Baked": {
"output_path": "data",
"use_separate_crates": true,
"pretty": true
}
},
"overwrite": true
}
2 changes: 2 additions & 0 deletions components/plurals/data/data/any.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated
impl_any_provider!(BakedDataProvider);
59 changes: 59 additions & 0 deletions components/plurals/data/data/macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// @generated
#[macro_use]
#[path = "macros/plurals_cardinal_v1.data.rs"]
mod plurals_cardinal_v1;
#[doc(inline)]
pub use __impl_plurals_cardinal_v1 as impl_plurals_cardinal_v1;
#[macro_use]
#[path = "macros/plurals_ordinal_v1.data.rs"]
mod plurals_ordinal_v1;
#[doc(inline)]
pub use __impl_plurals_ordinal_v1 as impl_plurals_ordinal_v1;
/// Implement [`DataProvider<M>`](icu_provider::DataProvider) on the given struct using the data
/// hardcoded in this file. This allows the struct to be used with
/// `icu`'s `_unstable` constructors.
///
/// ```compile_fail
/// struct MyDataProvider;
/// include!("/path/to/generated/macros.rs");
/// impl_data_provider(MyDataProvider);
/// ```
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_data_provider {
($ provider : path) => {
impl_plurals_cardinal_v1!($provider);
impl_plurals_ordinal_v1!($provider);
};
}
#[doc(inline)]
pub use __impl_data_provider as impl_data_provider;
/// Implement [`AnyProvider`](icu_provider::AnyProvider) on the given struct using the data
/// hardcoded in this module. This allows the struct to be used with
/// `icu`'s `_any` constructors.
///
/// ```compile_fail
/// struct MyAnyProvider;
/// include!("/path/to/generated/macros.rs");
/// impl_any_provider(MyAnyProvider);
/// ```
#[doc(hidden)]
#[macro_export]
macro_rules! __impl_any_provider {
($ provider : path) => {
#[clippy::msrv = "1.61"]
impl icu_provider::AnyProvider for $provider {
fn load_any(&self, key: icu_provider::DataKey, req: icu_provider::DataRequest) -> Result<icu_provider::AnyResponse, icu_provider::DataError> {
const PLURALS_CARDINAL_V1: icu_provider::DataKeyHash = <icu_plurals::provider::CardinalV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed();
const PLURALS_ORDINAL_V1: icu_provider::DataKeyHash = <icu_plurals::provider::OrdinalV1Marker as icu_provider::KeyedDataMarker>::KEY.hashed();
match key.hashed() {
PLURALS_CARDINAL_V1 => icu_provider::DataProvider::<icu_plurals::provider::CardinalV1Marker>::load(self, req).and_then(|r| r.take_metadata_and_payload()).map(|(metadata, payload)| icu_provider::AnyResponse { payload: Some(payload.wrap_into_any_payload()), metadata }),
PLURALS_ORDINAL_V1 => icu_provider::DataProvider::<icu_plurals::provider::OrdinalV1Marker>::load(self, req).and_then(|r| r.take_metadata_and_payload()).map(|(metadata, payload)| icu_provider::AnyResponse { payload: Some(payload.wrap_into_any_payload()), metadata }),
_ => Err(icu_provider::DataErrorKind::MissingDataKey.with_req(key, req)),
}
}
}
};
}
#[doc(inline)]
pub use __impl_any_provider as impl_any_provider;
Loading