Skip to content

feat(windows): sketch fix-pe.ts + bkwinvenv (skeletons for #346)#347

Draft
tannevaled wants to merge 1 commit into
pkgxdev:mainfrom
tannevaled:feat/windows-skeleton
Draft

feat(windows): sketch fix-pe.ts + bkwinvenv (skeletons for #346)#347
tannevaled wants to merge 1 commit into
pkgxdev:mainfrom
tannevaled:feat/windows-skeleton

Conversation

@tannevaled
Copy link
Copy Markdown

Draft, paired with #346 (RFC) + pkgxdev/pantry#12984 (llvm-mingw recipe).

Two new files to give concrete shape to the architecture sketched in #346:

Mirror of Purpose
lib/bin/fix-pe.ts fix-elf.ts Strip +brewing from PE binaries (binary-safe); audit-only DLL import check
libexec/bkwinvenv bkpyvenv Recipe-side hermetic bundler: walk PE imports → bin/*.exelibexec/, emit .cmd wrapper

What's intentionally NOT here

  • No wiring into the bottle/audit pipeline (that's the obvious follow-up once the shape is acked)
  • No platform == 'windows' branches added to bottle.ts, audit.ts, etc.
  • No tests
  • No CI changes

The goal of this draft is to make the architecture reviewable as code, not to ship anything. If the shapes look right, the wiring + tests + CI work is a separate PR (or several).

Sanity check on the design

The Linux bklibcvenv (you suggested the rename from bkcvenv for clarity) and this bkwinvenv end up with the same recipe-side API:

build:
  script:
    - bkwinvenv stage {{prefix}}  # or bklibcvenv on Linux
    - make && make install
    - bkwinvenv seal  {{prefix}}  # opt-in hermetic

So consumers learn one mental model: stage/seal + opt-in hermeticity, regardless of platform.

Key design points to push back on

  1. fix-pe doesn't rewrite anything load-bearing — Windows has no RPATH/PT_INTERP to surgery. The only rewrite is the +brewing byte-sweep (which is a generic problem, not a Windows-specific one). Do you want this consolidated into a generic post-rename pass on Linux and Windows? Currently the Linux side handles +brewing via fix-elf RPATH rewriting; the new byte-sweep would be an addition.

  2. SYSTEM_DLLS allowlist — I hard-coded the common Windows-shipped DLLs. There's no canonical machine-readable list; we'd be maintaining it ourselves. Alternative: assume any DLL whose name doesn't match a bottle-shipped one is system. (Less safe but simpler.)

  3. bkwinvenv stage is currently a no-op — does it actually need a stage phase? bkpyvenv stage creates the venv; bklibcvenv stage sets CC/CXX. For Windows, the toolchain is already wired (via llvm.org/mingw-w64 dep). We might just need seal.

Refs

Concrete artefact for pkgxdev#346 — two new files mirroring
the Linux side:

  lib/bin/fix-pe.ts    — analog of lib/bin/fix-elf.ts for PE/COFF
  libexec/bkwinvenv    — analog of libexec/bkpyvenv for hermetic
                         Windows-binary bundling

Both are skeletons — not wired into the build pipeline yet, no tests,
no plumbing into the bottle/audit phases. The intent is to give
shape to the architecture sketched in the RFC so the discussion can
move to concrete code instead of design questions.

## fix-pe.ts (PE/COFF audit + sanitize pass)

Three responsibilities, all light-weight since Windows has no RPATH:

  1. Strip "+brewing" from embedded strings (length-preserving,
     same problem the libc.so linker-script fix solved at
     pkgxdev/pantry#12968 — needed to be done as a binary-safe
     byte sweep here)
  2. (TODO) Strip absolute build paths from .pdb debug records
  3. Audit-only check that every NEEDED DLL is either Windows-shipped
     (kernel32, ucrtbase, vcruntime140, …) or co-located in the
     bottle. Warn-not-fail; bundling is bkwinvenv's job.

Notably absent: NO patchelf equivalent, NO RPATH rewriting, NO
PT_INTERP analog. None of those concepts exist in PE/COFF.

## bkwinvenv (recipe-side hermetic-bundle helper)

Mirrors bkpyvenv's stage/seal lifecycle:

  bkwinvenv stage <prefix>
    (currently no-op placeholder; reserved for future CC/LD wiring)

  bkwinvenv seal <prefix>
    For each bin/*.exe:
      1. walk PE imports (llvm-readobj --coff-imports)
      2. bundle non-system transitive DLLs into libexec/
      3. move exe → libexec/
      4. emit bin/<stem>.cmd wrapper that does
           "%~dp0\..\libexec\<exe>" %*

This is the Windows answer to bklibcvenv (pkgxdev#344) —
same opt-in hermeticity model, same bin/libexec layout, simpler
wrapper because Windows' default DLL search order already favors
the exe directory (no need for explicit loader invocation).

## What's NOT here

No platform-handling fixes (`platform == 'windows'` branches in
audit, bottle, env). Those go in follow-up commits once the
shapes here get sign-off — likely:

  - audit step: skip fix-elf on windows hosts, run fix-pe instead
  - bottle step: produce .tar.xz with Windows binaries
  - env: PATH separator, file extensions, etc.

Refs: pkgxdev#346 (RFC), pkgxdev#344 (bklibcvenv analog),
      pkgxdev/pantry#12984 (llvm-mingw recipe).
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