treewide: migrate to qemu-kvm in toolchain-bundle

Change-Id: I42a10a9adf7bdccb83ef997c6d554140ffaade4b
Reviewed-on: https://review.monogon.dev/c/monogon/+/4052
Reviewed-by: Jan Schär <jan@monogon.tech>
Tested-by: Jenkins CI
diff --git a/osbase/test/ktest/ktest.bzl b/osbase/test/ktest/ktest.bzl
index 4a6942f..5fc93e8 100644
--- a/osbase/test/ktest/ktest.bzl
+++ b/osbase/test/ktest/ktest.bzl
@@ -46,11 +46,12 @@
         is_executable = True,
     )
 
+    runfiles = ctx.runfiles(files = [ctx.file._ktest, initramfs, ctx.file.kernel, ctx.file.tester])
+    runfiles = runfiles.merge(ctx.attr._ktest[DefaultInfo].default_runfiles)
+
     return [DefaultInfo(
         executable = script_file,
-        runfiles = ctx.runfiles(
-            files = [ctx.files._ktest[0], initramfs, ctx.file.kernel, ctx.file.tester],
-        ),
+        runfiles = runfiles,
     )]
 
 k_test = rule(
@@ -105,7 +106,7 @@
             default = Label("//osbase/test/ktest"),
             cfg = "target",
             executable = True,
-            allow_files = True,
+            allow_single_file = True,
         ),
         "_ktest_init": attr.label(
             default = Label("//osbase/test/ktest/init"),
diff --git a/osbase/test/qemu/BUILD.bazel b/osbase/test/qemu/BUILD.bazel
index f45804f..0145ddb 100644
--- a/osbase/test/qemu/BUILD.bazel
+++ b/osbase/test/qemu/BUILD.bazel
@@ -3,13 +3,20 @@
 go_library(
     name = "qemu",
     srcs = ["launch.go"],
+    data = [
+        "//build/toolchain/toolchain-bundle:qemu-kvm",
+    ],
     importpath = "source.monogon.dev/osbase/test/qemu",
     visibility = [
         "//metropolis:__subpackages__",
         "//osbase:__subpackages__",
     ],
+    x_defs = {
+        "xQEMUPath": "$(rlocationpath //build/toolchain/toolchain-bundle:qemu-kvm )",
+    },
     deps = [
         "//osbase/freeport",
+        "@io_bazel_rules_go//go/runfiles",
         "@org_golang_x_sys//unix",
     ],
 )
diff --git a/osbase/test/qemu/launch.go b/osbase/test/qemu/launch.go
index 1b063de..ba33961 100644
--- a/osbase/test/qemu/launch.go
+++ b/osbase/test/qemu/launch.go
@@ -13,10 +13,12 @@
 	"net"
 	"os"
 	"os/exec"
+	"path/filepath"
 	"strconv"
 	"strings"
 	"syscall"
 
+	"github.com/bazelbuild/rules_go/go/runfiles"
 	"golang.org/x/sys/unix"
 
 	"source.monogon.dev/osbase/freeport"
@@ -136,6 +138,25 @@
 	return fd1, fd2, nil
 }
 
+var (
+	// These are filled by bazel at linking time with the canonical path of
+	// their corresponding file. Inside the init function we resolve it
+	// with the rules_go runfiles package to the real path.
+	xQEMUPath string
+)
+
+func init() {
+	var err error
+	for _, path := range []*string{
+		&xQEMUPath,
+	} {
+		*path, err = runfiles.Rlocation(*path)
+		if err != nil {
+			panic(err)
+		}
+	}
+}
+
 // MicroVMOptions contains all options to start a MicroVM
 type MicroVMOptions struct {
 	// Name is a human-readable identifier to be used in debug output.
@@ -240,7 +261,7 @@
 		"-m", "1G",
 		// Needed because QEMU does not boot without specifying the qboot bios
 		// even tho the documentation clearly states that this is the default.
-		"-bios", "/usr/share/qemu/qboot.rom",
+		"-bios", filepath.Join(filepath.Dir(xQEMUPath), "../share/qemu/qboot.rom"),
 		"-M", "microvm,x-option-roms=off,pic=off,pit=off,rtc=off,isa-serial=off",
 		"-kernel", opts.KernelPath,
 		// We force using a triple-fault reboot strategy since otherwise the kernel first
@@ -283,7 +304,7 @@
 	}
 
 	var stdErrBuf bytes.Buffer
-	cmd := exec.CommandContext(ctx, "/usr/bin/qemu-system-x86_64", append(baseArgs, extraArgs...)...)
+	cmd := exec.CommandContext(ctx, xQEMUPath, append(baseArgs, extraArgs...)...)
 	cmd.Stdout = opts.SerialPort
 	cmd.Stderr = &stdErrBuf