Skip to content

0.2.2: Emscripten (wasm32-emscripten) - #9

Merged
Sunrisepeak merged 2 commits into
mainfrom
os-0.2.2-emscripten
Oct 28, 2026
Merged

Sunrisepeak merged 2 commits into
mainfrom
os-0.2.2-emscripten

Conversation

@Sunrisepeak

Copy link
Copy Markdown
Member

Replaces #8, which GitHub closed when its base branch (#7's os-0.2.1) was deleted after #7 was squash-merged. The same commit, cherry-picked onto main, plus one commit that removes the temporary git pins now that openkal-emscripten 0.6.0 is in the index.

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, merged and tagged 0.6.0, which brings it to openkal 0.17.1; in the index since mcpplibs/mcpp-index#618). 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.

The three check projects resolve openkal-emscripten 0.6.0 from the index (the git rev pins of #8 are removed; the lock reads [email protected]).

Measured locally (mcpp 2026.10.27.1, the CI's pin)

  • Linux, [email protected]: mcpp test passes 7 of 7.
  • 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/absent fails at link naming kal_process_self.
  • With mcpp 2026.10.26.1 a clean build fails with failed to read compiled module ... imports must be built before being imported (mcpplibs.os.error / mcpplibs.os.terminal). That is the GCC module-map defect fixed in 2026.10.27.1 (the version this repository's CI states as its minimum), not a flake of this change.

Release order

  1. openkal-emscripten#8 merged and tagged 0.6.0. done
  2. mcpp-index gains openkal-emscripten 0.6.0. done (mcpp-index#618)
  3. This PR merged and tagged 0.2.2.
  4. mcpp-index gains os 0.2.2.

…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 merged commit 2b46d9f into main Oct 28, 2026
37 of 40 checks passed
Sunrisepeak added a commit to mcpplibs/mcpp-index that referenced this pull request Oct 28, 2026
Adds mcpplibs.os 0.2.2 (mcpplibs/os#9; tag 0.2.2 on 2b46d9f): the wasm32-emscripten target over Emscripten's C library and openkal-emscripten 0.6.0; fs::read without a 64 KiB stack array; stamp_of / identity_of ask for the kind. GLOBAL is the GitHub tag archive, CN the byte-identical GitCode mcpp-res/os asset (sha256 33c5d946...4e3e). Member tests/examples/os moves to 0.2.2.
@Sunrisepeak
Sunrisepeak deleted the os-0.2.2-emscripten branch October 28, 2026 16:48
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