Skip to content

0.2.2: Emscripten (wasm32-emscripten) - #8

Closed
Sunrisepeak wants to merge 1 commit into
os-0.2.1from
os-emscripten
Closed

Sunrisepeak wants to merge 1 commit into
os-0.2.1from
os-emscripten

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Stacked on #7 (os-0.2.1). When #7 merges, GitHub retargets this PR to main.

mcpplibs.os had no wasm32-emscripten target. A program that imports it, such as openmui's web build, stops at the first module:

warning: src/platform.cppm: module 'mcpplibs.os.platform:target' imported but not provided in this build
ninja: error: 'pcm.cache/mcpplibs.os.platform-target.pcm' ... missing and no known rule to make it

This adds the target over Emscripten's C library and openkal-emscripten 0.6.0 (mcpplibs/openkal-emscripten#8, which brings it to openkal 0.17.1). Running the tests on the target also found three defects that are not specific to Emscripten.

The target

  • Platform and architecture. platform::emscripten, architecture::wasm32 and is_emscripten. They are selected by src/targets/emscripten.cppm and src/arch/wasm32.cppm. host() is a constant expression, as on a native target.
  • Dependency. [target.'cfg(os = "emscripten")'.dependencies] openkal-emscripten = "0.6.0".
  • Implementation units in src/emscripten/:
    • machine: wasm32. The processor count is the one Emscripten reports (the host's in a -pthread link, otherwise one), and the memory is unknown.
    • library: not supported. A wasm module loads another only when it is linked with -sMAIN_MODULE.
    • exec replaces no program's image, and the terminal is always in the foreground.
    • Standard output is diverted with the C library's dup/dup2, because openkal-emscripten's streams are the C library's descriptors.
    • A volume's kind is the file system Emscripten mounted there (memfs, nodefs, idbfs, …), asked of its FS.
    • Durability and ownership come from the C library's part of src/posix/fs.cpp.
  • interrupt. Without openkal.process there is no stop word, so available() and requested() are false and end_as_requested() does nothing. The openkal implementation moves unchanged to src/kal/interrupt.cpp, which cfg(not(os = "emscripten")) selects. Before this change, a program that called interrupt::available() did not link on Emscripten.
  • Starting a program is absent, not failing. openkal-emscripten provides no openkal.process, so process::self, run, spawn and so on fail at link, naming the openkal symbol. checks/absent asserts this in CI. process.o is linked into every program, but wasm-ld reports only undefined symbols that are reached, so a program that does not start one links.

Defects found on the way (they affect every target)

  1. fs::read overflowed a wasm module's whole stack. It read through char buf[65536] on the stack, and Emscripten's default stack is 65536 bytes ("Stack overflow detected"). It now reads into the string's own storage (resize_and_overwrite), which also saves a copy.
  2. stamp_of and identity_of reported existing files as not found. info() asked openkal only for the size, time or identity, then read kind to detect absence. openkal says an implementation fills only the fields that are asked for, and openkal-emscripten does exactly that, so kind stayed 0 (kal_node_absent). info() now also asks for the kind.
  3. The tests assumed locks and no-replace renames on every volume. They now ask caps() first. On a volume that has neither, they check that the request is refused with not_supported and changes nothing. fs_test names its scratch directory with random bytes where no program can be named.

CI

A new emscripten (node) dev/release job:

  • runs the five suites that start no program (checks/emscripten, the package's own tests by #include) under node;
  • builds checks/constants for the target;
  • asserts the link failure in checks/absent.

Until openkal-emscripten 0.6.0 is in the index, those three check projects pin it by git rev from the root, which the root's declaration allows. The comment says to remove the pin when the release is published. The package's own manifest names the version, "0.6.0".

Measured locally

  • emsdk 6.0.9 and node 26.7.0: checks/emscripten passes 5 of 5 with --profile dev and with --profile release.
  • checks/constants builds for wasm. checks/discarded links and checks/misuse fails naming the three platform functions, as on native.
  • Native [email protected] on Linux: 7 of 7 tests pass. (The local mcpp, 2026.10.26.1, predates the GCC module-map fix that CI's pin has, so GCC was left to CI.)

Release order

  1. openkal-emscripten#8 merged and tagged 0.6.0.
  2. mcpp-index gains openkal-emscripten 0.6.0.
  3. 0.2.1: os over the program's own C library on every host #7, then this PR, merged and tagged 0.2.2.
  4. mcpp-index gains os 0.2.2.
  5. The git pins in checks/ are removed.

…en's C library and openkal-emscripten 0.6.0; fs::read without a 64 KiB stack array; an enquiry asks for the kind it reads absence from
@Sunrisepeak
Sunrisepeak deleted the branch os-0.2.1 October 28, 2026 13:55
Sunrisepeak added a commit that referenced this pull request Oct 28, 2026
…en's C library and openkal-emscripten 0.6.0; fs::read without a 64 KiB stack array; an enquiry asks for the kind it reads absence from (#9)

Replaces #8 (closed when its base branch was deleted).

- **Emscripten (`wasm32-emscripten`).** A wasm module over Emscripten's C library and openkal-emscripten 0.6.0, under node or in a page: `platform::emscripten`, `architecture::wasm32`, `is_emscripten`; `src/targets/emscripten.cppm`, `src/arch/wasm32.cppm`, `src/emscripten/` and the C library's part of `src/posix/fs.cpp`. No platform module is defined. A program that starts another fails at link, naming the openkal symbol (`checks/absent`). `interrupt` reports that no request to end is delivered; its openkal implementation moves to `src/kal/interrupt.cpp`.
- **`fs::read` reads into the string**, not through a 64 KiB array on the stack (all of a wasm module's default stack).
- **An enquiry asks for the kind it reads absence from** (`stamp_of`, `identity_of` reported existing files not found where an implementation fills only the fields asked for).
- CI: `emscripten (node) dev/release` runs the five suites that start no program under node, builds `checks/constants` for the target and asserts the link failure in `checks/absent`. The checks resolve openkal-emscripten 0.6.0 from the index (mcpplibs/mcpp-index#618).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant