Repository navigation
nix: Use a stable, non-/tmp dir for mkEdaShell ldPreload wrappers - #207
Conversation
The gmp LD_PRELOAD wrappers (e.g. for Vivado) were written to a fresh `mktemp -d` dir under /tmp on every shell start and prepended to PATH. Bazel-based flows such as OpenTitan's record the directory a tool was found in and run actions in a sandbox with a private /tmp (--incompatible_sandbox_hermetic_tmp), so the wrapper was invisible and the build failed with "vivado: No such file or directory". The random path also changed PATH on every new shell, invalidating cached results such as bitstreams. Write the wrappers to $XDG_CACHE_HOME/lowrisc-eda/wrappers/<vendor>-<tool>-<hash>, keyed on the tool home and gmp library, writing each one atomically. Resolve the real binaries with that dir stripped from PATH so a re-sourced profile cannot generate a self-exec'ing wrapper or duplicate the PATH entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David James McCorrie <james.mccorrie@lowrisc.org>
| # a sandbox with a private /tmp, and a per-shell path would change | ||
| # PATH (and so invalidate cached results) on every new shell. Key it | ||
| # on everything the wrapper contents depend on. | ||
| wrapdir="''${XDG_CACHE_HOME:-$HOME/.cache}/lowrisc-eda/wrappers/$v-$t-$(printf '%s\n' "$home" "${gmpLib}" | sha256sum | cut -c1-16)" |
There was a problem hiding this comment.
Just a note: I don't think this directory will be automatically cleaned-up like /tmp is, so these wrapper files will accumulate. Probably not an issue, but slightly ugly
There was a problem hiding this comment.
Agreed it won't be cleaned automatically. A new dir only appears when the tool home or the gmp store path changes (a Vivado version change or a nixpkgs bump), and each holds a few tiny scripts, so growth is very slow. I'd rather not prune automatically: a still-open shell may have an older dir on its PATH, and deleting it would break vivado there. rm -rf ~/.cache/lowrisc-eda is always safe with no shells open. Happy to add a note on that to README-eda.md if you think it's worth it.
hcallahan-lowrisc
left a comment
There was a problem hiding this comment.
LGTM, I think the PATH-handling could be slightly improved but this should work as-is for the issue encountered
The pathDirs loop prepended $home/<dir> to PATH unconditionally, so re-sourcing the profile in an existing shell (nested `bash -l`, `source /etc/profile`, ...) added another copy on each source. Prepend via a helper that first drops any existing occurrence, and reuse it for the ldPreload wrapper dir. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David James McCorrie <james.mccorrie@lowrisc.org>
Problem
mkEdaShell'sldPreload: gmpcapability (used for Vivado) wrote its wrapper scripts into a freshmktemp -ddir under/tmpon every shell start and prepended it toPATH.OpenTitan's
@nonhermeticBazel repo records the directoryvivadowas found in, and the FuseSoC synth action runs in a sandbox with a private/tmp(--incompatible_sandbox_hermetic_tmp, the default since Bazel 7). The wrapper is invisible there, so bitstream builds fail:The random path also changes
PATHon every new shell, which re-runs@nonhermeticand invalidates cached bitstreams.Fix
${XDG_CACHE_HOME:-$HOME/.cache}/lowrisc-eda/wrappers/<vendor>-<tool>-<hash>, keyed on the tool home and gmp lib path, so the location is stable across shells and visible inside the Bazel sandbox.PATH, so a re-sourced profile can't generate a wrapper that execs itself or add the dir toPATHtwice.Testing
nix fmt -- --checkandnix-instantiate --parsepass.PATH, and no temp files are left behind.nix run --override-input lowrisc-nix path:<this branch> .#eda:vivadoresolves to~/.cache/lowrisc-eda/wrappers/xilinx-vivado-<hash>/vivado, which preloads the Nix gmp and execs the 2021.1 install.vivado -versionruns.🤖 Generated with Claude Code