golang.org/x/build@v0.0.0-20240506185731-218518f32b70/env/darwin/aws/qemu.sh (about)

     1  #!/bin/bash
     2  # Copyright 2022 The Go Authors. All rights reserved.
     3  # Use of this source code is governed by a BSD-style
     4  # license that can be found in the LICENSE file.
     5  
     6  # Start macOS VM.
     7  
     8  if (( $# < 3 )); then
     9    echo "Usage: $0 <disk-image.qcow2> <OSK value> <VNC port index> [extra qemu args]"
    10    exit 1
    11  fi
    12  
    13  DISK=$1
    14  OSK=$2
    15  PORT=$3
    16  EXTRA_ARGS=${@:4}
    17  
    18  OVMF_CODE="$HOME/sysroot-macos-x86_64/share/qemu/edk2-x86_64-code.fd"
    19  
    20  # These arguments should be kept in sync with cmd/runqemubuildlet/darwin.go.
    21  args=(
    22    -m 10240
    23    -cpu host
    24    -machine q35
    25    -usb -device usb-kbd -device usb-tablet
    26    # macOS only likes a power-of-two number of cores, but odd socket count is
    27    # fine.
    28    -smp cpus=6,sockets=3,cores=2,threads=1
    29    -device usb-ehci,id=ehci
    30    -device nec-usb-xhci,id=xhci
    31    -global nec-usb-xhci.msi=off
    32    -device isa-applesmc,osk="$OSK"
    33    -drive if=pflash,format=raw,readonly=on,file="$OVMF_CODE"
    34    -smbios type=2
    35    -device ich9-intel-hda -device hda-duplex
    36    -device ich9-ahci,id=sata
    37    -drive id=MacHDD,if=none,format=qcow2,file="$DISK"
    38    -device ide-hd,bus=sata.2,drive=MacHDD
    39    # DHCP range is a dummy range. The actual guest IP is assigned statically
    40    # based on the MAC address matching an entry in /etc/bootptab.
    41    -netdev vmnet-shared,id=net0,start-address=192.168.64.1,end-address=192.168.64.100,subnet-mask=255.255.255.0
    42    -device virtio-net-pci,netdev=net0,id=net0,mac=52:54:00:c9:18:0$PORT # for macOS >= 11
    43    # -device vmxnet3,netdev=net0,id=net0,mac=52:54:00:c9:18:0$PORT # for macOS < 11
    44    -monitor stdio
    45    -device VGA,vgamem_mb=128
    46    -M accel=hvf
    47    -display vnc=127.0.0.1:"$PORT"
    48  )
    49  
    50  sudo env DYLD_LIBRARY_PATH="$HOME/sysroot-macos-x86_64/lib" "$HOME/sysroot-macos-x86_64/bin/qemu-system-x86_64" "${args[@]}" ${EXTRA_ARGS:+$EXTRA_ARGS}