golang.org/x/build@v0.0.0-20240506185731-218518f32b70/cmd/runqemubuildlet/windows.go (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"log"
    10  	"os"
    11  	"os/exec"
    12  	"path/filepath"
    13  )
    14  
    15  // defaultWindowsDir returns a default path for a Windows VM.
    16  //
    17  // The directory should contain the Windows VM image, and UTM
    18  // components (UTM.app and sysroot-macos-arm64).
    19  func defaultWindowsDir() string {
    20  	home, err := os.UserHomeDir()
    21  	if err != nil {
    22  		log.Printf("os.UserHomeDir() = %q, %v", home, err)
    23  		return ""
    24  	}
    25  	return filepath.Join(home, "macmini-windows")
    26  }
    27  
    28  // windows10Cmd returns a qemu command for running a Windows VM, ready
    29  // to be started.
    30  func windows10Cmd(base string) *exec.Cmd {
    31  	c := exec.Command(filepath.Join(base, "sysroot-macos-arm64/bin/qemu-system-aarch64"),
    32  		"-L", filepath.Join(base, "UTM.app/Contents/Resources/qemu"),
    33  		"-cpu", "max",
    34  		"-smp", "cpus=8,sockets=1,cores=8,threads=1", // This works well with M1 Mac Minis.
    35  		"-machine", "virt,highmem=off",
    36  		"-accel", "hvf",
    37  		"-accel", "tcg,tb-size=1536",
    38  		"-boot", "menu=on",
    39  		"-m", "12288",
    40  		"-name", "Virtual Machine",
    41  		"-device", "qemu-xhci,id=usb-bus",
    42  		"-device", "ramfb",
    43  		"-device", "usb-tablet,bus=usb-bus.0",
    44  		"-device", "usb-mouse,bus=usb-bus.0",
    45  		"-device", "usb-kbd,bus=usb-bus.0",
    46  		"-device", "virtio-net-pci,netdev=net0",
    47  		"-netdev", "user,id=net0,hostfwd=tcp:127.0.0.1:8080-:8080",
    48  		"-bios", filepath.Join(base, "Images/QEMU_EFI.fd"),
    49  		"-device", "nvme,drive=drive0,serial=drive0,bootindex=0",
    50  		"-drive", fmt.Sprintf("if=none,media=disk,id=drive0,file=%s,cache=writethrough", filepath.Join(base, "Images/win10.qcow2")),
    51  		"-device", "usb-storage,drive=drive2,removable=true,bootindex=1",
    52  		"-drive", fmt.Sprintf("if=none,media=cdrom,id=drive2,file=%s,cache=writethrough", filepath.Join(base, "Images/virtio.iso")),
    53  		"-snapshot", // critical to avoid saving state between runs.
    54  		"-vnc", ":3",
    55  	)
    56  	c.Env = append(os.Environ(),
    57  		fmt.Sprintf("DYLD_LIBRARY_PATH=%s", filepath.Join(base, "sysroot-macos-arm64/lib")),
    58  	)
    59  	return c
    60  }