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

Bad CPU type in helix editor executable after installing from brew cask on M1 Mac #1997

Closed
davidthewatson opened this issue Apr 6, 2022 · 9 comments
Labels
A-packaging Area: Packaging and bundling C-bug Category: This is a bug E-help-wanted Call for participation: Extra attention is needed O-macos Operating system: macOS

Comments

@davidthewatson
Copy link

Summary

Here's the CLI experience and output of the arch command following:

  ~ [1]> brew tap helix-editor/helix
              brew install helix
==> Tapping helix-editor/helix
Cloning into '/opt/homebrew/Library/Taps/helix-editor/homebrew-helix'...
remote: Enumerating objects: 59, done.
remote: Counting objects: 100% (59/59), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 59 (delta 12), reused 15 (delta 1), pack-reused 0
Receiving objects: 100% (59/59), 11.42 KiB | 2.28 MiB/s, done.
Resolving deltas: 100% (12/12), done.
Tapped 1 formula (13 files, 18.2KB).
==> Downloading https://github.com/helix-editor/helix/releases/download/22.03/helix-22.03-x86_64-macos.tar.xz
==> Downloading from https://objects.githubusercontent.com/github-production-release-asset-2e65be/268424739/6c4c3f64-b11b-4da4-be09-6406
######################################################################## 100.0%
==> Installing helix from helix-editor/helix
🍺  /opt/homebrew/Cellar/helix/22.03: 408 files, 71.5MB, built in 2 seconds
==> Running `brew cleanup helix`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
 ~> hx
/opt/homebrew/bin/hx: line 2: /opt/homebrew/Cellar/helix/22.03/libexec/hx: Bad CPU type in executable
/opt/homebrew/bin/hx: line 2: /opt/homebrew/Cellar/helix/22.03/libexec/hx: Undefined error: 0
 ~ [127]> arch
arm64

Note that arch gives arm64 but brew has installed x86_64.

I'd also recommend making the arm vs x86 distinction clear with respect to platform builds for macos. Right now, it's not clear whether M1 is supported in any way other than running linux.

Reproduction Steps

I tried this:

  1. hx

I expected this to happen:

helix editor loaded in terminal.

Instead, this happened:

 ~> hx
    /opt/homebrew/bin/hx: line 2: /opt/homebrew/Cellar/helix/22.03/libexec/hx: Bad CPU type in executable
    /opt/homebrew/bin/hx: line 2: /opt/homebrew/Cellar/helix/22.03/libexec/hx: Undefined error: 0

Helix log

No response

Platform

macos

Terminal Emulator

Apple Version 2.12.5 (444)

Helix Version

helix 22.03

@davidthewatson davidthewatson added the C-bug Category: This is a bug label Apr 6, 2022
@the-mikedavis the-mikedavis added the A-packaging Area: Packaging and bundling label Apr 6, 2022
@the-mikedavis
Copy link
Member

The tap definition is over here: https://github.com/helix-editor/homebrew-helix/blob/6afb869f03eaa59a3bdeadbd5acd114a2ecfe575/Formula/helix.rb

I see a comment that makes it seem like it's expected that the x86_64 binary should work on arm64 but I'm not sure why that is. Maybe the author meant on rosetta2?

@davidthewatson
Copy link
Author

davidthewatson commented Apr 6, 2022

Thanks, @the-mikedavis that's helpful.

That makes sense; however, the important part of the ux that's not getting triggered here is the dialog box that asks the user whether they want to install and use rosetta.

I see a comment that makes it seem like it's expected that the x86_64 binary should work on arm64 but I'm not sure why that is. Maybe the author meant on rosetta2?

There's some good detail here on SO.

None of that behavior happened here and while it's good to know the underlying details, I'm not sure of the status of the rosetta dialog box trigger with respect to brew?

@the-mikedavis the-mikedavis added the O-macos Operating system: macOS label Apr 7, 2022
@the-mikedavis
Copy link
Member

I'm not very knowledgeable about how this works in brew and how brew usually treats rosetta and the x86_64 vs. arm64 divide. If anyone knows how to improve the formula, a PR would be most welcome!

@the-mikedavis the-mikedavis added the E-help-wanted Call for participation: Extra attention is needed label Apr 8, 2022
@wiremoons
Copy link

I'm not very knowledgeable about how this works in brew and how brew usually treats rosetta and the x86_64 vs. arm64 divide. If anyone knows how to improve the formula, a PR would be most welcome!

Another rust command line application that is supported under brew that I use is bat.

In case it helps:

The error is being caused (as mentioned above) by installing a Intel x86 version of helix editor (ie hx) onto an Apple Silicon M1 (aarch64/arm64) computer. Unless for other reasons the user already has Apple's Rosetta 2 capability installed, then the computer can't run the intel binary. A native (aarch64/arm64) version of the helix editor needs to provided instead, then it will run fine.

