Skip to content

Build aarch64-apple-darwin binaries on CI #6989

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

Merged
merged 1 commit into from
Dec 22, 2020

Conversation

lnicola
Copy link
Member

@lnicola lnicola commented Dec 21, 2020

This splits the dist matrix job into four and tries to make xtask dist more principled about target and artifact naming.

@lnicola
Copy link
Member Author

lnicola commented Dec 21, 2020

I have no idea if this will work, but I couldn't figure how to trigger the action on my fork.

@richiksc
Copy link

richiksc commented Dec 21, 2020

I have no idea if this will work, but I couldn't figure how to trigger the action on my fork.

@lnicola I guess you could get the action to trigger by merging this change into trigger-nightly on your fork?

@lnicola
Copy link
Member Author

lnicola commented Dec 21, 2020

I think you can also trigger them manually, but actions don't usually run on forks.

@lnicola
Copy link
Member Author

lnicola commented Dec 21, 2020

Oh, I had to push it to the master branch, then wait for a while.

@richiksc
Copy link

@lnicola Looks like it's building on your fork after pushing to trigger-nightly: https://github.com/lnicola/rust-analyzer/runs/1591171874

@richiksc
Copy link

Hmm, looks like the build failed during linking. I think it's because compilation for aarch64-apple-darwin needs to use the Xcode 12 macosx11.0 SDK, but right now, it's using the macosx10.15 SDK by default.

https://github.com/lnicola/rust-analyzer/runs/1591171874#step:9:477

= note: ld: warning: ignoring file /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libresolv.tbd, missing required architecture arm64 in file /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libresolv.tbd

There are two ways around this: you can manually select the macOS 11 SDK, according to shepmaster's instructions:

SDKROOT=$(xcrun -sdk macosx11.0 --show-sdk-path) \
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx11.0 --show-sdk-platform-version) \
cargo build --target=aarch64-apple-darwin

Or you can set GitHub Actions to run on the macos-11.0 runner, which is what I did on a simple Rust command-line tool project I contributed to. That should require no extra configuration to cross-compile for aarch64-apple-darwin.

jobs:
  dist:
    name: dist
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
-        os: [ubuntu-16.04, windows-latest, macos-latest]
+        os: [ubuntu-16.04, windows-latest, macos-11.0]

@richiksc
Copy link

Also, will the necessary code change to code/src/main.ts be in this PR or another PR if this gets merged? platform would need to be set to "mac-arm", I'm guessing.

@lnicola
Copy link
Member Author

lnicola commented Dec 21, 2020

Thanks for looking it up -- I had to step out for a bit. I do wonder if the macos-11.0 binaries will be compatible with whatever macos-latest works on.

Also, will the necessary code change to code/src/main.ts be in this PR or another PR if this gets merged? platform would need to be set to "mac-arm", I'm guessing.

Yeah, I planned to do it in a different PR, after making sure that the binaries are built fine.

@richiksc
Copy link

@lnicola Looks like the binaries built on CI: https://github.com/lnicola/rust-analyzer/releases/tag/nightly

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

I don't think they did, there's no ARM binary. Maybe it used the code from the wrong branch? EDIT: ah, the real nightly kicked in and overwritten the release.

Anyway, I suppose it would be better to restructure the workflow to build them in parallel.

@richiksc
Copy link

richiksc commented Dec 22, 2020

I don't think they did, there's no ARM binary. Maybe it used the code from the wrong branch? EDIT: ah, the real nightly kicked in and overwritten the release.

Anyway, I suppose it would be better to restructure the workflow to build them in parallel.

Yep, the real nightly kicked in. I wish there was a way for you to tag it to build as separate. Potentially add an on: push: tags: build-* or something and push a tag, and then have the release action push it to that tag.

I don't know if there's a way to build them in parallel in the same job. Wouldn't it take more time to set up another whole macOS runner just to build the additional binary?

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

@richiksc if you don't mind, can you download a rust-analyzer-mac-arm file from https://github.com/lnicola/rust-analyzer/releases/tag/nightly and give it a spin? If you're having issues with Code, you can run it from the command line, e.g. rust-analyzer-mac-arm analysis-stats . in the RA repo (testing both of the x86-64 and aarch64 versions might be a nice benchmark).

I don't know if there's a way to build them in parallel in the same job. Wouldn't it take more time to set up another whole macOS runner just to build the additional binary?

In separate jobs, I meant. Not sure if it's better to use a single job or two, but it might make sense to have two. I tried to implement that (untested, I don't want to trigger another release until someone tests the latest one)

@lnicola lnicola force-pushed the apple-arm branch 2 times, most recently from 359beb5 to 45e4f25 Compare December 22, 2020 07:37

let toolchain = get_toolchain(&target);
cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this works..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe +{toolchain} syntax? Yeah, it should work

Copy link
Member

@matklad matklad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for looking into this, @lnicola !

As a super-minor stylistic changes, I am not a fan of get_ / compute_ / find_ preffixes on function names (get_executable_extension). I feel that they add zero additional information, and can be removed.

It might be argueed that let ext = get_extension(target) reads better than let ext = extension(target), but that depends on how do you look at the code.

If you look at it as action, then, yes, first one is better. But you can also see this as a predicate/assetion -- ext is extension of target. In that second reading, get prefix is not required.

To be clear, this is absolutely irrelevant in practice :-)


let toolchain = get_toolchain(&target);
cmd!("cargo +{toolchain} build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --release").run()?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THe +{toolchain} syntax? Yeah, it should work

}
}

fn get_executable_extension(target: &str) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn get_executable_extension(target: &str) -> String {
fn get_executable_suffix(target: &str) -> String {

https://doc.rust-lang.org/std/env/consts/constant.EXE_SUFFIX.html

extensioni s a thing without ..

}
}

