Skip to content

Commit cb64cba

Browse files
committed
Emscripten (wasm32-unknown-emscripten) support
Adds wasm32-unknown-emscripten as a target for nix, plus a CI job that runs the full test suite under Node. Source changes to compile on emscripten (which behaves like a Linux/musl libc): * ioctl: use the Linux ioctl module and a c_int ioctl_num_type on emscripten (src/sys/ioctl, src/sys/mod.rs). * resource: enable getrlimit/setrlimit and the Resource enum via libc::rlimit. * socket: include emscripten in the SockaddrStorage AF_UNIX (pathname/unnamed) decode arms. * unistd: sethostname is unavailable on emscripten, so gate it out. The suite spawns OS threads (signal and socket-peer tests), so std is rebuilt with atomics via -Zbuild-std and linked -pthread with -sPROXY_TO_PTHREAD so the main thread can block; JSPI (-sJSPI) provides the return-to-host suspension for blocking reads/writes, and NODERAWFS/NODERAWSOCKETS back the filesystem and sockets with node's. This needs nightly + rust-src and a JSPI-capable Node (26+, or 22 with --experimental-wasm-jspi). No custom target spec is required: nightly now emits the __main_argc_argv entry point (rust-lang/rust#158937). Genuinely-unsupported operations are ignored with fork/wait, pty/termios, mkfifo, getpwnam/setgroups/acct, flock, if_nametoindex, pipe2 FD_CLOEXEC, AF_UNIX SCM_RIGHTS/datagram, thread signal masking, and setrlimit; a few tests are cfg'd out where the feature is entirely absent (raw signal actions, socketpair) or the host differs (linkat symlink follow). Temporary, until the dependencies land upstream: * Cargo.toml patches libc to guybedford/libc#libc-0.2-emscripten for the emscripten externs (rust-lang/libc#5270). * the CI job builds against the guybedford/emscripten `cf` fork, which carries the NODEFS/socket/blocking patches this target depends on (emscripten-core/emscripten#27305, #27306). Suite result: 148 passed, 0 failed, 35 ignored under Node - green on Linux CI.
1 parent 23b6973 commit cb64cba

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,12 @@ jobs:
676676
- name: test
677677
run: |
678678
source ./emsdk/emsdk_env.sh
679+
export EM_CONFIG="$EMSDK/.emscripten"
679680
CARGO_TARGET_WASM32_UNKNOWN_EMSCRIPTEN_RUNNER="$JSPI_NODE" \
680681
RUSTFLAGS="-A linker_messages -C target-feature=+atomics,+bulk-memory,+mutable-globals -C link-arg=-pthread -C link-arg=-sPROXY_TO_PTHREAD -C link-arg=-sNODERAWSOCKETS -C link-arg=-sNODERAWFS -C link-arg=-sALLOW_MEMORY_GROWTH=1 -C link-arg=-sEXIT_RUNTIME=1 -C link-arg=-sJSPI" \
681-
cargo +nightly test --target wasm32-unknown-emscripten -Zbuild-std=std,panic_abort --test test
682+
cargo +nightly test --target wasm32-unknown-emscripten -Zbuild-std=std,panic_abort --test test \
683+
--config 'patch.crates-io.libc.git="https://github.com/guybedford/libc"' \
684+
--config 'patch.crates-io.libc.branch="libc-0.2-emscripten"'
682685
683686
- name: before_cache_script
684687
run: rm -rf $CARGO_HOME/registry/index

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ targets = [
2626
"x86_64-unknown-illumos"
2727
]
2828

29-
[patch.crates-io]
30-
libc = { git = "https://github.com/guybedford/libc", branch = "libc-0.2-emscripten" }
31-
3229
[dependencies]
3330
libc = { version = "0.2.186", features = ["extra_traits"] }
3431
bitflags = "2.3.3"

0 commit comments

Comments
 (0)