Browse documentation

WebAssembly modules link ICU4C and read its data from a file the host offers

Date: 2026-12-03 Area: build, apps, runtime Refines: ADR 0235, whose modules had no ICU, and ADR 0045, whose embedded CLDR resource no longer formats Related: ADR 0244, ADR 0237, ADR 0189

Context

Every Intl formatter, collator and segmenter takes its locale data from ICU, which the native builds load as a shared library. A wasm32-wasip1 module loads none, so on WebAssembly Intl had no locale data, and 39 test files failed for it (tests/wasm-known-failures.txt). The playground runs scripts in the browser by default only once ICU is in the module (#2538).

ICU4C 79.1 builds for wasm32-wasip1 with wasi-sdk 34's clang from configure options alone, and since ADR 0244 the modules link with wasm-ld, which links C and C++ libraries. fpc-toolchain 3.3.1+12 ships wasi-sdk's sysroot (libc, libc++, libc++abi, compiler-rt) and the RTL unit wasilibc, which puts C's malloc on FreePascal's heap and runs C++ constructors. It ships no C compiler.

ICU's data for every locale is 33.6 MB raw, 8.2 MB brotli. Johannes decided on 2 December 2026 that the data is "a separate data file", for "20 + test locales".

Decision

  • ICU is linked into the modules. scripts/build-wasm-icu.sh builds ICU 79.1 from its sources with wasi-sdk 34's clang (-Oz, no exceptions, no memory mapping, no legacy converters), each download pinned by SHA-256. With GOCCIA_WASM_ICU naming that build, build.pas defines GOCCIA_STATIC_ICU for wasm32-wasip1, and ICU.pas links ICU's libraries, the C++ runtime and wasilibc. CI builds every module so, caching ICU's build by the hash of the script, the data filter and the function table, and the releases and the nightly ship them.
  • Functions come from a table. ICU.pas resolves each ICU function by name, as on the native builds, from scripts/wasm-icu/icu-symbols.c, which a script writes from the names the sources resolve. Compiled with ICU's headers, every entry has the function's versioned name and real signature, which a call through a WebAssembly function table must match. CI fails when the table is out of date.
  • The data is a file of its own. icudt79l.dat holds the 20 locales of scripts/generate-intl-data.js, az and si, which the test suite uses, and ICU's root, without converter tables, transliteration, character names, spellout rules, StringPrep, confusables, or break dictionaries other than Chinese, Japanese and Thai. Another locale is not supported, so locale matching falls back to the default locale, as for any locale ICU lacks.
  • The host offers it at /.goccia/icu. On the module's first use of ICU, ICU.pas points ICU at that directory, and ICU reads the file whole into memory. A host that offers no such directory leaves the module without ICU, so it runs as before. Node's host offers it with scripts/run-wasi.js --icu-data; the release archive carries it under icu/, with ICU's license as ICU-LICENSE.txt.
  • The embedded CLDR resource does not format. ADR 0045 named it the fallback for every Intl operation. Since the engine rewrite (#2187) it answers locale aliases, plural categories, relative time patterns, a currency's default digits and parts of Intl.Locale's information; without ICU, numbers, dates, lists and display names format without locale data and collation compares code units, on every platform.

Consequences

  • The 39 files leave tests/wasm-known-failures.txt, which now describes a module with ICU linked in and its data offered. A RegExp property escape or identifier property the embedded Unicode tables lack is now asked of ICU, as on the native builds.

  • Sizes of the --prod modules and the data (bytes; gzip -9, brotli -q 11):

    FileWithout ICUWith ICU
    GocciaRunner raw14,822,96316,597,930
    GocciaRunner gzip3,258,5923,892,569
    GocciaRunner brotli2,086,7432,603,917
    GocciaTestRunner raw14,685,53516,460,508
    GocciaTestRunner gzip3,214,4633,848,942
    GocciaTestRunner brotli2,058,2852,574,707
    icudt79l.dat raw / gzip / brotli9,564,192 / 4,182,194 / 3,166,810
  • The modules import 25 WASI functions: ICU's C library adds fd_fdstat_set_flags, which the browser's WASI host now provides.

  • Building the modules with ICU needs a C++ compiler, make and python3 on the host for ICU's own build. A build without GOCCIA_WASM_ICU still has no ICU.

  • Adding an ICU function to the engine regenerates the table, and so rebuilds ICU in CI once.

  • ICU's data, time zones included, is 79.1's, whatever data the engine embeds for Temporal.