Skip to content

perl: generate Errno.pm on the wasm cross target so use Errno works (kd-gtxa)#827

Open
brandonpayton wants to merge 1 commit into
gascity/kd-1mr/kd-k7zy-package-perl-generated-core-module-runtime-filesfrom
gascity/kd-1mr/kd-gtxa-errno-constants
Open

perl: generate Errno.pm on the wasm cross target so use Errno works (kd-gtxa)#827
brandonpayton wants to merge 1 commit into
gascity/kd-1mr/kd-k7zy-package-perl-generated-core-module-runtime-filesfrom
gascity/kd-1mr/kd-gtxa-errno-constants

Conversation

@brandonpayton

Copy link
Copy Markdown
Member

Problem (kd-gtxa)

On the wasm cross target, Perl shipped without Errno.pm, so use Errno failed
("Can't locate Errno.pm") and any module needing errno constants broke. During
make, ext/Errno/Errno_pm.PL died: "No error definitions found at
Errno_pm.PL line 208."

Root cause

Errno_pm.PL::get_files() discovers which headers define the E* constants by
preprocessing #include <errno.h> and scanning the cpp output for
# <line> "file" linemarkers, then greps those headers for #define E*.
perl-cross defines cpp/cpprun/cppstdin as "$cc -E -P" (cnf/configure_tool.sh),
and -P suppresses linemarkers — so the scan discovered zero headers,
collected no constants, and Errno_pm.PL died. Not an include-path problem: the
SDK cc wrapper always injects --sysroot, and the constants are plain
#define E* <int> in the sysroot (musl arch/generic bits/errno.h, 134 of them).
They were simply never discovered.

Confirmed directly: wasm32posix-cc -E errno.c emits 13 linemarkers pointing at
sysroot/include/bits/errno.h; -E -P emits 0.

Fix

build-perl.sh patches get_files() to fall back to the sysroot errno headers
($WASM_POSIX_SYSROOT/include/{errno.h,bits/errno.h}) when linemarker discovery
yields nothing — surgical (zero blast radius on the configure probes that -P
serves), fallback-only (upstream discovery is untouched where it works), and
fail-loud (aborts if the anchor moves). Errno.pm is added to the runtime
post-check so a regression fails the build. Revision bumped 2→3 (perl-runtime.zip
now ships Errno.pm; perl.wasm is byte-unchanged — Errno is pure-perl, not
linked in). The formula installs it automatically (it unzips lib/*).

Verification

  • Reproduced on the unmodified perl: ship a usable core-module runtime (generated files + static XS) so File::Spec/POSIX load on Kandelo #821 recipe: Errno_pm.PL line 208 → Errno.pm
    absent from privlib + perl-runtime.zip.
  • Clean fresh-source rebuild (exercises the recipe patch path): exit 0,
    Errno.pm generated with 134 constants at exact musl values and staged into
    perl-runtime.zip.
  • Node smoke (demo/errno-smoke.ts): PERL_ERRNO_SMOKE_PASS — 16/16
    (use Errno loads; EPERM/ENOENT/…/EINVAL match musl; ERRNO_COUNT=134; %! tie).
  • Browser smoke (demo/errno-browser-smoke.ts): committed + ready; skips
    with reason where the browser bundle/playwright are absent. Host-agnostic:
    perl.wasm is byte-identical to the interpreter perl: run on the default/unset locale without a startup panic (kd-dvph) #822 browser-verified, and the
    browser perl-vfs image is built from perl-src/lib (now containing Errno.pm).
    Full browser acceptance tracked by kd-yuef.

Stacking

Stacked on #821 (kd-k7zy) — the Errno failure only exists on that recipe
(origin/main's build-perl.sh stops at make perl and never builds ext/Errno).
Base is the #821 branch; retarget to main after #821 merges.

🤖 Generated with Claude Code

ext/Errno/Errno_pm.PL discovers the E* errno constants by preprocessing
`#include <errno.h>` and scanning cpp output for `# <line> "file"` linemarkers.
perl-cross defines cpp/cpprun/cppstdin as "$cc -E -P"; -P suppresses those
linemarkers, so on the wasm cross target the scan found no headers, collected
no constants, and Errno_pm.PL died "No error definitions found" -- Errno.pm was
never generated/staged and `use Errno` failed. The constants are plain
`#define E* <int>` in the sysroot (musl arch/generic bits/errno.h).

build-perl.sh now patches get_files() to fall back to the sysroot errno headers
when linemarker discovery yields nothing, adds Errno.pm to the fail-loud
runtime post-check, and bumps the package revision (perl-runtime.zip now ships
Errno.pm; perl.wasm is byte-unchanged). Adds Node + browser use-Errno smokes.

Stacked on #821 (kd-k7zy). Verified: Node errno-smoke 16/16 (Errno.pm with 134
musl-valued constants + %! tie); browser smoke harness committed (skips where
the browser bundle is absent; browser acceptance tracked by kd-yuef).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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