Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use compiled data for tinywasm #4163

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,6 @@ jobs:
- name: Install lld-15
run: |
apt-get install -y lld-15
- name: Attempt to load download cache
uses: actions/cache@v3
with:
key: download-cache
path: /tmp/icu4x-source-cache

# Actual job
- name: Run `cargo make ci-job-test-js`
Expand Down
1 change: 0 additions & 1 deletion ffi/capi/js/examples/tinywasm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
lib
icu_capi.wasm
data.postcard
16 changes: 2 additions & 14 deletions ffi/capi/js/examples/tinywasm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,18 @@ target/wasm32-unknown-unknown/release/icu_capi_cdylib.wasm: FORCE
rustup toolchain install ${ICU4X_NIGHTLY_TOOLCHAIN}
rustup component add rust-src --toolchain ${ICU4X_NIGHTLY_TOOLCHAIN}
# Build the WASM library
# NOTE: the --features below only work within the workspace. Outside of the workspace, you should
# create your own cdylib crate that depends on icu_capi and enables the features you need.
RUSTFLAGS="-Cpanic=abort -Copt-level=s -C link-arg=-zstack-size=${WASM_STACK_SIZE} -Clinker-plugin-lto -Ccodegen-units=1 -C linker=${BASEDIR}/ld.py -C linker-flavor=wasm-ld" \
CARGO_TARGET_DIR="target" `# Special linker flags shouldn't overwrite the top-level target directory` \
cargo +${ICU4X_NIGHTLY_TOOLCHAIN} build \
-Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort \
--target wasm32-unknown-unknown \
--release \
--package icu_capi_cdylib \
--no-default-features \
--features buffer_provider,logging,icu_capi/icu_decimal
--package icu_capi_cdylib

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 \
--overwrite

build: icu_capi.wasm data.postcard lib
build: icu_capi.wasm lib

clean:
git clean -xf *
3 changes: 1 addition & 2 deletions ffi/capi/js/examples/tinywasm/delete_fetch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

// diplomat-wasm.mjs uses fetch when available, but fetch in Node.js is broken,
// so delete the function to force the wasm to be loaded via the fs module.
// The Node.js fetch bug may be related to this issue:
// <https://github.com/nodejs/undici/issues/1248>
// See <https://github.com/rust-diplomat/diplomat/issues/283>.
delete globalThis.fetch;
5 changes: 1 addition & 4 deletions ffi/capi/js/examples/tinywasm/ld.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import subprocess

SYMBOLS = [
"ICU4XDataProvider_create_from_byte_slice",
"ICU4XDataProvider_create_compiled",
"ICU4XDataProvider_destroy",
"ICU4XFixedDecimal_create_from_i32",
"ICU4XFixedDecimal_destroy",
Expand All @@ -29,9 +29,6 @@ def main():
is_export = False
elif arg == "--export":
is_export = True
elif arg == "--export-dynamic":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_export = False
# skip
else:
new_argv += [arg]
is_export = False
Expand Down
5 changes: 1 addition & 4 deletions ffi/capi/js/examples/tinywasm/tiny.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import { ICU4XLocale } from "./lib/ICU4XLocale.js";
import { ICU4XDataProvider } from "./lib/ICU4XDataProvider.js";
import { ICU4XFixedDecimalFormatter } from "./lib/ICU4XFixedDecimalFormatter.js";
import { ICU4XFixedDecimal } from "./lib/ICU4XFixedDecimal.js";
import { readFileSync } from "fs";

const data = readFileSync("data.postcard");

async function main() {
const locale = ICU4XLocale.create_from_string("bn");
const provider = ICU4XDataProvider.create_from_byte_slice(data);
const provider = ICU4XDataProvider.create_compiled();

const format = ICU4XFixedDecimalFormatter.create_with_grouping_strategy(provider, locale, "Auto");

Expand Down