Skip to content

refactor(delib-1a): platform pfd I/O uses Linux direct syscalls#47

Merged
chaploud merged 1 commit intomainfrom
develop/delib-phase1
Apr 24, 2026
Merged

refactor(delib-1a): platform pfd I/O uses Linux direct syscalls#47
chaploud merged 1 commit intomainfrom
develop/delib-phase1

Conversation

@chaploud
Copy link
Copy Markdown
Contributor

Summary

First step toward the W46 un-link-libc migration. Linux branch of platform.pfd* helpers now calls std.os.linux.{write,read,pread,pwrite,lseek,close,fsync} directly instead of going through libc wrappers (std.c.*). Mac/BSD keep std.c.* (libSystem auto-links), Windows keeps the Win32 path added in #45.

Behavior preserved via errno mirroring: the Linux branch writes the syscall errno into std.c._errno().* so callers that read cErrnoToWasi() continue to observe correct error codes during the transition.

Restructured as switch (comptime builtin.os.tag) so the Mac arm isn't semantically analyzed on Linux/Windows builds — prerequisite for later dropping link_libc = true.

What this does NOT do yet

  • Still links libc (link_libc = true in build.zig unchanged).
  • Path-based WASI ops (mkdirat / unlinkat / renameat / readlinkat / futimens / fstatat / dup) still use std.c.* directly, not gated. Those become W46 Phase 1b.
  • Doesn't shrink Linux binary yet — need to finish Phase 1b+ and remove link_libc.

Test plan

  • zig build test on Mac aarch64 (all pass).
  • zig build -Dtarget=x86_64-linux-gnu clean.
  • zig build -Dtarget=x86_64-windows-gnu clean.
  • Full CI on PR — Mac + Ubuntu + Windows green (including 46 real-world compat tests).

Tracking: .dev/checklist.md → W46 (planned for zwasm-cleanup merge).

First step toward the W46 un-link-libc migration. Replace
`std.c.{write,read,pread,pwrite,lseek,close,fsync}` inside
`platform.pfd*` helpers with `std.os.linux.*` direct syscalls
on Linux. Mac/BSD keep `std.c.*` (libSystem auto-link, still works).
Windows keeps the Win32 path added in 1af72d1.

Behavior unchanged: callers that read `std.c._errno()` still see
the right errno because the Linux branch mirrors the syscall's
errno into `_errno().*` before returning -1. `link_libc = true`
still on — actually removing it needs the path-based ops
(mkdirat / unlinkat / renameat / readlinkat / futimens / fstatat /
dup) migrated as well. Tracked as W46 Phase 1b+.

Restructures each pfd helper as a `switch (comptime builtin.os.tag)`
so the Mac `std.c.*` arm is not semantically analyzed on Linux or
Windows builds — a prerequisite for eventually dropping
`link_libc = true` without tripping "dependency on libc must be
explicitly specified" errors.

Verified: `zig build test` (Mac aarch64), `zig build
-Dtarget=x86_64-linux-gnu`, `zig build -Dtarget=x86_64-windows-gnu`
all succeed on the initial build. Full CI to follow.
@chaploud chaploud merged commit b4718fd into main Apr 24, 2026
5 checks passed
@chaploud chaploud deleted the develop/delib-phase1 branch April 30, 2026 15:15
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