xezim, a SystemVerilog Simulator in Rust, Now Builds Under Bazel
Can you add a new SystemVerilog simulator to a Bazel build in a few lines?
For xezim, you now can.
xezim is an open-source SystemVerilog simulator written in Rust, by
aionhw.
It parses, elaborates and simulates in one step, and it is licensed
MIT or Apache-2.0.
It also accepts the flag spellings of other simulators: -f,
+define+, +incdir+, -top, plusargs, -sv_lib and -gNAME=VAL.
For more on xezim itself, see this LinkedIn post.
Upstream ships no binaries, so you build xezim from source. xezim is now a module in the filmil Bazel registry, and Bazel builds it from source for you. Use version 0.11.7.bcr.1 (registry PR 921 and registry PR 924).
Note on this article: this article was written automatically. Check details against the linked sources before relying on them.
Using it
Add the registry to your .bazelrc, next to the Bazel Central Registry:
common --registry=https://raw.githubusercontent.com/filmil/bazel-registry/main
common --registry=https://bcr.bazel.build
Then depend on the module in MODULE.bazel:
bazel_dep(name = "xezim", version = "0.11.7.bcr.1")
Your workspace also needs a BUILD file at its root, even an empty one.
Without it, the build fails, because of a rules_rust bug described below.
Two targets are public.
@xezim//:xezimis the simulator binary. Use it as a tool in agenrule, or as data for a test.@xezim//:headersis acc_librarywithsvdpi.handvpi_user.h, for DPI-C and VPI libraries that xezim loads. Put it in thedepsof yourcc_binaryorcc_library, and write#include "svdpi.h"or#include "vpi_user.h".
The module builds on Linux on x86_64 only.
The UVM library is not built in: -uvm needs XEZIM_UVM_DIR to point at
a copy of it.
What it took
xezim’s own build is Cargo with a build script. Six things had to change for Bazel to build it from pinned sources, with a pinned compiler and C library, not the host’s.
- Rust 1.100. xezim needs it, and it was 12 days old.
rules_rust 0.75 defaults to Rust 1.99.1, and only the root module may
choose the Rust version.
So the module brings its own Rust 1.100.0 toolchain, and a transition
switches
@xezim//:xezimto that toolchain and to-c opt. The toolchain is never registered, so your other Rust code still builds with your own Rust version. - Pinned crates. xezim ships no
Cargo.lock, so the module adds one, and crate_universe pins the 123 packages in it. xezim-core and sv-parser both come from git, from the xezim-core repository, pinned at commitebd7886. - No build script. Upstream’s
build.rsasks git for version stamps, clones the UVM library during the build, and calls clang directly. The module replaces all three: the stamps are fixed for this release, the two C shims for VPI and DPI are an ordinarycc_library, and nothing is cloned. - libffi from the BCR. The libffi-sys crate normally builds its own copy of libffi with autoconf, which is not hermetic and has already broken upstream on macOS. The module uses the BCR’s libffi 3.8.0 instead.
- A root BUILD file. Any workspace that uses crate_universe through a
dependency needs a
BUILDfile at its root. That is a rules_rust bug, filed upstream as rules_rust issue 4385. - A pinned C compiler. xezim has C code: the two shims, and the zstd
and mimalloc libraries that crates build.
That code, and the final link, use a pinned clang 23.1.5 against
Chromium’s Debian bullseye sysroot, with glibc 2.31.
The host’s C compiler and C library are not used.
Only xezim’s own build uses that clang.
Your C++ and Rust toolchains stay as they are, and your compiler flags,
such as
--coptand--linkopt, are cleared for xezim’s build.
The tests
The module’s eight tests run in CI on Bazel 8 and 9, and pass on both.
- A counter runs and writes an FST waveform dump.
- A
$fatalcall makes the run exit with a nonzero status. xezim -Vprints the version.- A design is compiled to an artifact and run in a second step, so that elaboration and simulation can be timed apart.
- A DPI-C library is loaded and called.
- A VPI library is loaded and called.
- xezim runs as the tool of a
genrule. - A hermetic test checks both copies of the binary: the one that tests run, and the one that build tools get. Each must contain clang 23.1.5, show no trace of the host’s GCC, and need no glibc newer than 2.31. The test also checks that a library of your own did not pick up xezim’s clang.
On a GitHub runner, the module’s CI job, which builds xezim from scratch and runs its tests, takes 22 to 26 minutes.
What’s next
- The simulator benchmark in hdl-simbench uses this module (hdl-simbench PR 4), and will compare xezim with other open-source simulators.
- A generic
sim_testrule, with xezim as its first simulator toolchain, is in review (hdl_toolchains PR 5).
Links
- xezim, by aionhw
- The filmil Bazel registry, and the tracking issue 920
- rules_rust issue 4385
Feedback and technical corrections are welcome.