Skip to content

os: support TinyGo on js/wasm - #650

Open
0pcom wants to merge 1 commit into
spf13:masterfrom
0magnet:tinygo-support
Open

os: support TinyGo on js/wasm#650
0pcom wants to merge 1 commit into
spf13:masterfrom
0magnet:tinygo-support

Conversation

@0pcom

@0pcom 0pcom commented Aug 16, 2026

Copy link
Copy Markdown

TinyGo's os package does not define Chmod, Chown or Link on its js/wasm target, so afero does not compile there at all. This routes those three through small wrappers and adds js/wasm-only stubs returning ENOSYS — honest for a target with no filesystem to act on. syscall.EBADFD is likewise absent, so BADFD falls back to EBADF.

Scoped to js/wasm, not to TinyGo generally. That distinction is the reason for the odd-looking !(tinygo && js) constraints. I checked each target rather than assuming:

TinyGo target os.Chmod / Chown / Link
linux (native) present — unchanged, uses the standard files
wasip1 present — unchanged
wasm (js) absent — needs the stubs

So TinyGo native and wasip1 builds keep the existing implementations; only js/wasm diverges.

Verified: go build and go test on the host pass unchanged; tinygo build succeeds for both the linux and wasip1 targets; and go list -tags tinygo under GOOS=js selects exactly the two new files and none of the originals.

One thing I should be straight about: this is necessary but not by itself sufficient to build afero under TinyGo js/wasm today. With TinyGo 0.41.1 the build still fails afterwards inside net/http (roundtrip_js.go), which afero reaches through HttpFs. That is a TinyGo stdlib gap unrelated to this change, and it is being pursued separately — but I would rather say so than let the PR imply the target works end to end.

TinyGo's os package does not define Chmod, Chown or Link on the js/wasm
target, so afero does not compile there at all. Route those three through
small wrappers and supply js/wasm-only stubs returning ENOSYS, which is
honest: that target has no filesystem for them to act on.

syscall.EBADFD is likewise absent there, so BADFD falls back to EBADF.

Scoped to js/wasm rather than to TinyGo as a whole: TinyGo's linux and
wasip1 targets provide all three functions and keep using the standard
implementations, verified by building against both.
@CLAassistant

CLAassistant commented Aug 16, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

0pcom added a commit to 0magnet/afero that referenced this pull request Aug 16, 2026
The shims were gated on //go:build tinygo, which is too broad. Only TinyGo's
js/wasm target is missing os.Chmod, os.Chown and os.Link — its linux and
wasip1 targets provide all three, and were being given ENOSYS stubs for
functions that work.

Checked per target rather than assumed:

  tinygo linux   — present
  tinygo wasip1  — present
  tinygo wasm/js — absent

Same for syscall.EBADFD, which drives the BADFD fallback. Files renamed to
match the narrowed constraint.

This matches what was proposed upstream in spf13#650.
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.

2 participants