Skip to content

Commit b0890a7

Browse files
New datagen API (#3386)
1 parent defa43e commit b0890a7

File tree

48 files changed

+1807
-1359
lines changed

Some content is hidden

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

48 files changed

+1807
-1359
lines changed

Cargo.lock

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

provider/blob/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ log = { version = "0.4", optional = true }
3838

3939
[dev-dependencies]
4040
icu_locid = { path = "../../components/locid", features = ["serde"] }
41+
icu_datagen = { path = "../datagen" }
4142

4243
[features]
4344
std = ["icu_provider/std"]

provider/blob/src/export/blob_exporter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl DataExporter for BlobExporter<'_> {
5757
locale: &DataLocale,
5858
payload: &DataPayload<ExportMarker>,
5959
) -> Result<(), DataError> {
60-
log::trace!("Adding: {}/{}", key, locale);
6160
let mut serializer = postcard::Serializer {
6261
output: AllocVec::new(),
6362
};

provider/blob/src/export/mod.rs

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,59 @@
22
// called LICENSE at the top level of the ICU4X source tree
33
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
44

5-
//! Data generation for [`BlobDataProvider`](crate::BlobDataProvider) data. See the `icu_datagen` crate.
5+
//! Data exporter for [`BlobDataProvider`](crate::BlobDataProvider).
6+
//!
7+
//! This module can be used as a target for the `icu_datagen` crate.
68
//!
79
//! # Examples
810
//!
911
//! ```
10-
//! use icu_provider::datagen::DataExporter;
11-
//! use icu_provider::dynutil::*;
12+
//! use icu_datagen::prelude::*;
13+
//! use icu_provider_blob::export::*;
14+
//!
15+
//! let mut blob: Vec<u8> = Vec::new();
16+
//!
17+
//! // Set up the exporter
18+
//! let mut exporter = BlobExporter::new_with_sink(Box::new(&mut blob));
19+
//!
20+
//! // Export something
21+
//! DatagenProvider::default()
22+
//! .export(
23+
//! [icu_provider::hello_world::HelloWorldV1Marker::KEY].into_iter().collect(),
24+
//! exporter
25+
//! ).unwrap();
26+
//!
27+
//! // communicate the blob to the client application (network, disk, etc.)
28+
//! ```
29+
//!
30+
//! The resulting blob can now be used like this:
31+
//!
32+
//! ```
33+
//! use icu_locid::langid;
1234
//! use icu_provider::hello_world::*;
1335
//! use icu_provider::prelude::*;
14-
//! use icu_provider_blob::export::BlobExporter;
1536
//! use icu_provider_blob::BlobDataProvider;
16-
//! use std::borrow::Cow;
17-
//! use std::io::Read;
18-
//! use std::rc::Rc;
1937
//!
20-
//! let mut buffer: Vec<u8> = Vec::new();
38+
//! // obtain the data blob
39+
//! # let blob = std::fs::read(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/data/hello_world.postcard")).unwrap();
2140
//!
22-
//! let payload = DataPayload::<HelloWorldV1Marker>::from_owned(HelloWorldV1 {
23-
//! message: Cow::Borrowed("Hi"),
24-
//! });
25-
//!
26-
//! // Export something
27-
//! {
28-
//! let mut exporter = BlobExporter::new_with_sink(Box::new(&mut buffer));
29-
//! exporter
30-
//! .put_payload(
31-
//! HelloWorldV1Marker::KEY,
32-
//! &Default::default(),
33-
//! &UpcastDataPayload::upcast(payload.clone()),
34-
//! )
35-
//! .expect("Should successfully export");
36-
//! exporter
37-
//! .close()
38-
//! .expect("Should successfully dump to buffer");
39-
//! }
40-
//!
41-
//! // Create a blob provider reading from the buffer
41+
//! // Create a provider reading from the blob
4242
//! let provider =
43-
//! BlobDataProvider::try_new_from_blob(buffer.into_boxed_slice())
44-
//! .expect("Should successfully read from buffer");
45-
//!
46-
//! // Read the key from the filesystem and ensure it is as expected
47-
//! let req = DataRequest {
48-
//! locale: Default::default(),
49-
//! metadata: Default::default(),
50-
//! };
43+
//! BlobDataProvider::try_new_from_blob(blob.into_boxed_slice())
44+
//! .expect("Should successfully read from blob");
45+
//!
46+
//! // Read the key from the blob
5147
//! let response: DataPayload<HelloWorldV1Marker> = provider
5248
//! .as_deserializing()
53-
//! .load(req)
49+
//! .load(DataRequest {
50+
//! locale: &langid!("en").into(),
51+
//! metadata: Default::default(),
52+
//! })
5453
//! .unwrap()
5554
//! .take_payload()
5655
//! .unwrap();
5756
//!
58-
//! assert_eq!(response.get(), payload.get(),);
57+
//! assert_eq!(response.get().message, "Hello World");
5958
//! ```
6059
6160
mod blob_exporter;

provider/datagen/Cargo.toml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ icu_timezone = { version = "1.2.0", path = "../../components/timezone", features
5050
# ICU provider infrastructure
5151
icu_provider = { version = "1.2.0", path = "../core", features = ["std", "log_error_context", "datagen"]}
5252
icu_provider_adapters = { version = "1.2.0", path = "../adapters", features = ["datagen"] }
53-
icu_provider_blob = { version = "1.2.0", path = "../blob", features = ["export"] }
54-
icu_provider_fs = { version = "1.2.0", path = "../fs", features = ["export"] }
53+
54+
# Exporters
55+
icu_provider_blob = { version = "1.2.0", path = "../blob", features = ["export"], optional = true }
56+
icu_provider_fs = { version = "1.2.0", path = "../fs", features = ["export"], optional = true }
57+
crlify = { version = "1.0.1", path = "../../utils/crlify", optional = true }
58+
databake = { version = "0.1.3", path = "../../utils/databake", optional = true}
59+
syn = {version = "1.0", features = ["parsing"], optional = true }
5560

5661
# Other
5762
cached-path = { version = ">=0.5, <0.7", optional = true }
58-
crlify = { version = "1.0.1", path = "../../utils/crlify"}
59-
databake = { version = "0.1.3", path = "../../utils/databake"}
6063
displaydoc = { version = "0.2.3", default-features = false }
6164
elsa = "1.7"
6265
icu_codepointtrie_builder = { version = "0.3.4", path = "../../components/collections/codepointtrie_builder", default-features = false }
@@ -66,13 +69,10 @@ itertools = "0.10"
6669
lazy_static = "1"
6770
log = "0.4"
6871
ndarray = { version = "0.15.5", default-features = false }
69-
proc-macro2 = "1.0"
70-
quote = "1.0.9"
7172
rayon = "1.5"
7273
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] }
7374
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
7475
serde-aux = { version = "4.1.2", default-features = false }
75-
syn = {version = "1.0", features = ["parsing"] }
7676
tinystr = { version = "0.7.1", path = "../../utils/tinystr", features = ["alloc", "serde", "zerovec"], default-features = false }
7777
toml = "0.5"
7878
writeable = { version = "0.5.1", path = "../../utils/writeable" }
@@ -96,7 +96,11 @@ repodata = { path = "../../provider/repodata" }
9696
dhat = "0.3.0"
9797

