From 91bc24d689f61c9c42916d0eb111396eb36bd5b3 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Wed, 18 Aug 2021 10:40:38 -0700 Subject: [PATCH] Add (non-wprking) cpp-to-wasm test --- ffi/cpp/examples/fixeddecimal/Makefile | 10 +++++++++- ffi/cpp/examples/fixeddecimal/test.cpp | 7 ++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ffi/cpp/examples/fixeddecimal/Makefile b/ffi/cpp/examples/fixeddecimal/Makefile index 07725ba397f..e068e2af7d7 100644 --- a/ffi/cpp/examples/fixeddecimal/Makefile +++ b/ffi/cpp/examples/fixeddecimal/Makefile @@ -22,4 +22,12 @@ a.out: ../../../../target/debug/libicu_capi.a $(ALL_HEADERS) test.cpp build: a.out test: build - ./a.out \ No newline at end of file + ./a.out + + +../../../../target/wasm32-unknown-unknown/debug/libicu_capi.a: $(ALL_RUST) + cargo +nightly build -p icu_capi --target wasm32-unknown-unknown -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort + +# Currently this doesn't run successfully, however it's the status quo of compiling ICU4X in C++ to WASM +main.html: ../../../../target/wasm32-unknown-unknown/debug/libicu_capi.a $(ALL_HEADERS) test.cpp + emcc -std=c++17 test.cpp ../../../../target/wasm32-unknown-unknown/debug/libicu_capi.a -ldl -lpthread -lm -DWASM -g -o main.html --emrun -sWASM=1 diff --git a/ffi/cpp/examples/fixeddecimal/test.cpp b/ffi/cpp/examples/fixeddecimal/test.cpp index 691377690c8..909f66a5fce 100644 --- a/ffi/cpp/examples/fixeddecimal/test.cpp +++ b/ffi/cpp/examples/fixeddecimal/test.cpp @@ -6,13 +6,18 @@ #include +#ifndef WASM const std::string_view path = "../../../../provider/testdata/data/json/"; +#endif int main() { ICU4XLocale locale = ICU4XLocale::create("bn").value(); std::cout << "Running test for locale " << locale.tostring().ok().value() << std::endl; +#ifdef WASM + ICU4XDataProvider dp = ICU4XDataProvider::create_static().provider.value(); +#else ICU4XDataProvider dp = ICU4XDataProvider::create_fs(path).provider.value(); - +#endif ICU4XFixedDecimalFormatOptions opts = {ICU4XFixedDecimalGroupingStrategy::Auto, ICU4XFixedDecimalSignDisplay::Auto}; ICU4XFixedDecimalFormat fdf = ICU4XFixedDecimalFormat::try_new(locale, dp, opts).fdf.value();