Skip to content

Commit 78e2be7

Browse files
committed
feat: report error when running under rosetta
Signed-off-by: pengyu <[email protected]>
1 parent e4ede4f commit 78e2be7

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

cmd/limactl/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"runtime"
99
"strings"
1010

11+
"github.com/lima-vm/lima/pkg/osutil"
1112
"github.com/lima-vm/lima/pkg/store/dirnames"
1213
"github.com/lima-vm/lima/pkg/version"
1314
"github.com/mattn/go-isatty"
@@ -60,6 +61,12 @@ func newApp() *cobra.Command {
6061
if debug {
6162
logrus.SetLevel(logrus.DebugLevel)
6263
}
64+
65+
if osutil.IsBeingRosettaTranslated() {
66+
// running under rosetta would provide inappropriate runtime.GOARCH info, see: https://github.com/lima-vm/lima/issues/543
67+
return errors.New("limactl is running under rosetta, please reinstall lima with native arch")
68+
}
69+
6370
if runtime.GOOS == "windows" && isatty.IsCygwinTerminal(os.Stdout.Fd()) {
6471
formatter := new(logrus.TextFormatter)
6572
// the default setting does not recognize cygwin on windows

pkg/osutil/rosetta_darwin.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package osutil
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/sirupsen/logrus"
7+
"golang.org/x/sys/unix"
8+
)
9+
10+
func IsBeingRosettaTranslated() bool {
11+
ret, err := unix.SysctlUint32("sysctl.proc_translated")
12+
if err != nil {
13+
const fallback = false
14+
if err == unix.ENOENT {
15+
return false
16+
}
17+
18+
err = fmt.Errorf(`failed to read sysctl "sysctl.proc_translated": %w`, err)
19+
logrus.WithError(err).Warnf("failed to detect whether running under rosetta, assuming %v", fallback)
20+
return fallback
21+
}
22+
23+
return ret != 0
24+
}

pkg/osutil/rosetta_others.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//go:build !darwin
2+
// +build !darwin
3+
4+
package osutil
5+
6+
func IsBeingRosettaTranslated() bool {
7+
return false
8+
}

0 commit comments

Comments
 (0)