#!/usr/bin/env bash # Stage 21: how `cargo run` and `cargo test` start QEMU (Cargo.toml's # bootimage `run-command`). bootimage calls this with the boot image and # Cargo.toml's run-args / test-args; we only change two things: # # 1. Those args say `target/disk.img` & co. If you build with # CARGO_TARGET_DIR=/somewhere, the images are in /somewhere instead, # so every "=target/" becomes "=$CARGO_TARGET_DIR/". # 2. The boot_v2 test kernel (tests/boot_v2.rs) gets one more disk: # target/rootfs-gpt.img, the boot contract v2 image build.rs makes. # # `exec`: QEMU replaces this script, so its PID is the one bootimage # started (and times out). set -euo pipefail T="${CARGO_TARGET_DIR:-target}" args=() boot_v2=0 for a in "$@"; do args+=("${a//=target\//=$T/}") case "$a" in *bootimage-boot_v2-*) boot_v2=1 ;; esac done if [ "$boot_v2" = 1 ]; then args+=(-drive "file=$T/rootfs-gpt.img,format=raw,if=virtio,snapshot=on") fi exec qemu-system-x86_64 "${args[@]}"