refactor(delib-1a): platform pfd I/O uses Linux direct syscalls#47
Merged
refactor(delib-1a): platform pfd I/O uses Linux direct syscalls#47
Conversation
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.
This was referenced Apr 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First step toward the W46 un-link-libc migration. Linux branch of
platform.pfd*helpers now callsstd.os.linux.{write,read,pread,pwrite,lseek,close,fsync}directly instead of going through libc wrappers (std.c.*). Mac/BSD keepstd.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 readcErrnoToWasi()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 droppinglink_libc = true.What this does NOT do yet
link_libc = truein build.zig unchanged).mkdirat/unlinkat/renameat/readlinkat/futimens/fstatat/dup) still usestd.c.*directly, not gated. Those become W46 Phase 1b.link_libc.Test plan
zig build teston Mac aarch64 (all pass).zig build -Dtarget=x86_64-linux-gnuclean.zig build -Dtarget=x86_64-windows-gnuclean.Tracking:
.dev/checklist.md→ W46 (planned for zwasm-cleanup merge).