9898
[features]
99-
default = ["bin", "use_wasm", "networking"]
99+
default = ["bin", "use_wasm", "networking", "legacy_api"]
100+
provider_baked = ["dep:crlify", "dep:databake", "dep:syn"]
101+
provider_blob = ["dep:icu_provider_blob"]
102+
provider_fs = ["dep:icu_provider_fs"]
103+
legacy_api = ["provider_fs", "provider_blob", "provider_baked"]
100104
bin = ["dep:clap", "dep:eyre", "dep:simple_logger"]
101105
# Use wasm for building codepointtries
102106
use_wasm = ["icu_codepointtrie_builder/wasm"]
@@ -109,13 +113,13 @@ networking = ["dep:cached-path"]
109113

110114
[[bin]]
111115
name = "icu4x-datagen"
112-
path = "src/bin/datagen.rs"
116+
path = "src/bin/datagen/mod.rs"
113117
required-features = ["bin"]
114118

115119
[[test]]
116120
name = "icu4x-verify-zero-copy"
117121
path = "tests/verify-zero-copy.rs"
118122

119123
[package.metadata.cargo-all-features]
120-
# Disable check-all-features, as the bin feature is purely additive.
121-
skip_feature_sets = [[]]
124+
# We don't need working CPT builders for check
125+
skip_feature_sets = [["use_icu4c"], ["use_wasm"]]

provider/datagen/README.md

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

0 commit comments

Comments
 (0)