Skip to content

fix: repair wasi-libc sysroot patches so patched sysroot builds succesfully#1424

Open
airhorns wants to merge 1 commit intorivet-dev:mainfrom
airhorns:fix-sysroot
Open

fix: repair wasi-libc sysroot patches so patched sysroot builds succesfully#1424
airhorns wants to merge 1 commit intorivet-dev:mainfrom
airhorns:fix-sysroot

Conversation

@airhorns
Copy link
Copy Markdown

@airhorns airhorns commented Apr 2, 2026

I went to work on adding some new packages that need the sysroot built to build themselves, but I couldn't build the sysroot locally!

Claude and I debugged and we believe the patched wasi-libc sysroot (make sysroot) has been broken since f833343 ("chore: duckdb"), which corrupted two patch files and introduced a workaround in the build script that masked some failures while causing others. After undoing the changes to the sysroot patches made there, the sysroot still builds for me locally, as does duckdb.

The changes:

0008-sockets.patch: f833343 prepended 67 lines of plain unified-diff content (a commit message + duplicate diffs for install-include-headers.sh and sys/socket.h) to a patch that already had correct diff --git hunks for those same files at the end. When git apply processed the patch, the plain diffs applied first, then the git-format diffs failed because their context had already been modified. Restored to the last known-good version from cee26aa, which is a clean diff --git patch.

0012-posix-spawn-cwd.patch: was a plain unified diff with incorrect hunk line counts, causing "corrupt patch at line N" errors from git apply unless --recount was used. Regenerated as proper diff --git format from the intended changes (adding FDOP_CHDIR support and cwd propagation to posix_spawn in host_spawn_wait.c).

patch-wasi-libc.sh: removed --recount flag from all git apply calls. --recount was added as a workaround for the malformed 0012 patch, but it caused silent misapplication of the valid plain-format patches 0013-0015 (posix-socket-header-surface, initialize-cwd-from-pwd, always-link-cwd-relative-path-resolution). With all patches now in correct format, --recount is unnecessary and harmful. Also removed the "layered patch scenario" fallback in --check mode that treated patch failures as success when destination files existed, which hid real errors.

Verified: all 15 wasi-libc patches apply cleanly in sequence against the pinned wasi-libc commit (574b88d), and the full sysroot build (clone, patch, make libc, install CRT, rebuild llvm runtimes, install overrides) completes successfully.

…ssfully

The patched wasi-libc sysroot (make sysroot) has been broken since
f833343 ("chore: duckdb"), which corrupted two patch files and
introduced a workaround in the build script that masked some failures
while causing others.

0008-sockets.patch: f833343 prepended 67 lines of plain unified-diff
content (a commit message + duplicate diffs for install-include-headers.sh
and sys/socket.h) to a patch that already had correct diff --git hunks
for those same files at the end. When git apply processed the patch, the
plain diffs applied first, then the git-format diffs failed because
their context had already been modified. Restored to the last known-good
version from cee26aa, which is a clean diff --git patch.

0012-posix-spawn-cwd.patch: was a plain unified diff with incorrect
hunk line counts, causing "corrupt patch at line N" errors from git
apply unless --recount was used. Regenerated as proper diff --git format
from the intended changes (adding FDOP_CHDIR support and cwd propagation
to posix_spawn in host_spawn_wait.c).

patch-wasi-libc.sh: removed --recount flag from all git apply calls.
--recount was added as a workaround for the malformed 0012 patch, but
it caused silent misapplication of the valid plain-format patches
0013-0015 (posix-socket-header-surface, initialize-cwd-from-pwd,
always-link-cwd-relative-path-resolution). With all patches now in
correct format, --recount is unnecessary and harmful. Also removed
the "layered patch scenario" fallback in --check mode that treated
patch failures as success when destination files existed, which
hid real errors.

Verified: all 15 wasi-libc patches apply cleanly in sequence against
the pinned wasi-libc commit (574b88d), and the full sysroot build
(clone, patch, make libc, install CRT, rebuild llvm runtimes, install
overrides) completes successfully.
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