Skip to content

Commit

Permalink
Move the registry into its own crate (#5010)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian authored Jun 7, 2024
1 parent 0c41f61 commit a3c242b
Show file tree
Hide file tree
Showing 13 changed files with 168 additions and 49 deletions.
9 changes: 9 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 @@ -39,6 +39,7 @@ members = [
"provider/core/macros",
"provider/datagen",
"provider/fs",
"provider/registry",

# Baked data
"provider/baked/calendar",
Expand Down Expand Up @@ -151,6 +152,7 @@ icu_provider_macros = { version = "~1.5.0", path = "provider/core/macros", defau
icu_provider_adapters = { version = "~1.5.0", path = "provider/adapters", default-features = false }
icu_provider_blob = { version = "~1.5.0", path = "provider/blob", default-features = false }
icu_provider_fs = { version = "~1.5.0", path = "provider/fs/", default-features = false }
icu_registry = { version = "~1.5.0", path = "provider/registry/", default-features = false }

# Baked data
icu_calendar_data = { version = "~1.5.0", path = "provider/baked/calendar", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions provider/datagen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ log = { workspace = true }
memchr = { workspace = true }
rayon = { workspace = true, optional = true }
writeable = { workspace = true }
icu_registry = { workspace = true }

# Exporters
icu_provider_blob = { workspace = true, features = ["export"], optional = true }
Expand Down
2 changes: 1 addition & 1 deletion provider/datagen/src/baked_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,4 +802,4 @@ macro_rules! cb {
}
}
}
crate::registry!(cb);
icu_registry::registry!(cb);
33 changes: 1 addition & 32 deletions provider/datagen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
mod driver;
#[cfg(feature = "provider")]
mod provider;
mod registry;

pub use driver::DatagenDriver;
pub use driver::DeduplicationStrategy;
Expand Down Expand Up @@ -170,26 +169,6 @@ macro_rules! cb {
]
}

#[test]
fn no_marker_collisions() {
let mut map = std::collections::BTreeMap::new();
let mut failed = false;
for marker in all_markers() {
if let Some(colliding_marker) = map.insert(marker.path.hashed(), marker) {
println!(
"{:?} and {:?} collide at {:?}",
marker.path,
colliding_marker.path,
marker.path.hashed(),
);
failed = true;
}
}
if failed {
panic!();
}
}

/// Parses a human-readable marker identifier into a [`DataMarkerInfo`].
// Supports the hello world marker
/// # Example
Expand Down Expand Up @@ -234,16 +213,6 @@ macro_rules! cb {
}
}

#[test]
fn test_paths_correct() {
$(
assert_eq!(<$marker>::INFO.path.get(), $path);
)+
$(
assert_eq!(<$emarker>::INFO.path.get(), $epath);
)+
}

#[macro_export]
#[doc(hidden)] // macro
macro_rules! make_exportable_provider {
Expand All @@ -265,7 +234,7 @@ macro_rules! cb {
}
}
}
crate::registry!(cb);
icu_registry::registry!(cb);

/// Parses a list of human-readable marker identifiers and returns a
/// list of [`DataMarkerInfo`]s.
Expand Down
2 changes: 1 addition & 1 deletion provider/datagen/src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ macro_rules! cb {
);
}
}
crate::registry!(cb);
icu_registry::registry!(cb);

icu_provider::impl_data_provider_never_marker!(DatagenProvider);

Expand Down
2 changes: 1 addition & 1 deletion provider/datagen/src/provider/tests/make_testdata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl DataExporter for ZeroCopyCheckExporter {
};
}
}
crate::registry!(cb);
icu_registry::registry!(cb);

