Commit b4fab13
committed
feat(libexec): bklibcvenv — extract glibc wrapper-script pattern
Extracts the recipe-side hermetic libc-bundling pattern @jhheider
just validated inline in pkgxdev/pantry@5354c73f. Recipes that ship
their own libc (glibc today; musl, custom libcs tomorrow) get a
~one-line call:
- bklibcvenv seal {{prefix}} glibc-{{version.marketing}}
instead of the ~20-line inline wrapper-installer that's currently
duplicated in the glibc recipe.
## Shape
Mirror of libexec/bkpyvenv (Python venv → relocatable stubs):
libexec/bklibcvenv — the helper script
share/brewkit/libcvenv-wrapper.sh — the POSIX sh wrapper template
The helper:
1. takes `<prefix> <libdir-name>` as args
2. auto-detects LDSO from `uname -m` (overridable via LDSO env)
3. for each ELF in <prefix>/{bin,sbin}/* with a PT_INTERP:
- moves it to <prefix>/libexec/<libc-name>-<dir>/
- replaces it with a sed-templated sh wrapper
4. wrapper does `cd $(dirname $0)/..` to compute prefix at
runtime, then `exec $libdir/$ldso --library-path $libdir
$libexec_path "$@"`
`<libc-name>` (libdir-name up to first '-') prefixes the libexec
subdir so multiple libc bottles can coexist (glibc + musl):
- libexec/glibc-bin/
- libexec/glibc-sbin/
## Why this is useful
- **Fully relocatable** — bottle extracted at `/opt`, `~/.pkgx`, or
any other path works the same; no absolute paths baked in.
- **Sidesteps PT_INTERP** — invoking ld.so explicitly via wrapper
ignores the ELF's PT_INTERP. brewkit's fix-elf currently can't
rewrite PT_INTERP anyway (#345) and the bottle's
own ld.so suffers from fix-elf's RPATH pollution when not
`build.skip: fix-patchelf`'d.
- **Reusable** — same shape works for musl, dietlibc, or any
alternate libc anyone packages.
## Connection to bkwinvenv (#347)
The Windows analog (`bkwinvenv`, sketched at #347) uses the same
seal-into-libexec + emit-wrapper-script structure, just with `.cmd`
wrappers + Windows DLL search-order semantics (no explicit loader
invocation; co-location with the inner .exe is enough). Validating
this Linux pattern empirically (which @jhheider's commit does)
validates the Windows design too.
## Migration
Once this lands, pkgxdev/pantry's glibc recipe can shrink its
inline wrapper-installer block (currently ~20 lines + a prop:
template) to one line. Same for any future libc recipe.
Refs: #344 (this RFC), #347
(bkwinvenv sibling), pkgxdev/pantry@5354c73f (origin of pattern).1 parent 2e18552 commit b4fab13
2 files changed
Lines changed: 124 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments