Skip to content

Commit

Permalink
Add (non-wprking) cpp-to-wasm test
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Aug 18, 2021
1 parent fa61b29 commit 191b239
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion ffi/cpp/examples/fixeddecimal/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ a.out: ../../../../target/debug/libicu_capi.a $(ALL_HEADERS) test.cpp
build: a.out

test: build
./a.out
./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
7 changes: 6 additions & 1 deletion ffi/cpp/examples/fixeddecimal/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

#include <iostream>

#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();

Expand Down

0 comments on commit 191b239

Please sign in to comment.