A standalone Bazel index registry, in the Bazel Central Registry (BCR) layout,
for the Unicorn CPU emulator.
Bazel downloads the upstream Unicorn 2.1.4 release archive, verifies its
SHA-256 and applies the checked-in overlay pinned in
source.json. No CMake, Ninja or
configure run at build time.
This downstream overlay is AI-generated. It is not part of upstream Unicorn and is not supported by the Unicorn project. It is derived from the Bazel build in google/silifuzz (see NOTICE). If it proves useful, the plan is to offer it upstream.
-
Hosts (2.1.4.bcr.2 and later), each built and tested in CI with Bazel 8 and 9:
Host Compiler in CI Linux x86-64 GCC; also hermetic Zig/Clang Linux AArch64 GCC macOS AArch64 (Apple silicon) Apple Clang macOS x86-64 Apple Clang Windows x86-64 MSVC ( cl.exe,ml64)Other hosts, including Windows AArch64 and MinGW, are marked incompatible. Versions 2.1.4 and 2.1.4.bcr.1 support Linux x86-64 only.
-
Guest architectures: 32-bit ARM, AArch64 and x86 (16/32/64-bit). Unicorn's other front ends (MIPS, PPC, RISC-V, SPARC, m68k, s390x, TriCore) are not built yet.
-
Not included: Unicorn's language bindings and samples.
bazel_dep(name = "unicorn", version = "2.1.4.bcr.3")with this registry ahead of the BCR:
common --registry=https://raw.githubusercontent.com/sonix-network/unicorn-bazel/main
common --registry=https://bcr.bazel.build
Depend on exactly one of these targets and #include <unicorn/unicorn.h>:
| Target | Guest architectures |
|---|---|
@unicorn//:unicorn |
ARM, AArch64, x86 |
@unicorn//:unicorn_arm |
ARM |
@unicorn//:unicorn_arm64 |
AArch64 |
@unicorn//:unicorn_x86 |
x86 |
Each variant builds uc.c with its own UNICORN_HAS_<ARCH> defines, so two
variants must not be linked into one binary.
Notes for consumers:
- Build with
-c optfor a usable emulator. Like upstream's default CMake build, the overlay sets no optimization level of its own. - The libraries are static-only (
linkstatic = True), like upstream's singlelibunicorn, socc_test,cc_binaryand Rust consumers all link the front ends into one image. Version 2.1.4 was not static-only: a dynamically linkedcc_testorrust_testfailed to load or link the front ends there. Use 2.1.4.bcr.1 or later.
- Source lists, defines and include order follow Unicorn 2.1.4's
CMakeLists.txt(UNICORN_COMMON_SRCS,UNICORN_ARCH_COMMON, the*-softmmulibraries andUNICORN_SRCS):- its GCC/Clang branch on Linux and macOS;
- its MSVC branch on Windows, which adds the Win32 sources and the
setjmpwrapper assembled byml64.
- The host TCG backend follows the host CPU (
qemu/tcg/i386orqemu/tcg/aarch64). bazel/config/<os>-<cpu>/holds each POSIX host's output of Unicorn's ownqemu/configureandqemu/scripts/create_config, run asCMakeLists.txtruns them (the unusedCONFIG_IASLline dropped). Each header names the compiler it was probed with and fails with#erroron another host.- Linux x86-64 was probed locally with Clang and matches silifuzz's header.
- The others were probed on GitHub's runners.
- The manual probe workflow regenerates them.
- On Windows the config headers are Unicorn's own
msvc/tree, as for its MSVC build. - Every QEMU include directory is a private
-I. Onlyinclude/unicorn/*.his exported, so QEMU's internal headers (several targets ship acpu.h) never reach consumers. unicorn-commonis built with hidden visibility, as upstream'sC_VISIBILITY_PRESETdoes; that is safe because the libraries are static-only (2.1.4 omitted it).
With Bazel 9.3.2 (or Bazelisk). dev needs Linux x86-64; dev/bcr runs on
any supported host:
python3 dev/tools/pin_sources.py --check # overlay pins match the files
(cd dev && bazel test @unicorn//:all) # hermetic Zig toolchain
(cd dev/bcr && bazel test @unicorn//:all) # host compiler, like the BCR presubmitThe tests are Unicorn's upstream unit tests (tests/unit: test_arm,
test_arm64, test_x86, test_mem, test_ctl; test_arm also against
the ARM-only variant). A variant_test_* per library checks that it opens
exactly its own architectures and rejects the others.
After editing anything under overlay/, run
python3 dev/tools/pin_sources.py to refresh source.json. The dev
workspaces disable the lockfile, but a running Bazel server keeps the old
registry contents: run bazel shutdown before rebuilding.
Published versions are immutable. For build-only fixes against the same
upstream archive, add 2.1.4.bcr.1, 2.1.4.bcr.2, and so on, keeping the
directory name, module(version = ...) and metadata.json in sync.