rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.28k stars 1.61k forks source link

Ship binaries for Apple Silicon Macs (aarch64-apple-darwin) #6732

Closed TDHolmes closed 3 years ago

TDHolmes commented 3 years ago

I tried setting up my new Mac with rust-analyzer and got an error that binaries aren't shipped for this architecture. Makes sense as it's so new, but getting support for this would be great.

kiljacken commented 3 years ago

The limitations mentioned in #5256 are still in effect. Until GitHub actions provides a runner for your specific platform, we're unable to provide nightly builds for that platform. Please use the rustup component instead.

lnicola commented 3 years ago

Note that the rustup component isn't always up-to-date. I'd recommend building from source.

TDHolmes commented 3 years ago

Yeah I've installed from source in the meantime. I would assume GitHub actions will eventually support this, so can we keep this open until that happens?

jonas-schievink commented 3 years ago

How hard is it to cross-compile for this target from x86_64 macOS? If it's just one rustup target add away we can consider it.

TDHolmes commented 3 years ago

Just tried this on my intel Mac and it compiled on nightly with

rustup target add aarch64-apple-darwin
cargo build --target aarch64-apple-darwin

so looks like it is that simple!

richiksc commented 3 years ago

rustup v1.23.0 has native suport for aarch64-apple-darwin, and you can add the target as long as you're on beta or nightly Rust v1.49.0. It's super easy to cross compile if you're using Big Sur, and if you're using older versions of macOS you just need to have Xcode 12 command line tools and the macOS 11 SDK installed and set some environment variables.

Here are the instructions for cross-compilation from one of the maintainers of Rust, @shepmaster: https://github.com/shepmaster/rust/blob/silicon/silicon/README.md

Here's the tracking issue for Apple Silicon support: https://github.com/rust-lang/rust/issues/73908

Rust for aarch64-apple-darwin is a Tier 2 target and in beta, but it seems to work pretty well. The only reason it's not Tier 1 yet is the lack of availability of CI hardware for running the test suite.

richiksc commented 3 years ago

The limitations mentioned in #5256 are still in effect. Until GitHub actions provides a runner for your specific platform, we're unable to provide nightly builds for that platform. Please use the rustup component instead.

@kiljacken What's the update on this, given that GitHub Actions now has macosx11.0 runners, and Rust beta and nightly support native cross-compilation for aarch64-apple-darwin on macOS?

bjorn3 commented 3 years ago

While cross-compilation to ARM macOS is supported by rustc, there is currently no way to run the tests on ARM as Github actions doesn't yet have a runner for this.

lnicola commented 3 years ago

I think building binaries but not running tests is a reasonable compromise since most of RA is platform-independent anyway.

richiksc commented 3 years ago

I think building binaries but not running tests is a reasonable compromise since most of RA is platform-independent anyway.

You could always mark it as a "Tier 2" platform until you can run tests. Shipping binaries, even ones that might be unstable, is still better than no support at all.

phungleson commented 3 years ago

Hi everyone, sorry, it is still not clear for me on how to use rust-analyzer with aarch64.

I tried to checked out the project, and run

cargo build --target aarch64-apple-darwin --release

Then I copied ./target/release/rust-analyzer to my ~/.cargo/bin but when I launch vs code it still shows me this message

Bootstrap error [Error: Rust Analyzer Language Server is not available. Please, ensure its [proper installation

What else do I need to do to start using this? Thanks in advance, cheers.

phungleson commented 3 years ago

Ok after debugging a while looks like we need to change this line https://github.com/rust-analyzer/rust-analyzer/blob/c3d21ea05a1d1e1a88a983773fd821f6f6470264/editors/code/src/main.ts#L291

to something like:

if (process.arch === "x64" || process.arch === "ia32" || process.arch === "arm64") {

Do you want me to make a PR for this?

TDHolmes commented 3 years ago

@phungleson all I did was cargo xtask install when compiling from my M1 device. No code modification was needed for me.

phungleson commented 3 years ago

Thanks @TDHolmes I am running code in arm mode so it might be the difference?

bjorn3 commented 3 years ago

The difference is that you are using the extension from the vscode marketplace instead of the one that cargo xtask install would install. The one from the vscode marketplace will try to download the corresponding version from github. The one installed using cargo xtask install will use the locally built one. There is an extension config to define the path to the rust-analyzer executable.

phungleson commented 3 years ago

Ah ok yeah looks like this issue is about building the rust library while my issue is about running the extension for code, which is also in this repo.

In that case it is still worth putting in the fix for the extension?

I changed my extension locally and it managed to download corresponding version of rust-analyser and run as usual albeit it is Intel version.

lnicola commented 3 years ago

@phungleson to run the native version, you should set rust-analyzer.serverPath to point to a binary you've compiled and then you can undo that change to the extension.

But maybe we should still apply your change: it's not the best solution (ideally, we'd build and release binaries in CI), but it will make RA work again for users with new Apple devices. Do you want to file that PR?

lnicola commented 3 years ago

https://github.com/rust-analyzer/rust-analyzer/pull/6989 is untested, but might be a starting point to providing aarch64-apple-darwin binaries.

phungleson commented 3 years ago

Hey thanks, I made a PR here https://github.com/rust-analyzer/rust-analyzer/pull/6990

I have changed my rust-analyzer.serverPath but looks like there is some mismatch of my rust-analyzer, it crashes.

How do I know which version of rust-analyzer is compatible to my extension?

lnicola commented 3 years ago

Which Code version are you using? Maybe try the RA release from last week.

richiksc commented 3 years ago

🎉 With #6989 and #7001 merged, Apple Silicon support should be coming in nightly tonight, and in stable ~whenever they decide to do a new release~ next Monday! 🎉

Thanks so much for your time and effort @lnicola!

bjorn3 commented 3 years ago

There is a new release every monday.

TDHolmes commented 3 years ago

This seems to be working for me now! Should this be closed? Thanks for enabling this so quickly

lnicola commented 3 years ago

Yes! Thanks for testing.

JoshuaBrest commented 1 year ago

They should also ship this for alpine :/

bjorn3 commented 1 year ago

We already do. https://github.com/rust-lang/rust-analyzer/releases/tag/2023-06-05 there is rust-analyzer-alpine-x64.vsix and rust-analyzer-x86_64-unknown-linux-musl.gz.

JoshuaBrest commented 1 year ago

We already do. https://github.com/rust-lang/rust-analyzer/releases/tag/2023-06-05 there is rust-analyzer-alpine-x64.vsix and rust-analyzer-x86_64-unknown-linux-musl.gz.

thats x86.

bjorn3 commented 1 year ago

You mean shipping binaries for aarch64 alpine? Didn't connect the dots. My bad. Opening a new issue would be helpful I think.

JoshuaBrest commented 1 year ago

You mean shipping binaries for aarch64 alpine? Didn't connect the dots. My bad. Opening a new issue would be helpful I think.

I did, sorry for my rudeness. https://github.com/rust-lang/rust-analyzer/issues/15004