Building and testing
How to build vz from source, why the binary must be signed, and which tests run where.
Requirements
| Mac | Apple silicon (arm64) |
| macOS | 27 or newer. Package.swift targets macOS 27 because of DiskImageKit and AccessoryAccess |
| Toolchain | Xcode 27, or the Command Line Tools with Swift 6.2 (swift-tools-version: 6.2) |
| Optional | qemu-img (brew install qemu) for faster qcow2 conversion; check-jsonschema (pipx install check-jsonschema) for make schema-check |
Swift package dependencies are resolved by SwiftPM: swift-argument-parser and Yams.
NOTE
With only the Command Line Tools (no Xcode), SwiftPM does not find the swift-testing macro plugin. The Makefile finds it under $(xcode-select -p)/usr/lib/swift/host/plugins/testing and passes it to swift test. Use make test rather than plain swift test and this is handled for you.
Make targets
| Target | What it does |
|---|---|
make or make build | swift build -c debug, then signs .build/debug/vz |
make release | The same with CONFIG=release: .build/release/vz |
make sign | Signs $(BIN) with entitlements.plist using scripts/sign.sh |
make test | All test suites, then signs the debug binary again |
make test-core | Only LabCoreTests, LabImagesTests and LabOSTests, then signs again |
make install | Copies a release build to $(PREFIX)/bin and the schema and examples to $(PREFIX)/share/vz. PREFIX defaults to /usr/local |
make uninstall | Removes $(PREFIX)/bin/vz and $(PREFIX)/share/vz |
make format | swift format --in-place --recursive Sources Tests Package.swift |
make lint | swift format lint --recursive Sources Tests Package.swift |
make schema-check | Runs scripts/check-examples.sh |
make clean | Deletes .build |
CONFIG and PREFIX can be set on the command line, for example make build CONFIG=release or sudo make install PREFIX=/opt/vz.
Signing
Virtualization.framework refuses to run without the com.apple.security.virtualization entitlement. make build signs the binary ad hoc:
codesign --force --sign - --entitlements entitlements.plist .build/debug/vzAd-hoc signing is enough for VMs, switches and links. No Apple Developer account is needed.
An unsigned binary fails early with "this vz binary is not signed with the com.apple.security.virtualization entitlement ... Rebuild with: make build". Without that check vmnet would fail with unrelated-looking errors such as VMNET_MEM_FAILURE.
WARNING
swift test re-links the debug binary and drops its entitlements. make test and make test-core sign it again afterwards. If you run swift test or swift build directly, run make sign before you use .build/debug/vz.
USB passthrough is different: Accessory Access needs the com.apple.developer.accessory-access.usb entitlement and a Developer ID signature, which ad-hoc signing cannot provide. See USBAccess.swift.
Never build with sudo
A build under sudo leaves root-owned files in .build, and every later build fails with "Operation not permitted". make build detects this and stops with the fix:
sudo chown -R "$(id -un)" .buildTo install system-wide, build as yourself first, then only copy as root:
make release
sudo make installRunning your build
.build/debug/vz version
cd examples/01-single-vm
../../.build/debug/vz validate
../../.build/debug/vz upvz up spawns the same executable for the background lab process, so the build you run is the build that owns the VMs.
The binary finds the JSON Schema and the bundled examples in one of two places:
../share/vz/next to the executable (installed copies:make install, release tarballs)- The SwiftPM resource bundle, for builds in
.build
The resources come from Sources/CLI/Resources, which holds two symlinks:
| Symlink | Target |
|---|---|
Sources/CLI/Resources/27.json | schema/27.json |
Sources/CLI/Resources/examples | examples/ |
Edit the files at their real location. vz schema and vz init --example read them through the bundle.
Tests
Tests use swift-testing (@Suite, @Test, #expect).
| Suite | Covers | Needs |
|---|---|---|
LabCoreTests | Loader, validator, image references, address discovery, console replay, control codec | Nothing special |
LabImagesTests | Fetcher (with a fake network), checksum lists, unpackers, qcow2 conversion | Nothing special. QemuImgTests are skipped when qemu-img is not installed |
LabOSTests | ImageTests.swift: the image catalog and what each image maker fetches and prints. PlatformTests.swift: the platform table, each platform's validation and the plans they return (inspected, not installed), and reading init for macOS | Nothing special |
LabRuntimeTests | Engine code that needs the real frameworks, such as the DiskImageKit overlay stack | macOS 27 and a signed test binary |
make test-core # the tests CI runs: fast, no VMs, no entitlements
make check # test-core plus lint, schema-check and the repository rules: CI without VMs
make test # everything, including the runtime tests
swift test --filter ValidatorTests # one suite (then run make sign)Fixtures
Lab file fixtures live in Tests/LabCoreTests/Fixtures:
valid/: every file must load and validate without errors.LoaderTestschecks there are at least six.invalid/: every file must fail with its expected error.LoaderTestslists each one and checks the folder holds exactly that many, so a new invalid fixture needs a new test case.
make schema-check also validates valid/*.yaml and every examples/*/lab.yaml against the JSON Schema.
Testing for real
Unit tests cannot boot a guest. For changes to the runtime, platforms, image makers, cloud-init handling or networking, boot at least one example lab that uses the feature, and say which in your pull request. Labs 22 and 23 turn most node and switch keys on.