From 93dae0d6e9269fc834a544d6e0533a302ba39705 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Mon, 14 Aug 2023 17:34:56 -0700 Subject: [PATCH] Add segmenter_tiny example --- .../c/examples/fixeddecimal_tiny/.gitignore | 3 +- .../c/examples/fixeddecimal_tiny/Makefile | 2 + .../icu_capi_staticlib_tiny/Cargo.lock | 636 ------------------ .../c/examples/segmenter_tiny/.gitignore | 9 + .../c/examples/segmenter_tiny/Makefile | 80 +++ .../c/examples/segmenter_tiny/README.md | 5 + .../icu_capi_staticlib_tiny/Cargo.toml | 25 + .../icu_capi_staticlib_tiny/src/lib.rs | 27 + ffi/diplomat/c/examples/segmenter_tiny/test.c | 42 ++ tools/make/ffi.toml | 3 + 10 files changed, 195 insertions(+), 637 deletions(-) delete mode 100644 ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/.gitignore create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/Makefile create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/README.md create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/Cargo.toml create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/src/lib.rs create mode 100644 ffi/diplomat/c/examples/segmenter_tiny/test.c diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore b/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore index d6a0fdc9a56..705fd9f46d3 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/.gitignore @@ -5,4 +5,5 @@ optim* *.elf *.o a.out.dSYM -baked_data \ No newline at end of file +baked_data +icu_capi_staticlib_tiny/Cargo.lock diff --git a/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile b/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile index edd7004b8c5..77452a332fb 100644 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile +++ b/ffi/diplomat/c/examples/fixeddecimal_tiny/Makefile @@ -2,6 +2,8 @@ # called LICENSE at the top level of the ICU4X source tree # (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +# PLEASE KEEP THIS FILE IN SYNC WITH ../segmenter_tiny/Makefile + .DEFAULT_GOAL := test .PHONY: build test FORCE: 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 deleted file mode 100644 index eb9ad0f670f..00000000000 --- a/ffi/diplomat/c/examples/fixeddecimal_tiny/icu_capi_staticlib_tiny/Cargo.lock +++ /dev/null @@ -1,636 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "diplomat" -version = "0.5.2" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8d125999893fedfdf30595e97334c21ec4b18da9#8d125999893fedfdf30595e97334c21ec4b18da9" -dependencies = [ - "diplomat_core", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "diplomat-runtime" -version = "0.5.2" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8d125999893fedfdf30595e97334c21ec4b18da9#8d125999893fedfdf30595e97334c21ec4b18da9" - -[[package]] -name = "diplomat_core" -version = "0.5.2" -source = "git+https://github.com/rust-diplomat/diplomat?rev=8d125999893fedfdf30595e97334c21ec4b18da9#8d125999893fedfdf30595e97334c21ec4b18da9" -dependencies = [ - "lazy_static", - "proc-macro2", - "quote", - "serde", - "smallvec", - "strck_ident", - "syn", -] - -[[package]] -name = "displaydoc" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "dlmalloc" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "203540e710bfadb90e5e29930baf5d10270cec1f43ab34f46f78b147b2de715a" -dependencies = [ - "libc", -] - -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - -[[package]] -name = "fixed_decimal" -version = "0.5.3" -dependencies = [ - "displaydoc", - "ryu", - "smallvec", - "writeable", -] - -[[package]] -name = "icu_calendar" -version = "1.2.0" -dependencies = [ - "displaydoc", - "icu_calendar_data", - "icu_locid", - "icu_locid_transform", - "icu_provider", - "libm", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_calendar_data" -version = "1.3.0" - -[[package]] -name = "icu_capi" -version = "1.2.2" -dependencies = [ - "diplomat", - "diplomat-runtime", - "fixed_decimal", - "icu_calendar", - "icu_casemap", - "icu_collator", - "icu_datetime", - "icu_decimal", - "icu_displaynames", - "icu_list", - "icu_locid", - "icu_locid_transform", - "icu_normalizer", - "icu_plurals", - "icu_properties", - "icu_provider", - "icu_provider_adapters", - "icu_segmenter", - "icu_timezone", - "tinystr", - "writeable", -] - -[[package]] -name = "icu_capi_staticlib_tiny" -version = "0.0.0" -dependencies = [ - "dlmalloc", - "icu_capi", -] - -[[package]] -name = "icu_casemap" -version = "0.7.2" -dependencies = [ - "displaydoc", - "icu_casemap_data", - "icu_collections", - "icu_locid", - "icu_provider", - "writeable", - "yoke", - "zerovec", -] - -[[package]] -name = "icu_casemap_data" -version = "1.3.0" - -[[package]] -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", - "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", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_datetime" -version = "1.2.1" -dependencies = [ - "displaydoc", - "either", - "fixed_decimal", - "icu_calendar", - "icu_datetime_data", - "icu_decimal", - "icu_locid", - "icu_locid_transform", - "icu_plurals", - "icu_provider", - "icu_timezone", - "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", - "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", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_displaynames_data" -version = "1.3.0" - -[[package]] -name = "icu_list" -version = "1.2.0" -dependencies = [ - "displaydoc", - "icu_list_data", - "icu_locid_transform", - "icu_provider", - "regex-automata", - "writeable", -] - -[[package]] -name = "icu_list_data" -version = "1.3.0" - -[[package]] -name = "icu_locid" -version = "1.2.0" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_locid_transform" -version = "1.2.1" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "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", - "smallvec", - "utf16_iter", - "utf8_iter", - "write16", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "1.3.0" - -[[package]] -name = "icu_plurals" -version = "1.2.0" -dependencies = [ - "displaydoc", - "fixed_decimal", - "icu_locid", - "icu_locid_transform", - "icu_plurals_data", - "icu_provider", - "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", - "tinystr", - "unicode-bidi", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "1.3.0" - -[[package]] -name = "icu_provider" -version = "1.2.0" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_provider_macros", - "stable_deref_trait", - "writeable", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_provider_adapters" -version = "1.2.0" -dependencies = [ - "icu_locid", - "icu_locid_transform", - "icu_provider", - "tinystr", - "yoke", - "zerovec", -] - -[[package]] -name = "icu_provider_macros" -version = "1.2.0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "icu_segmenter" -version = "1.2.1" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locid", - "icu_provider", - "icu_segmenter_data", - "libm", - "utf8_iter", - "zerovec", -] - -[[package]] -name = "icu_segmenter_data" -version = "1.3.0" - -[[package]] -name = "icu_timezone" -version = "1.2.0" -dependencies = [ - "displaydoc", - "icu_calendar", - "icu_locid", - "icu_provider", - "icu_timezone_data", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_timezone_data" -version = "1.3.0" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.126" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" - -[[package]] -name = "libm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" - -[[package]] -name = "litemap" -version = "0.7.0" - -[[package]] -name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "proc-macro2" -version = "1.0.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex-automata" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9368763f5a9b804326f3af749e16f9abf378d227bcdee7634b13d8f17793782" -dependencies = [ - "memchr", -] - -[[package]] -name = "ryu" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" - -[[package]] -name = "serde" -version = "1.0.160" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.160" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - -[[package]] -name = "strck" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be91090ded9d8f979d9fe921777342d37e769e0b6b7296843a7a38247240e917" - -[[package]] -name = "strck_ident" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1c3802b169b3858a44667f221c9a0b3136e6019936ea926fc97fbad8af77202" -dependencies = [ - "strck", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "synstructure" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "unicode-xid", -] - -[[package]] -name = "tinystr" -version = "0.7.1" -dependencies = [ - "displaydoc", - "zerovec", -] - -[[package]] -name = "unicode-bidi" -version = "0.3.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" - -[[package]] -name = "unicode-ident" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" - -[[package]] -name = "unicode-xid" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" - -[[package]] -name = "utf16_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52df8b7fb78e7910d776fccf2e42ceaf3604d55e8e7eb2dbd183cb1441d8a692" - -[[package]] -name = "utf8_iter" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a8922555b9500e3d865caed19330172cd67cbf82203f1a3311d8c305cc9f33" - -[[package]] -name = "write16" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" - -[[package]] -name = "writeable" -version = "0.5.2" - -[[package]] -name = "yoke" -version = "0.7.1" -dependencies = [ - "serde", - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.7.1" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zerofrom" -version = "0.1.2" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.2" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zerovec" -version = "0.9.4" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.9.4" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] diff --git a/ffi/diplomat/c/examples/segmenter_tiny/.gitignore b/ffi/diplomat/c/examples/segmenter_tiny/.gitignore new file mode 100644 index 00000000000..705fd9f46d3 --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/.gitignore @@ -0,0 +1,9 @@ +a.out +optim* +*.i64 +*.dot +*.elf +*.o +a.out.dSYM +baked_data +icu_capi_staticlib_tiny/Cargo.lock diff --git a/ffi/diplomat/c/examples/segmenter_tiny/Makefile b/ffi/diplomat/c/examples/segmenter_tiny/Makefile new file mode 100644 index 00000000000..2890c02a83c --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/Makefile @@ -0,0 +1,80 @@ +# 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 ). + +# PLEASE KEEP THIS FILE IN SYNC WITH ../fixeddecimal_tiny/Makefile + +.DEFAULT_GOAL := test +.PHONY: build test +FORCE: + +ALL_HEADERS := $(wildcard ../../include/*.h) +ICU4X_NIGHTLY_TOOLCHAIN ?= "nightly-2022-09-26" + +$(ALL_HEADERS): + +GCC := gcc +CLANG := clang-15 +LLD := lld-15 + +../../../../../target/debug/libicu_capi_staticlib.a: FORCE + 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 + 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 + +icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a: FORCE + 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 + +# Naive target: no optimizations, full std +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 + $(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 + $(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 + $(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 + $(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 + $(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 +optim5.elf: optim5.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 optim5.elf optim5.o icu_capi_staticlib_tiny/target/x86_64-unknown-linux-gnu/release-opt-size/libicu_capi_staticlib_tiny.a -Wl,--gc-sections -Wl,--strip-all + +build: optim0.elf optim1.elf optim2.elf optim3.elf optim4.elf optim5.elf + +test: build + ./optim0.elf + ./optim1.elf + ./optim2.elf + ./optim2.elf + ./optim4.elf + ./optim5.elf + +clean: + git clean -xf * + rm -f ../../../../../target/debug/libicu_capi_staticlib.a diff --git a/ffi/diplomat/c/examples/segmenter_tiny/README.md b/ffi/diplomat/c/examples/segmenter_tiny/README.md new file mode 100644 index 00000000000..2832999da82 --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/README.md @@ -0,0 +1,5 @@ +# Tiny Segmenter FFI Demo + +This example contains tooling to build a size-optimized binary using Segmenter in C over FFI. + +For more information and prerequisites, see ../fixeddecimal_tiny/README.md diff --git a/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/Cargo.toml b/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/Cargo.toml new file mode 100644 index 00000000000..cc4727558cf --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/Cargo.toml @@ -0,0 +1,25 @@ +# 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_capi_staticlib_tiny" +publish = false +version = "0.0.0" +edition = "2021" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +icu_capi = { path = "../../../..", default-features = false, features = ["compiled_data", "icu_segmenter"] } +dlmalloc = { version = "0.2", features = ["global"] } + +[profile.release] +lto = true + +[profile.release-opt-size] +inherits = "release" +opt-level = "s" + +[workspace] \ No newline at end of file diff --git a/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/src/lib.rs b/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/src/lib.rs new file mode 100644 index 00000000000..aab46a885d5 --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/icu_capi_staticlib_tiny/src/lib.rs @@ -0,0 +1,27 @@ +// 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 ). + +#![feature(alloc_error_handler)] +#![no_std] + +extern crate icu_capi; + +extern crate dlmalloc; + +use core::alloc::Layout; +use core::panic::PanicInfo; +use dlmalloc::GlobalDlmalloc; + +#[global_allocator] +static ALLOCATOR: GlobalDlmalloc = GlobalDlmalloc; + +#[alloc_error_handler] +fn alloc_error(_layout: Layout) -> ! { + loop {} +} + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} diff --git a/ffi/diplomat/c/examples/segmenter_tiny/test.c b/ffi/diplomat/c/examples/segmenter_tiny/test.c new file mode 100644 index 00000000000..f9814eec2ba --- /dev/null +++ b/ffi/diplomat/c/examples/segmenter_tiny/test.c @@ -0,0 +1,42 @@ +// 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 ). + +#include "../../include/ICU4XLineSegmenter.h" +#include +#include + +int main(int argc, char *argv[]) { + ICU4XDataProvider* provider = ICU4XDataProvider_create_compiled(); + + diplomat_result_box_ICU4XLineSegmenter_ICU4XError segmenter_result = ICU4XLineSegmenter_create_auto(provider); + if (!segmenter_result.is_ok) { + printf("Failed to create ICU4XLineSegmenter\n"); + return 1; + } + ICU4XLineSegmenter* segmenter = segmenter_result.ok; + + char output[40]; + DiplomatWriteable write = diplomat_simple_writeable(output, 40); + + const char* data = "อักษรไทย เป็นอักษรที่ใช้เขียนภาษาไทยและภาษาของกลุ่มชาติพันธุ์ต่างๆ เช่น คำเมือง, อีสาน, ภาษาไทยใต้, มลายูปัตตานี เป็นต้น ในประเทศไทย มีพยัญชนะ 44 รูป สระ 21 รูป วรรณยุกต์ 4 รูป และเครื่องหมายอื่น ๆ อีกจำนวนหนึ่ง"; + + ICU4XLineBreakIteratorUtf8* iter = ICU4XLineSegmenter_segment_utf8(segmenter, data, strlen(data)); + + printf("Breakpoints:"); + while (true) { + int32_t breakpoint = ICU4XLineBreakIteratorUtf8_next(iter); + if (breakpoint == -1) { + break; + } + printf(" %d", breakpoint); + } + + printf("\n"); + + ICU4XLineBreakIteratorUtf8_destroy(iter); + ICU4XLineSegmenter_destroy(segmenter); + ICU4XDataProvider_destroy(provider); + + return 0; +} diff --git a/tools/make/ffi.toml b/tools/make/ffi.toml index fe8f04493de..7377df411db 100644 --- a/tools/make/ffi.toml +++ b/tools/make/ffi.toml @@ -126,6 +126,9 @@ else cd ffi/diplomat/c/examples/fixeddecimal_tiny exec --fail-on-error make exec ls -l + cd ../segmenter_tiny + exec --fail-on-error make + exec ls -l end '''