fn get_release_artifact_name(target: &str) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the plan here is to add full target tripple to the executable name? With two different macs that makes sense actually, 👍.

For the transition, we should adjust vscode, and broadcast the change to the clients issue. We might also just publish to sets of artifacts? THat is, run cp rust-analyzer-windows.exe rust-analyzer-x86_64-pc-windows-msvc.exe in `.yaml.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the plan here is to add full target tripple to the executable name? With two different macs that makes sense actually, +1.

We also had requests for Windows ARM binaries, so using the target tuple seems reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the transition, we should adjust vscode, and broadcast the change to the clients issue. We might also just publish to sets of artifacts? THat is, run cp rust-analyzer-windows.exe rust-analyzer-x86_64-pc-windows-msvc.exe in `.yaml.

I did it the other way around, but in xtask.

@matklad
Copy link
Member

matklad commented Dec 22, 2020

r=me

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

As a super-minor stylistic changes, I am not a fan of [...]

No problem, I shortened those, maybe even too much. I left get_target unchanged since it was different. Arguably, it could be called pick_target or something else, but I'd rather we passed RA_TARGET explicitly.. actually let me to just that. EDIT: no, I already tried it -- the problem is that I don't know how to determine the current target tuple (as a fallback, in case you want to run cargo xtask dist locally without bothering with the env variable). I'll use CARGO_BUILD_TARGET. That doesn't work either unless we're in a build script.

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

I triggered another test run (sorry), to make sure the workflow changes still work.

@lnicola lnicola force-pushed the apple-arm branch 4 times, most recently from 55173a3 to 3f7e904 Compare December 22, 2020 10:17
@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

bors seems stuck again (I think I've seen it merge workflows changes once), I'll merge manually.

@lnicola lnicola merged commit 02d8cf8 into rust-lang:master Dec 22, 2020
@lnicola lnicola deleted the apple-arm branch December 22, 2020 12:01
bors bot added a commit that referenced this pull request Dec 22, 2020
6989: Build aarch64-apple-darwin binaries on CI r=matklad a=lnicola

This splits the `dist` matrix job into four and tries to make `xtask dist` more principled about target and artifact naming.

Co-authored-by: Laurențiu Nicola <[email protected]>
@bors
Copy link
Contributor

bors bot commented Dec 22, 2020

@richiksc
Copy link

@richiksc if you don't mind, can you download a rust-analyzer-mac-arm file from https://github.com/lnicola/rust-analyzer/releases/tag/nightly and give it a spin? If you're having issues with Code, you can run it from the command line, e.g. rust-analyzer-mac-arm analysis-stats . in the RA repo (testing both of the x86-64 and aarch64 versions might be a nice benchmark).

@lnicola I wasn't able to test this earlier due to my timezone. I'd love to test the binary today but I can't see a release on your fork anymore - was it deleted for some reason? I can definitely run the benchmark in the rust-analyzer repo if necessary.

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

Oof, I deleted the branch and they're gone. I triggered a new build, but they don't seem to have a lot of macos-11.0 runners, so it's gonna take a while (~40 minutes) to run. I'll ping you.

I can definitely run the benchmark in the rust-analyzer repo if necessary.

It's not necessary, of course :-).

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

@richiksc I think it's ready

@richiksc
Copy link

@lnicola Hmm, the release seems to have both binaries with the old naming scheme ("rust-analyzer-mac") and the new naming scheme ("rust-analyzer-x86_64-apple-darwin") - are you building it twice?

@matklad
Copy link
Member

matklad commented Dec 22, 2020 via email

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

are you building it twice

No, it's just making a copy.

@richiksc
Copy link

@lnicola Ok, I've ran the benchmark.

Here's the results (13" MacBook Pro, M1, Late 2020, 16GB RAM):

rust-analyzer-aarch64-apple-darwin (ARM Native)

% ./rust-analyzer-aarch64-apple-darwin analysis-stats .
Database loaded 641.27ms
Crates in this dir: 36
Total modules found: 572
Total declarations: 11043
Total functions: 8630
Item Collection: 7.37s
30/8630 100% processing: logger::flushTotal expressions: 236758                nExpressions of unknown type: 2669 (1%)                             
Expressions of partially unknown type: 2053 (0%)
Type mismatches: 857
Inference: 14.35s
Total: 21.72s

rust-analyzer-x86_64-apple-darwin (Rosetta 2)

% ./rust-analyzer-x86_64-apple-darwin analysis-stats . 
Database loaded 913.53ms
Crates in this dir: 36
Total modules found: 572
Total declarations: 11043
Total functions: 8630
Item Collection: 11.22s
30/8630 100% processing: logger::flushTotal expressions: 236758                nExpressions of unknown type: 2669 (1%)                             
Expressions of partially unknown type: 2053 (0%)
Type mismatches: 857
Inference: 22.46s
Total: 33.68s

As you can see, a significant 35% reduction in analysis time just by being ARM native.

This is the second run of the x86_64 binary, as the first time, it just hung. I'm guessing it was because Rosetta 2 was performing AOT translation of it. It reported Database loaded 22s after killing it with ^C.

@lnicola
Copy link
Member Author

lnicola commented Dec 22, 2020

Then it works! Can you also use it with Code? You can set the server path in the settings.

@richiksc
Copy link

richiksc commented Dec 22, 2020

Then it works! Can you also use it with Code? You can set the server path in the settings.

@lnicola Yep, works great on the arm64 native Insiders build of VSCode!

Edit: this is the rust-analyzer extension v0.2.424 downloaded from the VSCode Extension Marketplace - I didn't load the nightly vsix from your release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants