Files
reims-vgpu/Makefile
T
Anees Iqbal 526bdf6633 ✅ Run reims-ctl's checks with one make target
Does what PR 130 asked for: one command for the checks of reims-ctl, whose
workspace cargo xtask check does not reach. PR 130 routed it through the
library's xtask, which builds in the library's workspace and so fetches
metal2vulkan, that reims-ctl's workspace is kept apart from, and it ran
neither reims-restore's workspace nor the Windows clippy, the one check on
the Mac or Linux that sees a break of their Windows build (docs/lessons.md).

`make check-ctl` runs, by each workspace's own manifest, in crates/reims-ctl
and in crates/reims-restore (a workspace of its own, with reims-apfs):
rustfmt, clippy, clippy for x86_64-pc-windows-gnullvm with MinGW's gcc and ar
for ring's C, and the tests, clippy with -D warnings and each with
--workspace; the cheapest first, stopping at the first failure. Where
x86_64-w64-mingw32-gcc or -ar is not on the PATH it says so and fails before
any step, never skipping the Windows clippy; on Windows itself the host's
clippy is that check, and it says so. The Makefile's header,
docs/development.md and AGENTS.md's reims-ctl row (now naming reims-restore
too) name the target, and the lesson on reims-ctl's Windows build says what
it catches.
2026-12-02 02:16:38 -08:00

177 lines
9.3 KiB
Makefile

# The Rust library and its tooling. The Cargo workspace is at the
# repository root.
#
# make the library as a plain library (cargo xtask dist) in its dist
# tree, target/dist-vulkan: libreims_vgpu.a and the shared
# library (.so on Linux, .dylib on a Mac, over MoltenVK), with
# reims_vgpu.h and reims-vgpu.pc
# make qemu the library as a plain library (cargo xtask dist), then
# vendor/qemu's qemu-system-x86_64 with reims-graphics-pci on
# its C API, linked statically through pkg-config, in
# build/qemu (docs/qemu.md), with a copy of the dist tree's
# stage helper, reims-vgpu-compile, beside it
# make vulkan-links
# on a Mac, links in build/lib to Homebrew's Vulkan loader and
# Mesa's KosmicKrisp driver, which the library's rt platform
# loads from ../lib of a QEMU in build/qemu or in a directory
# beside it (make qemu makes them too); nothing elsewhere
# make check-ctl
# reims-ctl's checks (AGENTS.md, "Checking a change") in each
# of its two workspaces, crates/reims-ctl and crates/reims-restore
# (with reims-apfs), which cargo xtask check reaches neither of:
# rustfmt, clippy, clippy for x86-64 Windows and the tests; it
# stops where x86_64-w64-mingw32-gcc is not on the PATH
# make clean remove build/, QEMU's build included
#
# QEMU_CONFIGURE adds options to QEMU's configure and runs it again.
# CARGO_TARGET_DIR moves the build, and with it RUST_TARGET, out of target.
BUILD := build
# $(BUILD) made absolute without abspath, which splits a path with spaces.
BUILD_DIR := $(if $(filter /%,$(BUILD)),$(BUILD),$(CURDIR)/$(BUILD))
QEMU_CONFIGURE ?=
QEMU_BUILD := $(BUILD_DIR)/qemu
QEMU_SRC := $(CURDIR)/vendor/qemu
# Cargo's target directory, made absolute the same way: the dist tree is
# under it, which QEMU's config.status records, and cargo resolves a
# relative one against the directory it runs in.
RUST_TARGET_REL := $(or $(CARGO_TARGET_DIR),target)
RUST_TARGET := $(if $(filter /%,$(RUST_TARGET_REL)),$(RUST_TARGET_REL),$(CURDIR)/$(RUST_TARGET_REL))
# The dist tree cargo xtask dist writes (xtask/src/dist.rs).
RUST_DIST := $(RUST_TARGET)/dist-vulkan
# The library's stage helper, in the dist tree's bin, which the library starts
# from beside the process's executable
# (crates/reims-vgpu-vulkan/src/rt_platform/stage.rs).
HELPER := reims-vgpu-compile$(if $(filter Windows_NT,$(OS)),.exe)
.PHONY: all qemu vulkan-links check-ctl clean
all:
CARGO_TARGET_DIR="$(RUST_TARGET)" cargo xtask dist
vendor/qemu/configure:
@echo "vendor/qemu is empty: git submodule update --init vendor/qemu" >&2
@exit 1
# QEMU finds reims-vgpu.pc in the dist tree and links libreims_vgpu.a, so the
# binary records no path to the library; reims-graphics-pci calls its C API
# (reims_vgpu.h). Configure runs once, out of tree, and again whenever
# QEMU_CONFIGURE is set or config.status was made from another source or with
# another PKG_CONFIG_PATH, or names an option vendor/qemu's configure no longer
# takes (--enable-pvg, --apple-gfx-backend, --pvg-framework) or the
# aarch64-softmmu target an earlier make qemu built. It also runs again when
# reims-vgpu.pc differs from the one it last read: meson keeps the package's
# flags from configure, so a framework the library came to need (its
# Libs.private) would otherwise be missing from QEMU's link. And it runs again
# where vendor/qemu's configure, the meson options it writes, its Python
# dependencies or its VERSION are newer than config-host.mak, as QEMU's own
# Makefile reruns it.
#
# ninja builds the binary, at its own default parallelism or a caller's -jN:
# QEMU's Makefile hands ninja -j1 where make was given no -j, which took
# 310 s for a clean build where ninja's default took 59 s (docs/qemu.md).
# ninja has meson regenerate build.ninja where a meson file changed, as
# install-ctl.sh's build relies on.
#
# vendor/qemu at another commit than the one build/qemu was configured from
# builds in an empty directory, as install-ctl.sh's does: meson, configuring
# or regenerating in place, deletes each file the last build made that the new
# build.ninja does not name, even one it has just written at configure
# (qemu-version.h of QEMU of 2026-11-13, docs/lessons.md). A clean build takes
# about a minute, and edits not yet committed keep the directory.
QEMU_PKG_CONFIG := $(RUST_DIST)/lib/pkgconfig
QEMU_PC_READ := $(QEMU_BUILD)/reims-vgpu.pc.configured
QEMU_CONFIGURE_INPUTS := configure scripts/meson-buildoptions.sh pythondeps.toml VERSION
qemu: all vendor/qemu/configure vulkan-links
@src=$$(git -C "$(QEMU_SRC)" rev-parse HEAD 2>/dev/null); \
if [ -n "$$src" ] && [ "$$(cat "$(QEMU_BUILD)/qemu-source" 2>/dev/null)" != "$$src" ]; then \
rm -rf "$(QEMU_BUILD)"; \
fi
@mkdir -p "$(QEMU_BUILD)"
@if [ ! -f "$(QEMU_BUILD)/build.ninja" ] || [ -n "$(QEMU_CONFIGURE)" ] \
|| ! grep -qF -- "exec '$(QEMU_SRC)/configure'" "$(QEMU_BUILD)/config.status" 2>/dev/null \
|| ! grep -qxF -- "PKG_CONFIG_PATH='$(QEMU_PKG_CONFIG)'" "$(QEMU_BUILD)/config.status" \
|| grep -qE -- "'--(enable-pvg|apple-gfx-backend=|pvg-framework=|target-list=aarch64-softmmu)" "$(QEMU_BUILD)/config.status" \
|| ! cmp -s "$(QEMU_PKG_CONFIG)/reims-vgpu.pc" "$(QEMU_PC_READ)" \
|| [ -n "$$(cd "$(QEMU_SRC)" && find $(QEMU_CONFIGURE_INPUTS) -newer "$(QEMU_BUILD)/config-host.mak" 2>/dev/null)" ]; then \
cd "$(QEMU_BUILD)" && PKG_CONFIG_PATH="$(QEMU_PKG_CONFIG)" "$(QEMU_SRC)/configure" \
--target-list=x86_64-softmmu --enable-reims-vgpu \
--disable-docs $(QEMU_CONFIGURE) \
&& cp "$(QEMU_PKG_CONFIG)/reims-vgpu.pc" "$(QEMU_PC_READ)"; \
fi
@git -C "$(QEMU_SRC)" rev-parse HEAD >"$(QEMU_BUILD)/qemu-source" 2>/dev/null || rm -f "$(QEMU_BUILD)/qemu-source"
ninja -C "$(QEMU_BUILD)" $(filter-out -j,$(filter -j%,$(MAKEFLAGS))) qemu-system-x86_64
cp -p "$(RUST_DIST)/bin/$(HELPER)" "$(QEMU_BUILD)/$(HELPER)"
# On a Mac, the library's rt platform loads the Vulkan loader and Mesa's
# KosmicKrisp driver only from beside the process's executable or from ../lib
# (crates/reims-vgpu-vulkan/src/os/macos/rt_driver.rs). build/lib is ../lib
# from build/qemu and from any QEMU build directory beside it, such as the
# arm64 one docs/qemu.md configures. It holds a link to each file in its
# Homebrew formula's opt directory, which brew upgrade moves to the new
# version: the loader to vulkan-loader's, KosmicKrisp to mesa's (whose build
# has KosmicKrisp on macOS 26 and later). A file Homebrew lacks is named and
# not linked, and the rt platform then makes its own instance, or searches for
# the loader itself.
VULKAN_LIBS := $(BUILD_DIR)/lib
vulkan-links:
@[ "$$(uname -s)" = Darwin ] || exit 0; \
hb=$$(brew --prefix 2>/dev/null) || { echo "vulkan-links: no Homebrew: nothing linked in $(VULKAN_LIBS)" >&2; exit 0; }; \
mkdir -p "$(VULKAN_LIBS)"; \
for f in vulkan-loader/lib/libvulkan.1.dylib mesa/lib/libvulkan_kosmickrisp.dylib; do \
if [ -f "$$hb/opt/$$f" ]; then \
ln -sfn "$$hb/opt/$$f" "$(VULKAN_LIBS)/$${f##*/}"; \
else \
echo "vulkan-links: Homebrew's $${f%%/*} has no $$hb/opt/$$f: $${f##*/} not linked in $(VULKAN_LIBS)" >&2; \
fi; \
done
# reims-ctl's checks, run in each of its workspaces by --manifest-path, never
# through the library's xtask: reims-ctl and reims-restore are workspaces of
# their own, so they build without the metal2vulkan the library's workspace
# fetches. The cheapest step first, and the first failure stops it. clippy for
# x86_64-pc-windows-gnullvm, the Windows build, is the one check on the Mac or
# Linux that sees a break of it (docs/lessons.md): its build scripts compile
# C for Windows (ring's, under ureq's rustls) with MinGW's gcc and ar, which
# a Mac has from Homebrew's mingw-w64. Where they are missing it says so and
# stops, before any step runs. On Windows, where reims-ctl builds for that
# target natively (MSYS2's CLANG64), the host's clippy is that check, and it
# says so in place of a second run.
CTL_WORKSPACES := crates/reims-ctl crates/reims-restore
CTL_WINDOWS := x86_64-pc-windows-gnullvm
CTL_MINGW := x86_64-w64-mingw32
check-ctl:
ifneq ($(OS),Windows_NT)
@for t in gcc ar; do command -v $(CTL_MINGW)-$$t >/dev/null || { \
echo "check-ctl: $(CTL_MINGW)-$$t is not on the PATH, and clippy for $(CTL_WINDOWS) needs it for the C its dependencies build (on a Mac: brew install mingw-w64)" >&2; \
exit 1; }; done
endif
@for w in $(CTL_WORKSPACES); do \
echo "check-ctl: rustfmt in $$w"; \
cargo fmt --manifest-path $$w/Cargo.toml --all --check || exit 1; \
done
@for w in $(CTL_WORKSPACES); do \
echo "check-ctl: clippy in $$w"; \
cargo clippy --manifest-path $$w/Cargo.toml --workspace --all-targets -- -D warnings || exit 1; \
done
ifeq ($(OS),Windows_NT)
@echo "check-ctl: clippy for $(CTL_WINDOWS): the clippy above, this host's"
else
@for w in $(CTL_WORKSPACES); do \
echo "check-ctl: clippy for $(CTL_WINDOWS) in $$w"; \
CC_x86_64_pc_windows_gnullvm=$(CTL_MINGW)-gcc AR_x86_64_pc_windows_gnullvm=$(CTL_MINGW)-ar \
cargo clippy --manifest-path $$w/Cargo.toml --workspace --all-targets --target $(CTL_WINDOWS) -- -D warnings || exit 1; \
done
endif
@for w in $(CTL_WORKSPACES); do \
echo "check-ctl: tests in $$w"; \
cargo test --manifest-path $$w/Cargo.toml --workspace || exit 1; \
done
@echo "check-ctl: ok"
clean:
rm -rf "$(BUILD_DIR)"