Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm: make rosetta emulation configurable #555

Merged
merged 2 commits into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ func init() {
}
if util.MacOS13OrNewer() {
startCmd.Flags().StringVarP(&startCmdArgs.VMType, "vm-type", "t", defaultVMType, "virtual machine type ("+types+")")
if util.MacOS13OrNewerOnM1() {
startCmd.Flags().BoolVar(&startCmdArgs.VZRosetta, "vz-rosetta", false, "enable Rosetta for amd64 emulation")
}
}

// config
Expand Down Expand Up @@ -221,7 +224,10 @@ func mountsFromFlag(mounts []string) []config.Mount {
}

func setDefaults(cmd *cobra.Command) {
startCmdArgs.VMType = "qemu"
if startCmdArgs.VMType == "" {
startCmdArgs.VMType = "qemu"
}

if util.MacOS13OrNewer() {
// changing to vz implies changing mount type to virtiofs
if cmd.Flag("vm-type").Changed && startCmdArgs.VMType == "vz" && !cmd.Flag("mount-type").Changed {
Expand Down Expand Up @@ -364,6 +370,11 @@ func prepareConfig(cmd *cobra.Command) {
startCmdArgs.VMType = current.VMType
}
}
if util.MacOS13OrNewerOnM1() {
if !cmd.Flag("vz-rosetta").Changed {
startCmdArgs.VZRosetta = current.VZRosetta
}
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ type Config struct {
Network Network `yaml:"network,omitempty"`
Env map[string]string `yaml:"env,omitempty"` // environment variables

// VM VMType
VMType string `yaml:"vmType,omitempty"`
// VM
VMType string `yaml:"vmType,omitempty"`
VZRosetta bool `yaml:"rosetta,omitempty"`

// volume mounts
Mounts []Mount `yaml:"mounts,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ docker: {}
# Default: qemu
vmType: qemu

# Utilise rosetta for amd64 emulation (requires m1 mac and vmType `vz`)
# Default: false
rosetta: false

# Volume mount driver for the virtual machine (virtiofs, 9p, sshfs).
#
# virtiofs is limited to macOS and vmType `vz`. It is the fastest of the options.
Expand Down
4 changes: 2 additions & 2 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) {
l.VMType = VZ

// Rosetta is only available on M1
if l.Arch == environment.AARCH64 {
if conf.VZRosetta && util.MacOS13OrNewerOnM1() {
if util.RosettaRunning() {
l.Rosetta.Enabled = true
l.Rosetta.BinFmt = true
} else {
logrus.Warnln("Rosetta2 is not installed, linux/amd64 containers will run much slower")
logrus.Warnln("Unable to enable Rosetta: Rosetta2 is not installed")
logrus.Warnln("Run 'softwareupdate --install-rosetta' to install Rosetta2")
}
}
Expand Down
5 changes: 5 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func MacOS() bool {
return runtime.GOOS == "darwin"
}

// MacOS13OrNewer returns if the current OS is macOS 13 or newer.
func MacOS13OrNewerOnM1() bool {
return runtime.GOARCH == "arm64" && MacOS13OrNewer()
}

// MacOS13OrNewer returns if the current OS is macOS 13 or newer.
func MacOS13OrNewer() bool {
if !MacOS() {
Expand Down