Skip to content
New issue

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

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

Already on GitHub? # to your account

binstall installs x86_64 binaries on macOS aarch64 without Rosetta 2 enabled #857

Closed
0xazure opened this issue Mar 4, 2023 · 6 comments · Fixed by #875
Closed

binstall installs x86_64 binaries on macOS aarch64 without Rosetta 2 enabled #857

0xazure opened this issue Mar 4, 2023 · 6 comments · Fixed by #875

Comments

@0xazure
Copy link

0xazure commented Mar 4, 2023

Hi there 👋

New to using cargo-binstall so I hope I'm not misunderstanding the behaviour here, but it seems to be downloading binaries that I can't run on macOS aarch64 (e.g., aarch64-apple-darwin).

$ cargo binstall -V
0.19.3

I wanted to try installing https://github.com/kbknapp/cargo-outdated (which apparently - at least at time of writing - doesn't have prebuilt aarch64-apple-darwin artifacts).

I can see from cargo binstall cargo-outdated --log-level debug that cargo-binstall tries a bunch of extension permutations for aarch64-apple-darwin and then universal-apple-darwin, but then it also tries x86_64-apple-darwin which it dutifully downloaded:

DEBUG Found a binary install source: github.com (x86_64-apple-darwin)
 WARN The package cargo-outdated v0.11.2 will be downloaded from github.com
 INFO This will install the following binaries:
 INFO   - cargo-outdated (cargo-outdated -> /Users/azure/.cargo/bin/cargo-outdated-v0.11.2)
 INFO And create (or update) the following symlinks:
 INFO   - cargo-outdated (/Users/azure/.cargo/bin/cargo-outdated -> cargo-outdated-v0.11.2)
Do you wish to continue? yes/[no]
? y
 INFO Installing binaries...
 INFO Done in 45.764850958s

but which isn't a compatible architecture for my machine:

$ cargo outdated
error: could not execute process `/Users/azure/.cargo/bin/cargo-outdated outdated` (never executed)

Caused by:
  Bad CPU type in executable (os error 86)

I also want to note that the selected architecture/"winning" URL is only visible if you pass --log-level debug, otherwise only the crate name and version are printed:

$ cargo binstall cargo-outdated
 INFO resolve: Resolving package: 'cargo-outdated'
 WARN The package cargo-outdated v0.11.2 will be downloaded from github.com
 INFO This will install the following binaries:
 INFO   - cargo-outdated (cargo-outdated -> /Users/azure/.cargo/bin/cargo-outdated-v0.11.2)
 INFO And create (or update) the following symlinks:
 INFO   - cargo-outdated (/Users/azure/.cargo/bin/cargo-outdated -> cargo-outdated-v0.11.2)

I can see that x86_64-apple-darwin is an alternative target based on this lookup:

AARCH64 => [Some(X86), Some(UNIVERSAL)],

but since x86_64-apple-darwin isn't compatible with aarch64-apple-darwin I don't think this is desireable?

Forcing the target with --target aarch64-apple-darwin results in the expected (at least for me) behaviour of offering to build from source, given that https://github.com/kbknapp/cargo-outdated doesn't have prebuilt binaries for my architecture, though it would be nice if it indicated why it was building from source: that no matching artifact was found.

@passcod
Copy link
Member

passcod commented Mar 4, 2023

I guess we assume you've got Rosetta, but that's not guaranteed

@passcod
Copy link
Member

passcod commented Mar 4, 2023

(To be clear, if you've got Rosetta, x86 is compatible with arm64.)

@NobodyXu
Copy link
Member

NobodyXu commented Mar 4, 2023

Thanks for spotting this bug!
I will fix this in the next release.

Regarding cargo-outdated, you might be able to download that from quickinstall, given that they will build popular crates and crates requested by cargo-quickinstall and cargo-binstall.

@NobodyXu
Copy link
Member

NobodyXu commented Mar 4, 2023

I guess we assume you've got Rosetta, but that's not guaranteed

Yeah and we probably want to add another check for this.

@NobodyXu
Copy link
Member

NobodyXu commented Mar 4, 2023

Seems like MacOS provides no API to check whether Rosetta is enabled, so we will have to fallback to running a x86-64 binary to see if it can be run.

@0xazure
Copy link
Author

0xazure commented Mar 4, 2023

I guess we assume you've got Rosetta, but that's not guaranteed

Ah, I completely forgot about Rosetta; I'm not running any x86_64 apps/binaries on my system and haven't enabled it.

Seems like MacOS provides no API to check whether Rosetta is enabled

I see a couple different options:

  1. I'd be happy with an additional message during binstall in addition to the existing INFO output that could say something like

Could not find a native artifact for aarch64-apple-darwin, falling back to x86_64-apple-darwin (which requires Rosetta 2 to be enabled); rerun with cargo binstall --target aarch64-apple-darwin <BIN_NAME> to build from source instead.

This could also inform the user about other options like quickinstall.

  1. Probably not ideal, but spawning a subprocess to check something like arch -arch x86_64 /usr/bin/true could determine if Rosetta 2 is available.

On my machine this check fails (as expected) like this:

$ arch -arch x86_64 /usr/bin/true
arch: posix_spawnp: /usr/bin/true: Bad CPU type in executable

@0xazure 0xazure changed the title binstall installs incompatible x86_64 binaries on macOS aarch64 binstall installs x86_64 binaries on macOS aarch64 without Rosetta 2 enabled Mar 4, 2023
NobodyXu added a commit that referenced this issue Mar 10, 2023
Fixed #857

Run `arch -arch x86_64 /usr/bin/true` to check whether rosetta2 is
enabled and working.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants