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_capi #3607

Merged
merged 4 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 9 additions & 6 deletions components/properties/src/props.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ impl<T: TrieValue> PropertyValueNameToEnumMapper<T> {
}
}

/// Construct a new one from loaded data
///
/// Typically it is preferable to use methods on individual property value types
/// (like [`Script::get_name_to_enum_mapper()`]) instead.
#[doc(hidden)] // used for efficiency by FFI code
pub fn from_data<M>(data: DataPayload<M>) -> Self
pub(crate) fn from_data<M>(data: DataPayload<M>) -> Self
where
M: DataMarker<Yokeable = PropertyValueNameToEnumMapV1<'static>>,
{
Expand All @@ -114,6 +109,14 @@ impl<T: TrieValue> PropertyValueNameToEnumMapper<T> {
markers: PhantomData,
}
}

#[doc(hidden)] // used by FFI code
pub fn erase(self) -> PropertyValueNameToEnumMapper<u16> {
PropertyValueNameToEnumMapper {
map: self.map.cast(),
markers: PhantomData,
}
}
}

impl<T: TrieValue> PropertyValueNameToEnumMapperBorrowed<'_, T> {
Expand Down
8 changes: 3 additions & 5 deletions docs/tutorials/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ _We are still working on improving the user experience of using ICU4X from other
- Inside the crate you can use `cargo build` to build the library
- Be sure to pass `--release` to get an optimized build
- Specify Cargo features with `--features ...`:
- `compiled_data` to include data (`ICU4XDataProvider::create_compiled()`)
- `buffer_provider` for working with blob data providers (`ICU4XDataProvider::create_from_byte_slice()`)
- `provider_test` to include testing data (`ICU4XDataProvider::create_test()`)
- `provider_fs` for loading data from the file system (`ICU4XDataProvider::create_fs()`). This also requires enabling a syntax on the `icu_provider` crate.
- `logging` and `simple_logger` enable basic stdout logging of error metadata. Further loggers can be added on request.
- `cpp_default` turns on a bunch of these and is useful for exploration, but should not be used in production as it enables `provider_test`
Expand Down Expand Up @@ -50,10 +50,8 @@ int main() {
// Create a locale object representing Bangla
ICU4XLocale locale = ICU4XLocale::create_from_string("bn").ok().value();

// Use a testing data provider
// Production code probably should use create_fs() or create_from_byte_slice()
// with data generated by icu4x-datagen
ICU4XDataProvider dp = ICU4XDataProvider::create_test();
// Use compiled data
ICU4XDataProvider dp = ICU4XDataProvider::create_compiled();

// Create a formatter object with the appropriate settings
ICU4XFixedDecimalFormatter fdf = ICU4XFixedDecimalFormatter::create_with_grouping_strategy(
Expand Down
1 change: 1 addition & 0 deletions ffi/capi_cdylib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ icu_provider = { version = "1.2.0", path = "../../provider/core", default-featur
default = ["icu_capi/default"]
any_provider = ["icu_capi/any_provider"]
buffer_provider = ["icu_capi/buffer_provider"]
compiled_data = ["icu_capi/compiled_data"]
provider_fs = ["icu_capi/provider_fs"] # Indirectly implies buffer_provider
provider_test = ["icu_capi/provider_test"]
logging = ["icu_capi/logging"]
Expand Down
1 change: 1 addition & 0 deletions ffi/capi_staticlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ icu_provider = { version = "1.2.0", path = "../../provider/core", default-featur
default = ["icu_capi/default"]
any_provider = ["icu_capi/any_provider"]
buffer_provider = ["icu_capi/buffer_provider"]
compiled_data = ["icu_capi/compiled_data"]
provider_fs = ["icu_capi/provider_fs"] # Indirectly implies buffer_provider
provider_test = ["icu_capi/provider_test"]
logging = ["icu_capi/logging"]
Expand Down
18 changes: 16 additions & 2 deletions ffi/diplomat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ max_combination_size = 2

# Please keep the features list in sync with the icu_capi_staticlib/icu_capi_cdylib crates (except for components features)
[features]
default = ["any_provider", "default_components"]
default = ["compiled_data", "default_components"]
any_provider = []
buffer_provider = [
"dep:icu_provider_blob",
Expand Down Expand Up @@ -67,7 +67,7 @@ logging = ["icu_provider/log_error_context", "dep:log"]
simple_logger = ["dep:simple_logger"]

# meta feature for things we enable by default in C and C++
cpp_default = ["provider_test", "logging", "simple_logger"]
cpp_default = ["logging", "simple_logger"]

# meta feature for things we enable by default in wasm
wasm_default = ["buffer_provider", "logging"]
Expand All @@ -93,6 +93,20 @@ icu_properties = ["dep:icu_properties", "dep:icu_collections", "dep:unicode-bidi
icu_segmenter = ["dep:icu_segmenter"]
icu_timezone = ["dep:icu_timezone", "dep:icu_calendar"]

compiled_data = [
"icu_calendar?/compiled_data",
"icu_collator?/compiled_data",
"icu_datetime?/compiled_data",
"icu_decimal?/compiled_data",
"icu_displaynames?/compiled_data",
"icu_list?/compiled_data",
"icu_locid_transform?/compiled_data",
"icu_normalizer?/compiled_data",
"icu_plurals?/compiled_data",
"icu_properties?/compiled_data",
"icu_segmenter?/compiled_data",
"icu_timezone?/compiled_data",
]

robertbastian marked this conversation as resolved.
Show resolved Hide resolved
[dependencies]
# Mandatory ICU4X components and utils
Expand Down
2 changes: 1 addition & 1 deletion ffi/diplomat/c/examples/fixeddecimal/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main() {
return 1;
}
ICU4XLocale* locale = locale_result.ok;
ICU4XDataProvider* provider = ICU4XDataProvider_create_test();
ICU4XDataProvider* provider = ICU4XDataProvider_create_compiled();

ICU4XFixedDecimal* decimal = ICU4XFixedDecimal_create_from_u64(1000007);

Expand Down

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

2 changes: 1 addition & 1 deletion ffi/diplomat/c/examples/locale/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ int main() {
ICU4XLocale_destroy(locale);

// Create a LocaleCanonicalizer and LocaleExpander.
ICU4XDataProvider* provider = ICU4XDataProvider_create_test();
ICU4XDataProvider* provider = ICU4XDataProvider_create_compiled();
diplomat_result_box_ICU4XLocaleCanonicalizer_ICU4XError result2 = ICU4XLocaleCanonicalizer_create(provider);
if (!result2.is_ok) {
printf("Could not construct Locale Canonicalizer");
Expand Down
2 changes: 1 addition & 1 deletion ffi/diplomat/c/examples/pluralrules/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main() {
return 1;
}
ICU4XLocale* locale = locale_result.ok;
ICU4XDataProvider* provider = ICU4XDataProvider_create_test();
ICU4XDataProvider* provider = ICU4XDataProvider_create_compiled();
diplomat_result_box_ICU4XPluralRules_ICU4XError plural_result = ICU4XPluralRules_create_cardinal(provider, locale);
if (!plural_result.is_ok) {
printf("Failed to create PluralRules\n");
Expand Down
2 changes: 2 additions & 0 deletions ffi/diplomat/c/include/ICU4XDataProvider.h

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

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

2 changes: 1 addition & 1 deletion ffi/diplomat/c/include/ICU4XRegionDisplayNames.h

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

4 changes: 2 additions & 2 deletions ffi/diplomat/cpp/docs/source/calendar_ffi.rst

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

2 changes: 1 addition & 1 deletion ffi/diplomat/cpp/docs/source/collator_ffi.rst

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

10 changes: 5 additions & 5 deletions ffi/diplomat/cpp/docs/source/datetime_formatter_ffi.rst

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

2 changes: 1 addition & 1 deletion ffi/diplomat/cpp/docs/source/decimal_ffi.rst

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

8 changes: 4 additions & 4 deletions ffi/diplomat/cpp/docs/source/displaynames_ffi.rst

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

2 changes: 1 addition & 1 deletion ffi/diplomat/cpp/docs/source/fallbacker_ffi.rst

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

6 changes: 3 additions & 3 deletions ffi/diplomat/cpp/docs/source/list_ffi.rst

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

8 changes: 4 additions & 4 deletions ffi/diplomat/cpp/docs/source/locale_ffi.rst

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

Loading