From a0a25673542e669561551376431b5029ae5484d4 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 11 Sep 2024 11:50:05 +0100 Subject: [PATCH] Suggest installing Rosetta when extension installation fails due to missing `darwin-arm64` binary, but a `darwin-amd64` binary is available When installing an extension, the CLI must to select the correct binary to download for the machine (see the [`installBin` function](https://github.com/cli/cli/blob/78c1d00eccac1b2ae82ac0bfeea3e2292c98056a/pkg/cmd/extension/manager.go#L240)). By default, the CLI will download a binary matching the current machine's architecture. However, to provide better support for Macs running on Apple Silicon, it will [fall back](https://github.com/cli/cli/blob/78c1d00eccac1b2ae82ac0bfeea3e2292c98056a/pkg/cmd/extension/manager.go#L267-L274) from `darwin-arm64` to `darwin-amd64` if [Rosetta](https://support.apple.com/en-gb/102527) (Apple's compatibility layer) is installed. If Rosetta isn't installed, this fallback doesn't happen, which can lead to surprising and confusing results when one Mac has Rosetta and another doesn't, because the extension will install on one machine but not another. In the situation where a `darwin-arm64` binary isn't available but the CLI can't fall back to `amd64` because Rosetta isn't installed, this updates our error message to suggest installing Rosetta. Closes https://github.com/cli/cli/issues/9592. --- pkg/cmd/extension/manager.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 0ab429c2e..60fe8d239 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -263,12 +263,18 @@ func (m *Manager) installBin(repo ghrepo.Interface, target string) error { } } - // if an arm64 binary is unavailable, fall back to amd64 if it can be executed through Rosetta 2 - if asset == nil && isMacARM && hasRosetta() { + // if using an ARM-based Mac and an arm64 binary is unavailable, fall back to amd64 if a relevant binary is available and Rosetta 2 is installed + if asset == nil && isMacARM { for _, a := range r.Assets { if strings.HasSuffix(a.Name, "darwin-amd64") { - asset = &a - break + if hasRosetta() { + asset = &a + break + } else { + return fmt.Errorf( + "%[1]s unsupported for %[2]s. Install Rosetta with `softwareupdate --install-rosetta` to use the available darwin-amd64 binary, or open an issue: `gh issue create -R %[3]s/%[1]s -t'Support %[2]s'`", + repo.RepoName(), platform, repo.RepoOwner()) + } } } }