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.shbuilds 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. WithGOCCIA_WASM_ICUnaming that build,build.pasdefinesGOCCIA_STATIC_ICUforwasm32-wasip1, andICU.paslinks ICU's libraries, the C++ runtime andwasilibc. 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.pasresolves each ICU function by name, as on the native builds, fromscripts/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.datholds the 20 locales ofscripts/generate-intl-data.js,azandsi, 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.paspoints 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 withscripts/run-wasi.js --icu-data; the release archive carries it undericu/, with ICU's license asICU-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
--prodmodules and the data (bytes; gzip-9, brotli-q 11):File Without ICU With ICU GocciaRunnerraw14,822,963 16,597,930 GocciaRunnergzip3,258,592 3,892,569 GocciaRunnerbrotli2,086,743 2,603,917 GocciaTestRunnerraw14,685,535 16,460,508 GocciaTestRunnergzip3,214,463 3,848,942 GocciaTestRunnerbrotli2,058,285 2,574,707 icudt79l.datraw / 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,
makeandpython3on the host for ICU's own build. A build withoutGOCCIA_WASM_ICUstill 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.