Skip to content

Commit

Permalink
only use vz instead of qemu on m3 macs
Browse files Browse the repository at this point in the history
  • Loading branch information
pb-dod committed Jan 16, 2024
1 parent ca8d93e commit f8aea80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
29 changes: 16 additions & 13 deletions lib/core/rancher/step.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ function ih::setup::core.rancher::test() {
return 1
fi

# Use vz instead of qemu on macOS 13.3 to resolve m3 mac issues.
# See: https://github.com/lima-vm/lima/issues/1996
# Also: https://github.com/rancher-sandbox/rancher-desktop/blob/fcffd3cc071a9414dcf03c895792b5142116ffd4/pkg/rancher-desktop/main/commandServer/settingsValidator.ts#L320-L330
# Use vz (requires macOS >=13.3) instead of qemu on M3 macs to resolve issues.
# More details: https://github.com/lima-vm/lima/issues/1996
local macos_version=$(ih::arch::get_macos_version)
if (( $(echo "$macos_version >= 13.3" | bc -l) )); then
if grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "The PLIST file already uses 'vz' for Virtualization."
else
ih::log::debug "The PLIST file needs to be updated to use 'vz'."
if ih::arch::is_m3_mac; then
if (( $(echo "$macos_version < 13.3" | bc -l) )); then
ih::log::error "macOS version 13.3 or higher is required for M3 Macs."
return 1
elif ! grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "The PLIST file needs to be updated to use 'vz' for M3 Macs."
return 1
fi
fi
Expand Down Expand Up @@ -133,11 +133,14 @@ function ih::setup::core.rancher::install() {
fi
fi

# Use vz instead of qemu on macOS 13.3 to resolve m3 mac issues.
local macos_version=$(ih::arch::get_macos_version)
if (( $(echo "$macos_version >= 13.3" | bc -l) )); then
if ! grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "Updating PLIST to use 'vz' for Virtualization."
# Use vz (requires macOS >=13.3) instead of qemu on M3 macs to resolve issues.
# More details: https://github.com/lima-vm/lima/issues/1996
if ih::arch::is_m3_mac; then
if (( $(echo "$macos_version < 13.3" | bc -l) )); then
ih::log::error "macOS version 13.3 or higher is required for M3 Macs."
return 1 # Abort the installation for M3 Macs
elif ! grep -q "<string>vz</string>" "$PLIST_DST"; then
ih::log::debug "Updating PLIST to use 'vz' for Virtualization for M3 Macs."
sudo sed -i '' 's/<string>qemu<\/string>/<string>vz<\/string>/g' "$PLIST_DST"
fi
fi
Expand Down
9 changes: 9 additions & 0 deletions lib/utils/arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ ih::arch::mbrew() {
ih::arch::get_macos_version() {
sw_vers -productVersion | awk -F '.' '{ printf("%d.%d\n", $1, $2) }'
}

ih::arch::is_m3_mac() {
local hw_model=$(sysctl -n machdep.cpu.brand_string)
if [[ "$hw_model" == *"M3"* ]]; then
return 0 # This is an M3 Mac.
else
return 1 # This is not an M3 Mac.
fi
}

0 comments on commit f8aea80

Please sign in to comment.