From ad932870cf7b01998f20bc34461deaed3ed49648 Mon Sep 17 00:00:00 2001 From: Robert Bastian Date: Wed, 5 Jul 2023 00:38:36 +0200 Subject: [PATCH] ffi-examples --- .github/workflows/artifacts-build.yml | 6 +- .../locid_transform/src/provider/mod.rs | 1 + ffi/capi_cdylib/Cargo.toml | 1 + ffi/capi_staticlib/Cargo.toml | 1 + ffi/diplomat/Cargo.toml | 2 +- .../c/examples/fixeddecimal_tiny/.gitignore | 3 +- .../c/examples/fixeddecimal_tiny/Makefile | 31 ++-- .../icu_capi_staticlib_tiny/Cargo.lock | 132 +++++++++--------- .../icu_capi_staticlib_tiny/Cargo.toml | 2 +- .../c/examples/fixeddecimal_tiny/test.c | 8 +- ffi/diplomat/js/examples/node/Makefile | 9 +- ffi/diplomat/js/examples/node/index.js | 11 -- .../js/examples/node/test/data-providers.mjs | 19 +-- .../node/test/fixed-decimal-format.mjs | 4 +- ffi/diplomat/js/examples/tinywasm/Makefile | 1 + .../js/examples/wasm-demo/required-keys.txt | 27 ---- .../js/examples/wasm-demo/src/ts/app.ts | 6 +- provider/datagen/src/lib.rs | 14 +- 18 files changed, 109 insertions(+), 169 deletions(-) delete mode 100644 ffi/diplomat/js/examples/wasm-demo/required-keys.txt diff --git a/.github/workflows/artifacts-build.yml b/.github/workflows/artifacts-build.yml index d18828b4e60..99be0e82627 100644 --- a/.github/workflows/artifacts-build.yml +++ b/.github/workflows/artifacts-build.yml @@ -158,11 +158,7 @@ jobs: - name: Init node package run: | cd ffi/diplomat/js/examples/node - make lib - make icu_capi.wasm - # Manually running datagen with the required keys - cargo run -p icu_datagen -- --key-file ../wasm-demo/required-keys.txt --locales full --format blob --out data.postcard - cd ../wasm-demo + make npm ci - name: Run Webpack diff --git a/components/locid_transform/src/provider/mod.rs b/components/locid_transform/src/provider/mod.rs index 6c319a0f59a..4c83cc10850 100644 --- a/components/locid_transform/src/provider/mod.rs +++ b/components/locid_transform/src/provider/mod.rs @@ -39,6 +39,7 @@ const _: () = { icu_locid_transform_data::impl_locid_transform_likelysubtags_ext_v1!(Baked); icu_locid_transform_data::impl_locid_transform_likelysubtags_l_v1!(Baked); icu_locid_transform_data::impl_locid_transform_likelysubtags_sr_v1!(Baked); + #[cfg(feature = "experimental")] icu_locid_transform_data::impl_locid_transform_script_dir_v1!(Baked); }; diff --git a/ffi/capi_cdylib/Cargo.toml b/ffi/capi_cdylib/Cargo.toml index 4fc14b742dd..67d235578e7 100644 --- a/ffi/capi_cdylib/Cargo.toml +++ b/ffi/capi_cdylib/Cargo.toml @@ -50,6 +50,7 @@ logging = ["icu_capi/logging"] simple_logger = ["icu_capi/simple_logger"] wasm_default = ["icu_capi/wasm_default"] cpp_default = ["icu_capi/cpp_default"] +default_components = ["icu_capi/default_components"] [package.metadata.cargo-all-features] # Tested by icu_capi diff --git a/ffi/capi_staticlib/Cargo.toml b/ffi/capi_staticlib/Cargo.toml index d4afce77c1c..3abfcfb88a0 100644 --- a/ffi/capi_staticlib/Cargo.toml +++ b/ffi/capi_staticlib/Cargo.toml @@ -50,6 +50,7 @@ logging = ["icu_capi/logging"] simple_logger = ["icu_capi/simple_logger"] wasm_default = ["icu_capi/wasm_default"] cpp_default = ["icu_capi/cpp_default"] +default_components = ["icu_capi/default_components"] [package.metadata.cargo-all-features] # Tested by icu_capi diff --git a/ffi/diplomat/Cargo.toml b/ffi/diplomat/Cargo.toml index 8ad152d4f90..9af0756fe8e 100644 --- a/ffi/diplomat/Cargo.toml +++ b/ffi/diplomat/Cargo.toml @@ -69,7 +69,7 @@ simple_logger = ["dep:simple_logger"] cpp_default = ["logging", "simple_logger"] # meta feature for things we enable by default in wasm -wasm_default = ["buffer_provider", "logging"] +wasm_default = ["logging"] # Components default_components = ["icu_calendar", "icu_collator", "icu_datetime", "icu_decimal", diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore b/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore index 36fd6b8da6c..d6a0fdc9a56 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore @@ -5,5 +5,4 @@ optim* *.elf *.o a.out.dSYM -decimal-bn-en.postcard -decimal_bn_en.h +baked_data \ No newline at end of file diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile b/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile index a8819791971..f9c8dae4bff 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile @@ -15,54 +15,51 @@ GCC := gcc CLANG := clang-14 LLD := lld-14 +baked_data/macros.rs: + cargo run -p icu_datagen -- --locales en bn --keys all --fallback expand --format mod --use-separate-crates --out baked_data + ../../../../../target/debug/libicu_capi_staticlib.a: FORCE - cargo build -p icu_capi_staticlib --no-default-features --features buffer_provider,icu_capi/default_components + cargo build -p icu_capi_staticlib --no-default-features --features compiled_data,default_components -icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a: FORCE +icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a: FORCE baked_data/macros.rs rustup toolchain install ${ICU4X_NIGHTLY_TOOLCHAIN} rustup component add rust-src --toolchain ${ICU4X_NIGHTLY_TOOLCHAIN} cd icu_capi_staticlib_tiny && \ - RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu + RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" ICU4X_DATA_DIR=$(shell pwd)/baked_data cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu -icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a: FORCE +icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a: FORCE baked_data/macros.rs rustup toolchain install ${ICU4X_NIGHTLY_TOOLCHAIN} rustup component add rust-src --toolchain ${ICU4X_NIGHTLY_TOOLCHAIN} cd icu_capi_staticlib_tiny && \ - RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu --profile=release-opt-size - -decimal-bn-en.postcard: - cargo run -p icu_datagen -- --locales en bn --keys "decimal/symbols@1" --format blob --out decimal-bn-en.postcard - -decimal_bn_en.h: decimal-bn-en.postcard - xxd -i -C decimal-bn-en.postcard > decimal_bn_en.h + RUSTFLAGS="-Clinker-plugin-lto -Clinker=$(CLANG) -Ccodegen-units=1 -Clink-arg=-flto -Cpanic=abort" ICU4X_DATA_DIR=$(shell pwd)/baked_data cargo +${ICU4X_NIGHTLY_TOOLCHAIN} panic-abort-build --target x86_64-unknown-linux-gnu --profile=release-opt-size # Naive target: no optimizations, full std -optim0.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c decimal_bn_en.h +optim0.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c $(GCC) test.c ../../../../../target/debug/libicu_capi_staticlib.a -ldl -lpthread -lm -g -o optim0.elf # optim.elf: gcc with maximum link-time code stripping (gc-sections and strip-all) -optim1.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c decimal_bn_en.h +optim1.elf: ../../../../../target/debug/libicu_capi_staticlib.a $(ALL_HEADERS) test.c $(GCC) -fdata-sections -ffunction-sections test.c ../../../../../target/debug/libicu_capi_staticlib.a -ldl -lpthread -lm -g -o optim1.elf -Wl,--gc-sections -Wl,--strip-all # optim2.elf: clang single-step with gc-sections -optim2.elf: icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a $(ALL_HEADERS) test.c decimal_bn_en.h +optim2.elf: icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a $(ALL_HEADERS) test.c $(CLANG) -flto -fdata-sections -ffunction-sections test.c icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a -g -o optim2.elf -Wl,--gc-sections -optim3.o: $(ALL_HEADERS) test.c decimal_bn_en.h +optim3.o: $(ALL_HEADERS) test.c $(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim3.o # optim3.elf: clang two-step with lld, debug mode optim3.elf: optim3.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a $(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim3.elf optim3.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/debug/libicu_capi_staticlib_tiny.a -Wl,--gc-sections -optim4.o: $(ALL_HEADERS) test.c decimal_bn_en.h +optim4.o: $(ALL_HEADERS) test.c $(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -g -o optim4.o # optim4.elf: clang two-step with lld, release mode with debug symbols optim4.elf: optim4.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a $(CLANG) -flto=thin -fuse-ld=$(LLD) -L . -o optim4.elf optim4.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a -Wl,--gc-sections -optim5.o: $(ALL_HEADERS) test.c decimal_bn_en.h +optim5.o: $(ALL_HEADERS) test.c $(CLANG) -c -flto=thin -fdata-sections -ffunction-sections --target=x86_64-unknown-linux-gnu test.c -o optim5.o # optim5.elf: clang two-step with lld, release mode stripped of debug symbols diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock b/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock index aeb87b8ff9c..b5fe8475c2f 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock @@ -8,19 +8,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "cobs" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67ba02a97a2bd10f4b59b25c7973101c79642302776489e030cd13cdab09ed15" - -[[package]] -name = "deduplicating_array" -version = "0.1.4" -dependencies = [ - "serde", -] - [[package]] name = "diplomat" version = "0.5.2" @@ -92,15 +79,20 @@ name = "icu_calendar" version = "1.2.0" dependencies = [ "displaydoc", + "icu_calendar_data", "icu_locid", + "icu_locid_transform", "icu_provider", "libm", - "serde", "tinystr", "writeable", "zerovec", ] +[[package]] +name = "icu_calendar_data" +version = "1.3.0" + [[package]] name = "icu_capi" version = "1.2.2" @@ -121,11 +113,9 @@ dependencies = [ "icu_properties", "icu_provider", "icu_provider_adapters", - "icu_provider_blob", "icu_segmenter", "icu_timezone", "log", - "serde", "tinystr", "writeable", ] @@ -143,24 +133,28 @@ name = "icu_collator" version = "1.2.0" dependencies = [ "displaydoc", + "icu_collator_data", "icu_collections", "icu_locid", + "icu_locid_transform", "icu_normalizer", "icu_properties", "icu_provider", - "serde", "smallvec", "utf16_iter", "utf8_iter", "zerovec", ] +[[package]] +name = "icu_collator_data" +version = "1.3.0" + [[package]] name = "icu_collections" version = "1.2.0" dependencies = [ "displaydoc", - "serde", "yoke", "zerofrom", "zerovec", @@ -174,62 +168,79 @@ dependencies = [ "either", "fixed_decimal", "icu_calendar", + "icu_datetime_data", "icu_decimal", "icu_locid", + "icu_locid_transform", "icu_plurals", "icu_provider", "icu_timezone", - "litemap", - "serde", "smallvec", "tinystr", "writeable", "zerovec", ] +[[package]] +name = "icu_datetime_data" +version = "1.3.0" + [[package]] name = "icu_decimal" version = "1.2.0" dependencies = [ "displaydoc", "fixed_decimal", + "icu_decimal_data", "icu_locid", + "icu_locid_transform", "icu_provider", - "serde", "writeable", ] +[[package]] +name = "icu_decimal_data" +version = "1.3.0" + [[package]] name = "icu_displaynames" version = "0.10.0" dependencies = [ "icu_collections", + "icu_displaynames_data", "icu_locid", + "icu_locid_transform", "icu_provider", - "serde", "tinystr", "zerovec", ] +[[package]] +name = "icu_displaynames_data" +version = "1.3.0" + [[package]] name = "icu_list" version = "1.2.0" dependencies = [ - "deduplicating_array", "displaydoc", + "icu_list_data", + "icu_locid_transform", "icu_provider", "regex-automata", - "serde", "writeable", ] +[[package]] +name = "icu_list_data" +version = "1.3.0" + [[package]] name = "icu_locid" version = "1.2.0" dependencies = [ "displaydoc", "litemap", - "serde", "tinystr", "writeable", "zerovec", @@ -241,21 +252,25 @@ version = "1.2.1" dependencies = [ "displaydoc", "icu_locid", + "icu_locid_transform_data", "icu_provider", - "serde", "tinystr", "zerovec", ] +[[package]] +name = "icu_locid_transform_data" +version = "1.3.0" + [[package]] name = "icu_normalizer" version = "1.2.0" dependencies = [ "displaydoc", "icu_collections", + "icu_normalizer_data", "icu_properties", "icu_provider", - "serde", "smallvec", "utf16_iter", "utf8_iter", @@ -263,6 +278,10 @@ dependencies = [ "zerovec", ] +[[package]] +name = "icu_normalizer_data" +version = "1.3.0" + [[package]] name = "icu_plurals" version = "1.2.0" @@ -270,24 +289,34 @@ dependencies = [ "displaydoc", "fixed_decimal", "icu_locid", + "icu_locid_transform", + "icu_plurals_data", "icu_provider", - "serde", "zerovec", ] +[[package]] +name = "icu_plurals_data" +version = "1.3.0" + [[package]] name = "icu_properties" version = "1.2.0" dependencies = [ "displaydoc", "icu_collections", + "icu_locid_transform", + "icu_properties_data", "icu_provider", - "serde", "tinystr", "unicode-bidi", "zerovec", ] +[[package]] +name = "icu_properties_data" +version = "1.3.0" + [[package]] name = "icu_provider" version = "1.2.0" @@ -295,8 +324,6 @@ dependencies = [ "displaydoc", "icu_locid", "icu_provider_macros", - "postcard", - "serde", "stable_deref_trait", "writeable", "yoke", @@ -311,24 +338,11 @@ dependencies = [ "icu_locid", "icu_locid_transform", "icu_provider", - "serde", "tinystr", "yoke", "zerovec", ] -[[package]] -name = "icu_provider_blob" -version = "1.2.0" -dependencies = [ - "icu_provider", - "postcard", - "serde", - "writeable", - "yoke", - "zerovec", -] - [[package]] name = "icu_provider_macros" version = "1.2.0" @@ -346,12 +360,16 @@ dependencies = [ "icu_collections", "icu_locid", "icu_provider", + "icu_segmenter_data", "libm", - "serde", "utf8_iter", "zerovec", ] +[[package]] +name = "icu_segmenter_data" +version = "1.3.0" + [[package]] name = "icu_timezone" version = "1.2.0" @@ -360,11 +378,15 @@ dependencies = [ "icu_calendar", "icu_locid", "icu_provider", - "serde", + "icu_timezone_data", "tinystr", "zerovec", ] +[[package]] +name = "icu_timezone_data" +version = "1.3.0" + [[package]] name = "lazy_static" version = "1.4.0" @@ -386,9 +408,6 @@ checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" [[package]] name = "litemap" version = "0.7.0" -dependencies = [ - "serde", -] [[package]] name = "log" @@ -405,16 +424,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "postcard" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c2b180dc0bade59f03fd005cb967d3f1e5f69b13922dad0cd6e047cb8af2363" -dependencies = [ - "cobs", - "serde", -] - [[package]] name = "proc-macro2" version = "1.0.56" @@ -473,9 +482,6 @@ name = "smallvec" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -dependencies = [ - "serde", -] [[package]] name = "stable_deref_trait" @@ -527,7 +533,6 @@ name = "tinystr" version = "0.7.1" dependencies = [ "displaydoc", - "serde", "zerovec", ] @@ -612,7 +617,6 @@ dependencies = [ name = "zerovec" version = "0.9.4" dependencies = [ - "serde", "yoke", "zerofrom", "zerovec-derive", diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.toml b/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.toml index 5e58fa6e3fd..f6e13b20881 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.toml +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" crate-type = ["staticlib"] [dependencies] -icu_capi = { path = "../../../..", default-features = false, features = ["buffer_provider", "icu_decimal"] } +icu_capi = { path = "../../../..", default-features = false, features = ["compiled_data", "icu_decimal"] } dlmalloc = { version = "0.2", features = ["global"] } [profile.release] diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/test.c b/ffi/diplomat/c/examples/fixeddecimal_tiny/test.c index 1f5bde05d7a..880cbad1447 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/test.c +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/test.c @@ -3,7 +3,6 @@ // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). #include "../../include/ICU4XFixedDecimalFormatter.h" -#include "decimal_bn_en.h" #include #include @@ -19,12 +18,7 @@ int main(int argc, char *argv[]) { return 1; } - diplomat_result_box_ICU4XDataProvider_ICU4XError provider_result = ICU4XDataProvider_create_from_byte_slice(DECIMAL_BN_EN_POSTCARD, DECIMAL_BN_EN_POSTCARD_LEN); - if (!provider_result.is_ok) { - printf("Failed to create ICU4XDataProvider\n"); - return 1; - } - ICU4XDataProvider* provider = provider_result.ok; + ICU4XDataProvider* provider = ICU4XDataProvider_create_compiled(); ICU4XFixedDecimal* decimal = ICU4XFixedDecimal_create_from_u64(1000007); diplomat_result_box_ICU4XFixedDecimalFormatter_ICU4XError fdf_result = diff --git a/ffi/diplomat/js/examples/node/Makefile b/ffi/diplomat/js/examples/node/Makefile index 6e0bc4dd6b4..50964b5345b 100644 --- a/ffi/diplomat/js/examples/node/Makefile +++ b/ffi/diplomat/js/examples/node/Makefile @@ -34,14 +34,7 @@ lib: $(ALL_HEADERS) icu_capi.wasm: ../../../../../target/wasm32-unknown-unknown/release/icu_capi_cdylib.wasm cp ../../../../../target/wasm32-unknown-unknown/release/icu_capi_cdylib.wasm icu_capi.wasm -data.postcard: icu_capi.wasm - cargo run -p icu_datagen -- \ - --keys-for-bin icu_capi.wasm \ - --locales full \ - --format blob \ - --out data.postcard - -build: icu_capi.wasm data.postcard lib +build: icu_capi.wasm lib clean: git clean -xf * diff --git a/ffi/diplomat/js/examples/node/index.js b/ffi/diplomat/js/examples/node/index.js index 459758eeaba..4eb60931a42 100644 --- a/ffi/diplomat/js/examples/node/index.js +++ b/ffi/diplomat/js/examples/node/index.js @@ -1,12 +1 @@ export * from './lib/index.js' - -export async function fullData() { - const path = new URL('./data.postcard', import.meta.url); - if (typeof fetch === 'undefined') { // Node - const fs = await import("fs"); - return fs.readFileSync(path); - } else { // Browser - const response = await fetch(path); - return await response.arrayBuffer(); - } -} \ No newline at end of file diff --git a/ffi/diplomat/js/examples/node/test/data-providers.mjs b/ffi/diplomat/js/examples/node/test/data-providers.mjs index e8428f47746..9d1ba683504 100644 --- a/ffi/diplomat/js/examples/node/test/data-providers.mjs +++ b/ffi/diplomat/js/examples/node/test/data-providers.mjs @@ -4,11 +4,11 @@ import test from 'ava'; -import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter, fullData } from "../index.js" +import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter } from "../index.js" -test("use create_from_byte_slice to format a simple decimal", async t => { +test("use create_compiled to format a simple decimal", async t => { const locale = ICU4XLocale.create_from_string("bn"); - const provider = ICU4XDataProvider.create_from_byte_slice(await fullData()); + const provider = ICU4XDataProvider.create_compiled(); const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); @@ -17,16 +17,3 @@ test("use create_from_byte_slice to format a simple decimal", async t => { t.is(format.format(decimal), "১২.৩৪"); }); - -test("fail to create from invalid buffer", t => { - const arrayBuffer = new ArrayBuffer(8); - const bytes = new Uint8Array(arrayBuffer); - // Fill the buffer with junk data - for (let i = 0; i < bytes.length; i++) { - bytes[i] = i; - } - t.throws(() => { - const result = ICU4XDataProvider.create_from_byte_slice(bytes); - }); - -}); diff --git a/ffi/diplomat/js/examples/node/test/fixed-decimal-format.mjs b/ffi/diplomat/js/examples/node/test/fixed-decimal-format.mjs index 87329c90278..f49a0494cf0 100644 --- a/ffi/diplomat/js/examples/node/test/fixed-decimal-format.mjs +++ b/ffi/diplomat/js/examples/node/test/fixed-decimal-format.mjs @@ -4,10 +4,10 @@ import test from 'ava'; -import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter, fullData } from "../index.js" +import { ICU4XFixedDecimal, ICU4XLocale, ICU4XDataProvider, ICU4XFixedDecimalFormatter } from "../index.js" const locale = ICU4XLocale.create_from_string("bn"); -const provider = ICU4XDataProvider.create_from_byte_slice(await fullData()); +const provider = ICU4XDataProvider.create_compiled(); const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto"); test("format a simple decimal", t => { diff --git a/ffi/diplomat/js/examples/tinywasm/Makefile b/ffi/diplomat/js/examples/tinywasm/Makefile index 73e7245ae38..b80a55113e6 100755 --- a/ffi/diplomat/js/examples/tinywasm/Makefile +++ b/ffi/diplomat/js/examples/tinywasm/Makefile @@ -33,6 +33,7 @@ target/wasm32-unknown-unknown/release/icu_capi_cdylib.wasm: FORCE --target wasm32-unknown-unknown \ --release \ --package icu_capi_cdylib \ + --no-default-features --features buffer_provider,logging \ icu_capi.wasm: target/wasm32-unknown-unknown/release/icu_capi_cdylib.wasm diff --git a/ffi/diplomat/js/examples/wasm-demo/required-keys.txt b/ffi/diplomat/js/examples/wasm-demo/required-keys.txt deleted file mode 100644 index 761d4f7b79f..00000000000 --- a/ffi/diplomat/js/examples/wasm-demo/required-keys.txt +++ /dev/null @@ -1,27 +0,0 @@ -calendar/japanese@1 -calendar/japanext@1 -datetime/buddhist/datelengths@1 -datetime/buddhist/datesymbols@1 -datetime/coptic/datelengths@1 -datetime/coptic/datesymbols@1 -datetime/ethiopian/datelengths@1 -datetime/ethiopian/datesymbols@1 -datetime/ethiopic/datelengths@1 -datetime/ethiopic/datesymbols@1 -datetime/gregory/datelengths@1 -datetime/gregory/datesymbols@1 -datetime/indian/datelengths@1 -datetime/indian/datesymbols@1 -datetime/japanese/datelengths@1 -datetime/japanese/datesymbols@1 -datetime/japanext/datelengths@1 -datetime/japanext/datesymbols@1 -datetime/timelengths@1 -datetime/timesymbols@1 -decimal/symbols@1 -fallback/likelysubtags@1 -fallback/parents@1 -segmenter/dictionary/w_auto@1 -segmenter/lstm/wl_auto@1 -segmenter/grapheme@1 -segmenter/word@1 diff --git a/ffi/diplomat/js/examples/wasm-demo/src/ts/app.ts b/ffi/diplomat/js/examples/wasm-demo/src/ts/app.ts index 9c1393becb3..c0d3a7a56d8 100644 --- a/ffi/diplomat/js/examples/wasm-demo/src/ts/app.ts +++ b/ffi/diplomat/js/examples/wasm-demo/src/ts/app.ts @@ -1,4 +1,4 @@ -import { ICU4XDataProvider, fullData } from 'icu4x'; +import { ICU4XDataProvider } from 'icu4x'; import * as fdf from './fixed-decimal'; import * as dtf from './date-time'; import * as seg from './segmenter'; @@ -8,9 +8,7 @@ import 'bootstrap/js/dist/dropdown'; import 'bootstrap/js/dist/collapse'; (async function init() { - const dataProvider = ICU4XDataProvider.create_from_byte_slice(await fullData()); - dataProvider.enable_locale_fallback(); - + const dataProvider = ICU4XDataProvider.create_compiled(); fdf.setup(dataProvider); dtf.setup(dataProvider); seg.setup(dataProvider); diff --git a/provider/datagen/src/lib.rs b/provider/datagen/src/lib.rs index 4e1443d2227..f95c1901f04 100644 --- a/provider/datagen/src/lib.rs +++ b/provider/datagen/src/lib.rs @@ -336,11 +336,17 @@ impl DatagenProvider { locale: &locale, metadata: Default::default(), }; - let payload = provider + match provider .load_data(key, req) - .and_then(DataResponse::take_payload) - .map_err(|e| e.with_req(key, req))?; - exporter.put_payload(key, &locale, &payload).map_err(|e| e.with_key(key)) + .and_then(DataResponse::take_payload) { + Err(DataError { kind: DataErrorKind::MissingLocale, ..}) => { + // well, we tried + Ok(()) + }, + Ok(payload) => exporter.put_payload(key, &locale, &payload), + e => e.map(|_| ()) + } + .map_err(|e| e.with_req(key, req)) })?; exporter.flush_with_fallback(key, icu_provider::datagen::FallbackMode::None) .map_err(|e| e.with_key(key))