if payload_before != &payload_after {
self.rountrip_errors.lock().expect("poison").insert((
Expand Down
19 changes: 19 additions & 0 deletions provider/registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# 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 ).

[package]
name = "icu_registry"
version.workspace = true
rust-version.workspace = true
authors.workspace = true
edition.workspace = true
repository.workspace = true
homepage.workspace = true
license.workspace = true
categories.workspace = true
include.workspace = true

[dev-dependencies]
icu = { workspace = true, features = ["experimental"] }
icu_provider = { workspace = true }
46 changes: 46 additions & 0 deletions provider/registry/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
UNICODE LICENSE V3

COPYRIGHT AND PERMISSION NOTICE

Copyright © 2020-2024 Unicode, Inc.

NOTICE TO USER: Carefully read the following legal agreement. BY
DOWNLOADING, INSTALLING, COPYING OR OTHERWISE USING DATA FILES, AND/OR
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.

Permission is hereby granted, free of charge, to any person obtaining a
copy of data files and any associated documentation (the "Data Files") or
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.

SPDX-License-Identifier: Unicode-3.0


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.
23 changes: 23 additions & 0 deletions provider/registry/README.md

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

76 changes: 62 additions & 14 deletions provider/datagen/src/registry.rs → provider/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

//! Exposes the list of all known `DataMarker`s.
//!
//! This is modeled as a macro that accepts a callback macro of the shape:
//!
//! ```
//! macro_rules! cb {
//! ($($marker:path = $path:literal,)+ #[experimental] $($emarker:path = $epath:literal,)+) => {
//! // Do something for each marker, or each experimental marker
//! };
//! }
//! ```
//!
//! Calling this as `registry!(cb);` evaluates `cb` with the list of markers.

#[macro_export]
#[doc(hidden)] // macro
/// The list of all known [`DataMarker`](icu_provider::DataMarker)s.
///
/// This is modeled as a macro that accepts a callback macro of the shape:
///
/// ```
/// macro_rules! cb {
/// ($($marker:path = $path:literal,)+ #[experimental] $($emarker:path = $epath:literal,)+) => {
/// // Do something for each marker, or each experimental marker
/// };
/// }
/// ```
///
/// Calling this as `registry!(cb);` evaluates `cb` with the list of markers.
/// See the crate docs.
macro_rules! registry(
($cb:ident) => {
cb!(
Expand Down Expand Up @@ -324,3 +325,50 @@ macro_rules! registry(
);
}
);

macro_rules! cb {
($($marker:path = $path:literal,)+ #[experimental] $($emarker:path = $epath:literal,)+) => {
#[test]
fn no_marker_collisions() {
use icu_provider::prelude::*;

let mut map = std::collections::BTreeMap::new();
let mut failed = false;
for marker in [
$(
<$marker>::INFO,
)+
$(
<$emarker>::INFO,
)+
] {
if let Some(colliding_marker) = map.insert(marker.path.hashed(), marker) {
println!(
"{:?} and {:?} collide at {:?}",
marker.path,
colliding_marker.path,
marker.path.hashed(),
);
failed = true;
}
}
if failed {
panic!();
}
}

#[test]
fn test_paths_correct() {
use icu_provider::prelude::*;

$(
assert_eq!(<$marker>::INFO.path.get(), $path);
)+
$(
assert_eq!(<$emarker>::INFO.path.get(), $epath);
)+
}
}
}

registry!(cb);
1 change: 1 addition & 0 deletions tools/depcheck/src/allowlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub const EXTRA_DATAGEN_DEPS: &[&str] = &[
"icu_codepointtrie_builder",
"icu_pattern",
"icu_provider_adapters",
"icu_registry",
"itertools",
"itoa",
"matrixmultiply",
Expand Down
1 change: 1 addition & 0 deletions tutorials/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ icu_provider_macros = { path = "../provider/core/macros" }
icu_provider_adapters = { path = "../provider/adapters" }
icu_provider_blob = { path = "../provider/blob" }
icu_provider_fs = { path = "../provider/fs/" }
icu_registry = { path = "../provider/registry/" }

# Baked data
icu_calendar_data = { path = "../provider/baked/calendar" }
Expand Down

0 comments on commit a3c242b

Please sign in to comment.