Skip to content

Let simulators from VUnit packages describe how they load the bridge - #41

Open
ru551n wants to merge 10 commits into
VUnit:mainfrom
ru551n:yavs-support
Open

ru551n wants to merge 10 commits into
VUnit:mainfrom
ru551n:yavs-support

Conversation

@ru551n

@ru551n ru551n commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why: a simulator provided by a VUnit package should not need an entry in a per-simulator table of the bridge.

What: the bridge builds its list of simulators from VUnit: it starts from the built-in simulators (BUILTIN_SIMULATORS: NVC, GHDL, Questa/ModelSim, Riviera-PRO) and adds every simulator class VUnit knows, for instance from a simulator package, that defines foreign_language_interface ("VHPIDIRECT", "FLI" or "VHPI") and native_library_hooks(library_file), a dict of register_simulator_hooks keyword arguments saying how the simulator loads the library. These take precedence over a built-in simulator of the same name, and the bridge adds its configuration run_env on top of theirs. Only the selected simulator is checked and has its hooks called: if it is not in the list, defines only one attribute, has an unknown interface, or hooks that are not a dict of known keys, it fails with an error naming the simulator, the cause and the fix. A half-defined class of another simulator is ignored. A "Simulator packages" docs page describes the protocol for simulator authors.

How tested (Linux, Python 3.13, VUnit 5.0.0.dev16): unit tests 137 passed (fake simulator classes in a fake and a real VUnit simulator factory); ruff 0.17.0, license headers and sphinx-build -W clean. tests/run.py 136 of 137 with the expected failure verified, file_base 7 of 7, example 19 of 19, on NVC 1.23-devel and GHDL 7.0.0-dev mcode.

Known limits: no CI job for a package simulator. Windows untested for package simulators; the Windows 64-bit check of the simulator executable only covers NVC, GHDL, Questa/ModelSim and Riviera-PRO.

🤖 Generated with Claude Code

ru551n and others added 4 commits October 29, 2026 14:07
yavs calls a VHPIDIRECT foreign subprogram by the last word of its
attribute and loads libraries given with --load, like NVC. The bridge
serves it with the NVC attributes, a --load run flag and the
configuration in the run environment.

yavs is provided by the vunit-yavs package. Its default source
encoding takes a non-ASCII character of a UTF-8 source as one
character, not as UTF-8 bytes, which the docs point out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yavs comes from a simulator package, so the bridge should not list it.
The next commit lets a simulator package describe how it loads the bridge.

This reverts commit b36e497.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A simulator provided by a VUnit package is unknown to the table of the
bridge. Its interface class now describes itself: foreign_language_interface
names the binding ("VHPIDIRECT", "FLI" or "VHPI") and
native_library_hooks(library_file) returns the simulator hooks that make
it load the library. The bridge adds the configuration to the run
environment those hooks give. The attributes take precedence over the
table, which stays for the built-in simulators. A simulator with neither
fails with an error naming the two attributes, and bad attribute values
fail with what is wrong.

The Windows check of the simulator executable only applies to the
built-in simulators, whose executable the bridge knows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A "Simulator packages" page for simulator authors describes
foreign_language_interface and native_library_hooks, with the README,
the requirements and the news fragment pointing to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ru551n ru551n changed the title Support yavs Let simulators from VUnit packages describe how they load the bridge Oct 29, 2026
Comment thread docs/simulator_packages.rst Outdated
reads a source as one character per code point needs an option to read it as
bytes (Latin-1) for non-ASCII string literals to reach Python unchanged.

yavs is a simulator served this way, by its package ``vunit-yavs``.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not mention yavs here.

Comment thread docs/simulator_packages.rst Outdated
Comment on lines +54 to +57
The bridge passes a VHDL string to Python as UTF-8 bytes, one character per
byte, which is what NVC and GHDL make of a UTF-8 source file. A simulator that
reads a source as one character per code point needs an option to read it as
bytes (Latin-1) for non-ASCII string literals to reach Python unchanged.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

Comment thread release_notes/news.d/41.feature.md Outdated
@@ -0,0 +1 @@
A simulator provided by a VUnit package is supported when its simulator interface class defines `foreign_language_interface` and `native_library_hooks(library_file)`, which say how it loads the bridge. See "Simulator packages" in the documentation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shorten this and only point to the docs

Comment thread src/vunit_python_bridge/bridge.py Outdated
Comment on lines +43 to +44
# The simulators of the table, named as a user knows them
SUPPORTED_SIMULATORS = "NVC, GHDL, Questa/ModelSim or Riviera-PRO"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called BUILTIN_SIMULATORS or something

Comment thread src/vunit_python_bridge/bridge.py Outdated
Comment on lines +97 to +100
raise PythonBridgeError(
f"The vunit-python-bridge package requires {SUPPORTED_SIMULATORS}, "
f"it is not supported for {simulator_name}"
)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be reworked, such that we add simulators to the list from VUnit, which in turn loads them from the simulator specific packages.

# override, the Questa/ModelSim and Aldec interfaces use vsim. The executable of a simulator
# from a VUnit package is not known here.
if simulator_name in ("nvc", "ghdl"):
name = os.environ.get(simulator_name.upper(), simulator_name)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need upper case here?

ru551n and others added 6 commits October 29, 2026 15:20
…he news fragment

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The bridge starts from the built-in simulators and adds every simulator class of VUnit,
for instance from a simulator package, that defines foreign_language_interface and
native_library_hooks. The selected simulator is looked up in that list.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A simulator class of another package that is half defined no longer breaks a project.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ter one

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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