Skip to content

Building and testing ​

How to build vz from source, why the binary must be signed, and which tests run where.

Requirements ​

MacApple silicon (arm64)
macOS27 or newer. Package.swift targets macOS 27 because of DiskImageKit and AccessoryAccess
ToolchainXcode 27, or the Command Line Tools with Swift 6.2 (swift-tools-version: 6.2)
Optionalqemu-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 ​

TargetWhat it does
make or make buildswift build -c debug, then signs .build/debug/vz
make releaseThe same with CONFIG=release: .build/release/vz
make signSigns $(BIN) with entitlements.plist using scripts/sign.sh
make testAll test suites, then signs the debug binary again
make test-coreOnly LabCoreTests, LabImagesTests and LabOSTests, then signs again
make installCopies a release build to $(PREFIX)/bin and the schema and examples to $(PREFIX)/share/vz. PREFIX defaults to /usr/local
make uninstallRemoves $(PREFIX)/bin/vz and $(PREFIX)/share/vz
make formatswift format --in-place --recursive Sources Tests Package.swift
make lintswift format lint --recursive Sources Tests Package.swift
make schema-checkRuns scripts/check-examples.sh
make cleanDeletes .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:

bash
codesign --force --sign - --entitlements entitlements.plist .build/debug/vz

Ad-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:

bash
sudo chown -R "$(id -un)" .build

To install system-wide, build as yourself first, then only copy as root:

bash
make release
sudo make install

Running your build ​

bash
.build/debug/vz version
cd examples/01-single-vm
../../.build/debug/vz validate
../../.build/debug/vz up

vz 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:

  1. ../share/vz/ next to the executable (installed copies: make install, release tarballs)
  2. The SwiftPM resource bundle, for builds in .build

The resources come from Sources/CLI/Resources, which holds two symlinks:

SymlinkTarget
Sources/CLI/Resources/27.jsonschema/27.json
Sources/CLI/Resources/examplesexamples/

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).

SuiteCoversNeeds
LabCoreTestsLoader, validator, image references, address discovery, console replay, control codecNothing special
LabImagesTestsFetcher (with a fake network), checksum lists, unpackers, qcow2 conversionNothing special. QemuImgTests are skipped when qemu-img is not installed
LabOSTestsImageTests.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 macOSNothing special
LabRuntimeTestsEngine code that needs the real frameworks, such as the DiskImageKit overlay stackmacOS 27 and a signed test binary
bash
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. LoaderTests checks there are at least six.
  • invalid/: every file must fail with its expected error. LoaderTests lists 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.

See also ​