Rust is able to compile applications that support both Apple computers using Intel x86 and Apple M1 (aarch64) binaries - with bat being one such example. Most Homebrew programs provide both, and install the correct binary for the Apple computer architectures being used.

Sorry I can help further, but I don't maintain any Homebrew taps, and I don't develop with Rust to help with building a Apple aarch64 version either. Hopefully someone else can assist in fixing this, so I can try Helix out on my computer, after seeng the recent HackerNews article :)

Should a user want to install Rosetta 2 just to use the non native version of hx, then this command should install it: softwareupdate --install-rosetta. Not really the ideal solution - but a good workaround if needed!

@the-mikedavis
Copy link
Member

I'm curious if when you install bat via brew, does it do the compilation when you brew install bat? Another formula like that is zellij and it also builds from source in the formula. I would say we should do the same thing, but I suspect that the formulas in homebrew core get built and cached by some process in homebrew so not all users need to build it themselves (I might be wrong, I'm not a regular homebrew user).

W.r.t. providing a aarch64 pre-built image: it would be great if we could but there isn't currently a github actions runner that would support it. We could try cross-compiling from an x86_64 macos runner but the cross-compiler for x86_64 linux to arm64 linux was horribly old and couldn't compile some of the tree-sitter parsers.

@wiremoons
Copy link

Hi @the-mikedavis
No - there is no compilation on my computer when it is installed. It just installs the binary for me when I run brew install bat. I don't have any Rust compiler installed on my computer anyway, so it would not be possible to build it for me either.

Below are a few outputs in case they are of any further assistance:

% brew install bat

==> Downloading https://ghcr.io/v2/homebrew/core/bat/manifests/0.20.0
Already downloaded: /Users/simon/Library/Caches/Homebrew/downloads/a1dbc33109948f5e5a4b2814b3b380f8025790740b30d486f6194ea4bb9aaf74--bat-0.20.0.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/bat/blobs/sha256:8cf2fa7f8e76d0bb98eb3424f092c4fc7ee28c8dc076ed4647381f7a9dd93425
Already downloaded: /Users/simon/Library/Caches/Homebrew/downloads/456f55009befa386bb38717d83fb7b3a24514d01537ca586df395c74b8f2ac64--bat--0.20.0.arm64_monterey.bottle.tar.gz
==> Pouring bat--0.20.0.arm64_monterey.bottle.tar.gz
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions
==> Summary
🍺  /opt/homebrew/Cellar/bat/0.20.0: 14 files, 4.3MB
==> Running `brew cleanup bat`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

% brew info bat

bat: stable 0.20.0 (bottled)
Clone of cat(1) with syntax highlighting and Git integration
https://github.com/sharkdp/bat
/opt/homebrew/Cellar/bat/0.20.0 (14 files, 4.3MB) *
  Poured from bottle on 2022-04-08 at 15:06:06
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/bat.rb
License: Apache-2.0 or MIT
==> Dependencies
Build: rust ✘
==> Caveats
zsh completions have been installed to:
  /opt/homebrew/share/zsh/site-functions


% file /opt/homebrew/bin/bat

/opt/homebrew/bin/bat: Mach-O 64-bit executable arm64

@the-mikedavis
Copy link
Member

In that case, we could probably fix this by getting the formula set up in homebrew core (see here). Iirc there was some trouble getting the tests to work which was preventing it from being merged for the 0.6.0 release.

@wiremoons
Copy link

That would be good if it were possible to use Homebrew core to solve the issue 👍 .

Sorry - I noticed I failed to answer your second question regarding building for Apple Silicon computers on Github!

This is unfortunately a common issue, and until Microsoft (owners of GitHub) provide the anticipated supporting computers to build on, cross compiling on macOS is the only way to fix it I think (ie without using machines outside of the GitHub build environments anyway!). There is a an open issue here with more information: actions/runner-images#2187

I did notice that the Rust project cross compile macOS builds from the GitHub using the Intel x86 macOS systems to create Apple M1 arm64/aarch64 binaries for some of the Rust projects repos. I haven't looked at them in detail - but the GitHub actions that they have in their repos maybe of help to see how this is achieved.

Also see this issue here: rust-lang/rustup#2413

I think macOS cross compile works, as a Apple Intel x86 machines with the XCode compiler and tools installed can be used to build an Apple M1 native arm64 binary too. It is a command line switch I think when the compiler is called. As Github does have x86 macOS available for build systems, with XCode pre-installed too, these are being used for now by some projects.

@the-mikedavis
Copy link
Member

Closing this now since we're in homebrew core plus we have cross-compiled arm darwin builds for releases (#3137)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-packaging Area: Packaging and bundling C-bug Category: This is a bug E-help-wanted Call for participation: Extra attention is needed O-macos Operating system: macOS
Projects
None yet
Development

No branches or pull requests

3 participants