Repository navigation
Conversation
The prebuilt Windows DLL was copied to the output path and other libraries were built there, which fails where the output path does not allow executing files. The prebuilt DLL is now loaded from the installed package and built libraries are cached in the cache directory of the user. VUNIT_PYTHON_BRIDGE_LIBRARY_DIR selects another directory on every platform. The library found its configuration next to itself. The configuration stays in the output path, and the simulator hooks of NVC, GHDL and Questa/ModelSim pass its path in VUNIT_PYTHON_BRIDGE_CONFIG. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Loading it from the package gave GHDL its versioned file name as the VHPIDIRECT library token, which exceeds the 32 characters GHDL accepts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The simulator cannot load the bridge library from a file system mounted noexec (e.g. a tmpfs in a rootless podman container) and GHDL only says "cannot load VHPIDIRECT shared library". Check the mount when preparing the library and point at VUNIT_PYTHON_BRIDGE_LIBRARY_DIR instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A linked simulation found the bridge library only through the LD_LIBRARY_PATH the run environment hook sets, so a ghdl wrapper that resets it, or a re-run by hand, failed to load it. GHDL passes what follows -Wl, to the compiler driver, hence -Wl,-Wl,-rpath. mcode and llvm-jit cannot be helped this way: GHDL limits the library name of a VHPIDIRECT attribute to 32 characters, too short for an absolute path. Document that. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ru551n
force-pushed
the
library-dir
branch
2 times, most recently
from
October 11, 2026 21:13
5c0c1e8 to
76dc3a0
Compare
…ritable A container run with a random UID often has HOME=/ or a read-only home, and the setup then failed with a bare OSError creating the cache directory. Raise a PythonBridgeError naming the directory, whether it is the default or set by VUNIT_PYTHON_BRIDGE_LIBRARY_DIR, and asking for that variable to be set to a writable directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Windows has no noexec mount, but an execution policy (AppLocker, Windows Defender Application Control, Smart App Control) can block libraries in a directory, and NVC and GHDL then only report that loading failed. Load the VHPIDIRECT library once at setup, with the LoadLibrary search order the simulators use, and fail early: a policy error points to VUNIT_PYTHON_BRIDGE_LIBRARY_DIR, any other error is reported with its reason. The library is unloaded again so the file is not kept open. The FLI variant is not checked, it needs the libraries of vsim. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NVC and GHDL report a bridge library they cannot load as "cannot load VHPIDIRECT shared library" and leave out the reason the loader gives. The setup now loads the VHPIDIRECT variant itself on Linux and macOS, the counterpart of the Windows check, and fails with that reason, for example a missing libpython. Taken from VUnit#20. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bridge library ended up in the VUnit output path: the prebuilt Windows DLL was copied to
<output path>/python_bridge/..., and Linux/macOS and Windows gcc builds were compiled there. Where the output path doesn't allow executing files (anoexecmount, AppLocker or similar), the simulator can't load the library.Changes
All bridge libraries go to the user's cache directory instead of the output path: the prebuilt Windows DLLs, copied under the short name
vunit_python_bridge.dllas before, and the libraries built for Linux/macOS, Windows gcc and Questa FLI. The default locations are:~/.cache/vunit-python-bridgeon Linux, or underXDG_CACHE_HOMEif set,~/Library/Caches/vunit-python-bridgeon macOS,%LOCALAPPDATA%\vunit-python-bridgeon Windows.Builds are keyed by what they were built from, so projects can share the cache.
VUNIT_PYTHON_BRIDGE_LIBRARY_DIRselects another directory on every platform.Configuration. The library used to read
vunit_python_bridge.cfgfrom its own directory, which is why it had to live in the output path. The config is per project, so it stays in<output path>/python_bridge. Newrun_envhooks for NVC, GHDL and Questa/ModelSim pass its path inVUNIT_PYTHON_BRIDGE_CONFIG.config.creads that variable, with_wgetenvon Windows so non-ASCII paths survive, and falls back to the library's directory when it isn't set.Why the DLL is still copied. The first version of this PR loaded the DLL straight from the package. GHDL's VHPIDIRECT library token then became the versioned file name, which is longer than the 32 characters GHDL accepts, and Windows GHDL CI crashed.
Docs and release note. README, the "How it works" section of the user guide, and
release_notes/0.2.0.md.Unwritable library directory. When the library directory cannot be created or written (e.g.
HOME=/with a random UID in a container), the setup fails with aPythonBridgeErrornaming the directory, whether it is the default or set byVUNIT_PYTHON_BRIDGE_LIBRARY_DIR, and asking for that variable to be set to a writable directory. There is no fallback to the output path.Windows load check. Windows has no
noexecmount, but an execution policy (AppLocker, Windows Defender Application Control, Smart App Control) can block libraries in a directory, and NVC and GHDL then only report that loading failed. The setup loads the VHPIDIRECT library once, withwinmode=0so dependencies are searched like the simulators'LoadLibrarydoes, and unloads it again. Errors 1260, 577 and 4551 (blocked by policy, invalid image hash, integrity policy violation) fail with a message pointing toVUNIT_PYTHON_BRIDGE_LIBRARY_DIR. Any other load error fails with its reason. The FLI variant is not checked, since it needs vsim's libraries. Overhead: one load and unload per setup, well under a millisecond (measured 0.16 ms for the Linux equivalent).Linux/macOS load check (taken from Test on RHEL 9 and 10 with every GHDL backend and NVC, and report why the bridge does not load #20). After the noexec check, the setup loads the VHPIDIRECT library with
ctypes.CDLL, the counterpart of the Windows check. Any other load failure, for example a missing libpython, fails with the loader's reason, which NVC and GHDL leave out of "cannot load VHPIDIRECT shared library". The FLI variant is not checked, since it needs vsim's symbols. It does not catch aLD_LIBRARY_PATHthat is dropped between VUnit and GHDL mcode/llvm-jit, since it loads the library by absolute path; that case is documented below.noexec check. On Linux and macOS, a library directory on a file system mounted
noexec(e.g. a tmpfs in a rootless podman container) now fails the setup with aPythonBridgeErrornaming the directory andVUNIT_PYTHON_BRIDGE_LIBRARY_DIR. Without it, GHDL only sayscannot load VHPIDIRECT shared library 'libvunit_python_bridge.so'.rpath for GHDL llvm and gcc. The elaboration hook also passes
-Wl,-Wl,-rpath,<library dir>(GHDL hands what follows-Wl,to the compiler driver). A linked simulation then finds the bridge without theLD_LIBRARY_PATHof the run environment, so aghdlwrapper that drops it, or a re-run by hand, works. It still needsVUNIT_PYTHON_BRIDGE_CONFIG, and fails with a message naming it when that is missing. mcode and llvm-jit can't be helped this way: GHDL stores the VHPIDIRECT library name in a 32-character field, too short for an absolute path. The user guide documents that a wrapper must keepLD_LIBRARY_PATHandVUNIT_PYTHON_BRIDGE_CONFIG.Tests
pytest:
run_envhook for every simulator.The suite sets
VUNIT_PYTHON_BRIDGE_LIBRARY_DIRto temporary directories, so it never writes to the real user cache.CI:
Locally (Linux):
~/.cache/vunit-python-bridgeand the output path only holds the config and generated VHDL.AlmaLinux 9.6, rootless podman, GHDL mcode, dnf python3.11:
noexectmpfs: the bridge now loads (107 of 108 feature tests; the remaining failure, "Test importing a module with a relative file name", also fails on main).noexectmpfs: the setup fails with the new message.Linux/macOS load check: a new unit test puts a broken library in a fresh library directory and checks the message names it with the loader's reason. The two tests with a stub compiler mock the load. In podman, AlmaLinux 9.6 with Python 3.11 and GHDL 6.0.0 mcode, and Ubuntu 24.04 with Python 3.12 and NVC 1.22.1: pytest 95 passed and feature tests 108 of 108 on both, and a corrupt cached library fails the setup with
does not load: ... file too short.Windows load check: three unit tests with
ctypesmocked (policy errors, other errors, unload with a 64-bit handle). The 13 Windows CI jobs (prebuilt DLL and gcc build, NVC and GHDL, wheel tests) pass, so the check does not reject a library that loads. The policy-blocked case is not tested on a real machine.AlmaLinux 9.6, GHDL mcode, unwritable library directory:
HOME=/:Cannot build the Python bridge library in /.cache/vunit-python-bridge (the default): [Errno 13] Permission denied: '/.cache'. Set VUNIT_PYTHON_BRIDGE_LIBRARY_DIR to a writable directory.(set by VUNIT_PYTHON_BRIDGE_LIBRARY_DIR).AlmaLinux 9.6, GHDL master llvm (LLVM 19):
ghdlwrapper droppingLD_LIBRARY_PATH: before,error while loading shared libraries: libvunit_python_bridge.so; after, passes.ghdlwrapper runningenv -i: fails withFailed to open the Python bridge configuration file (VUNIT_PYTHON_BRIDGE_CONFIG is not set).-Wl,), left to CI.Not tested locally: the Windows code in
config.c(left to the Windows CI jobs), and GHDL llvm/gcc (left to CI).Not in this PR
The Riviera-PRO/Active-HDL VHPI application is still built under
<output path>/<simulator>/librariesbyforeign_application.py, so it has the same problem. It needs a separate change.🤖 Generated with Claude Code