Skip to content

Commit

Permalink
Add host test to test-ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Aug 24, 2021
1 parent 8c276dc commit 2ef0e6e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions ffi/cpp/examples/fixeddecimal_wasm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node-version.js
node-version.wasm
package-lock.json
node_modules
a.out
17 changes: 16 additions & 1 deletion ffi/cpp/examples/fixeddecimal_wasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

.DEFAULT_GOAL := build
.PHONY: build test clean serve
.PHONY: build test clean serve build-host test-host

ALL_HEADERS := $(wildcard ../../include/*.hpp) $(wildcard ../../../capi/include/*.h)
ALL_RUST := $(wildcard ../../../capi//src/*.rs)
Expand All @@ -12,6 +12,12 @@ $(ALL_RUST):

$(ALL_HEADERS):

../../../../target/debug/libicu_capi.a: $(ALL_RUST)
cargo build -p icu_capi

a.out: ../../../../target/debug/libicu_capi.a $(ALL_HEADERS) test.cpp
g++ -std=c++17 test.cpp ../../../../target/debug/libicu_capi.a -ldl -lpthread -lm -g

../../../../target/wasm32-unknown-emscripten/release/libicu_capi.a: $(ALL_RUST)
RUSTFLAGS="-Cpanic=abort" cargo +nightly build --release -p icu_capi --target wasm32-unknown-emscripten -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort

Expand All @@ -29,10 +35,19 @@ test: node-version.js
serve: web-version.html
emrun web-version.html

# These make it possible to ensure that the C++ code is up to date with the bindings
# without needing to set up emsdk. This way `make test-ffi` works without emsdk.
build-host: a.out

test-host: build-host
./a.out

clean:
rm -f web-version.html
rm -f web-version.wasm
rm -f web-version.js
rm -f node-version.js
rm -f node-version.wasm
rm -f ../../../../target/wasm32-unknown-emscripten/release/libicu_capi.a
rm -f ../../../../target/debug/libicu_capi.a
rm -f a.out
6 changes: 6 additions & 0 deletions ffi/cpp/examples/fixeddecimal_wasm/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#ifdef __EMSCRIPTEN__
#include <emscripten/bind.h>
#endif

#include "../../include/ICU4XFixedDecimalFormat.hpp"

Expand All @@ -14,7 +16,9 @@ extern "C" void log_js(char* s) {
}

int runFixedDecimal() {
#ifdef __EMSCRIPTEN__
diplomat_init();
#endif
ICU4XLocale locale = ICU4XLocale::create("bn").value();
std::cout << "Running test for locale " << locale.tostring().ok().value() << std::endl;
ICU4XDataProvider dp = ICU4XDataProvider::create_static().provider.value();
Expand Down Expand Up @@ -48,9 +52,11 @@ int runFixedDecimal() {
return 0;
}

#ifdef __EMSCRIPTEN__
EMSCRIPTEN_BINDINGS(testFixedDecimal) {
emscripten::function("runFixedDecimal", &runFixedDecimal);
}
#endif

#ifndef NOMAIN
int main() {
Expand Down
2 changes: 2 additions & 0 deletions tools/scripts/ffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ cd ffi/cpp/examples/pluralrules
exec --fail-on-error make
cd ../fixeddecimal
exec --fail-on-error make
cd ../fixeddecimal_wasm
exec --fail-on-error make test-host
'''

[tasks.test-cppdoc]
Expand Down

0 comments on commit 2ef0e6e

Please sign in to comment.