Skip to content

fix(workspace): scope libstdc++ for uvx native wheels in direnv CI - #1184

Merged
c-vigo merged 8 commits into
devfrom
bugfix/1181-uvx-native-libs-helper
Jul 17, 2026
Merged

c-vigo merged 8 commits into
devfrom
bugfix/1181-uvx-native-libs-helper

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What & why

On a non-Python direnv-mode consumer, the CI preamble keeps the Nix CPython on PATH (the manylinux exclusion of #1028 only applies when pyproject.toml exists). A uvx-run tool whose manylinux native wheel links libstdc++.so.6 then aborts with libstdc++.so.6: cannot open shared object file, because the Nix loader does not search /usr/lib — the same failure class as the dropped pymarkdown/pyjson5 hook.

Fixes #1181.

Approach

Ship the proven org-config pattern as a base justfile helper rather than a global preamble export or a change to setup-devkit-toolchain (owned by #1180). The root assets/workspace/justfile gains a with-native-libs +command recipe:

  • Lives in the root justfile so it is reachable in every delivery mode (direnv/bare have no .devcontainer/justfile.devc) — direnv-mode CI is exactly the case that needs it.
  • Derives a command-scoped LD_LIBRARY_PATH from $VIGOS_STDCPP_LIB (dev-shell export) or, failing that, from the on-PATH cc wrapper via cc -print-file-name=libstdc++.so.6 (the wrapper is on the preamble-forwarded PATH; cc echoes the bare name back — not an absolute path — when it cannot resolve the lib, so the leading-/ check degrades to a no-op).
  • Scoped to the one wrapped command, so the Nix libstdc++ never leaks into other tools' processes; degrades to the caller's own LD_LIBRARY_PATH (or empty) when neither source resolves.

A consumer recipe wraps its tool:

validate:
    just with-native-libs uvx --from otterdog@1.2.3 otterdog validate --local

Provenance & evidence

  • Mirrors the consumer-side fix proven in org-config@f01175a (feat(config): import vig-os organization configuration org-config#40), reproduced under a CI-faithful env -i PATH=<store bins> simulation.
  • TDD: failing bats test committed first, then the recipe. New coverage in tests/bats/just.bats exercises all branches:
    • derives LD_LIBRARY_PATH from the on-PATH cc wrapper,
    • prefers $VIGOS_STDCPP_LIB over deriving from cc,
    • no-ops cleanly when the lib is not found,
    • prepends to an existing LD_LIBRARY_PATH.
  • bats tests/bats/just.bats: 51/51 pass (5 new). prek run --all-files: fully green.

Scope

Minimal diff — root justfile helper, its bats coverage, changelog (+ synced .devcontainer/ mirror), and NIX.md docs. Does not touch setup-devkit-toolchain (#1180) and does not resurrect the pymarkdown hook (nix-packaged separately in #1177).

Review fix: no empty LD_LIBRARY_PATH entries

Review found an edge case: when nothing resolved the libstdc++ dir (no $VIGOS_STDCPP_LIB, cc absent or lib not found) the recipe still composed the prefix, yielding :/pre/existing when the caller had an LD_LIBRARY_PATH (a leading empty entry = cwd on the dynamic loader's search path — a tool run from an untrusted directory could load a planted libstdc++.so.6), or setting the variable to "" when it did not. Fixed (TDD, RED then GREEN): the recipe now branches on a non-empty prefix and otherwise runs the command with the environment untouched — never a leading colon, never set-to-empty. New bats coverage asserts the caller's value passes through byte-identical and that the variable stays unset in the pure no-op case. After the fix: bats tests/bats/just.bats 52/52 pass, prek run --all-files fully green.

Refs: #1181, vig-os/org-config#40

c-vigo added 8 commits July 17, 2026 14:24
Add bats coverage for a base `with-native-libs` recipe that scopes
LD_LIBRARY_PATH to a single uvx/uv-tool command so a nix CPython can
load manylinux native wheels under direnv-mode CI. Exercises derivation
from the on-PATH cc wrapper, VIGOS_STDCPP_LIB precedence, graceful
no-op when the lib is absent, and preservation of an existing
LD_LIBRARY_PATH. Fails until the recipe ships.

Refs: #1181
On a non-Python direnv-mode consumer the CI preamble keeps the Nix
CPython on PATH, whose loader does not search /usr/lib, so a uvx tool's
manylinux native wheel (e.g. otterdog's rjsonnet) aborts with
"libstdc++.so.6: cannot open shared object file" — the same failure
class as the dropped pymarkdown/pyjson5 hook.

Add a base `with-native-libs` recipe to the root justfile (reachable in
every delivery mode, unlike the devcontainer-only justfile.devc) that
wraps one uvx/uv-tool command with a command-scoped LD_LIBRARY_PATH,
sourced from $VIGOS_STDCPP_LIB or derived from the on-PATH `cc` wrapper
and degrading to a no-op when neither resolves. Mirrors the pattern
proven in org-config@f01175a.

Refs: #1181
Record the direnv-mode CI fix in the changelog and document the base
`with-native-libs` recipe in the Nix runtime notes: when a consumer
needs it (uvx/uv-tool tools with native extensions under the Nix
CPython), how to wrap an invocation, and how it degrades to a no-op.

Refs: #1181
…libs

When nothing resolves the libstdc++ dir, the current composition still
sets LD_LIBRARY_PATH — empty, or ":/pre/existing" when the caller had
one. Either way that adds an empty entry, which the dynamic loader
treats as the current working directory, silently putting cwd on the
library search path. Assert the caller's value passes through
byte-identical (no leading colon) and that with no inherited value the
variable stays unset. Fails until the recipe branches on a non-empty
prefix.

Refs: #1181
The dev-shell environment exports a multi-line shellHook variable whose
body contains the literal text LD_LIBRARY_PATH, so the substring refute
can never pass regardless of the recipe's behavior. Refute the exact
env line (^LD_LIBRARY_PATH=) instead, which still rejects both an
empty-set and a leading-colon composition.

Refs: #1181
…ve-libs

When neither $VIGOS_STDCPP_LIB nor the cc wrapper resolves the
libstdc++ dir, the recipe composed the prefix anyway: with the caller's
LD_LIBRARY_PATH set it produced ":/pre/existing", and with it unset it
set the variable to "". Either way that is an empty search-path entry,
which the dynamic loader treats as the current working directory —
running a wrapped tool from an untrusted directory could load a planted
libstdc++.so.6. Branch on a non-empty prefix and run the command with
the environment untouched otherwise.

Refs: #1181
The helper now leaves the environment untouched when nothing resolves
the libstdc++ dir instead of composing an empty prefix; align the Nix
runtime notes with that behavior and record why an empty entry is
unsafe.

Refs: #1181
@c-vigo
c-vigo merged commit 8bee189 into dev Jul 17, 2026
13 checks passed
@c-vigo
c-vigo deleted the bugfix/1181-uvx-native-libs-helper branch July 17, 2026 12:54
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