typelevel / typelevel-nix

Development tools for Typelevel projects
Apache License 2.0
109 stars 12 forks source link

scala-cli doesn't compile for aarch64-darwin #12

Closed amarrella closed 1 year ago

amarrella commented 2 years ago

Hi! Thanks again for the project!

I've tried running it on a M1 mac and it fails because scala-cli doesn't support aarch64-darwin yet (i tried compiling it from scratch to contribute directly upstream but no success so far).

Luckily x86 packages still work on the M1 (via rosetta) even if not as performantly (but this is fine for scala-cli i believe). Do you think it would be a good idea to add some logic to overlay x86_64 scala cli on aarch64 architectures? Or provide an example in the docs?

I've worked around it in my local project like this and it works, but there is probably a more robust way

let
pkgs-x86_64 = import nixpkgs {
    system = "x86_64-darwin";
};
scala-cli-overlay = final: prev: {
    scala-cli = pkgs-x86_64.scala-cli;
};
pkgs = import nixpkgs {
    inherit system;
    overlays = [ typelevel-nix.overlay scala-cli-overlay ];
};
rossabaker commented 2 years ago

I didn't realize it had any native dependencies, so I'm surprised that doesn't just work. Yeah, adding that overlay for aarch64-darwin seems like an okay workaround to me. Would you like to submit a PR?

kubukoz commented 1 year ago

This will work but use the wrong JVM. You need to override the JRE for the x86 scala-cli so that it uses an arm-compiled one (otherwise scala-cli's bloop will run with rosetta, which... will be really slow).

I'm opening a PR asap :)

kubukoz commented 1 year ago

@rossabaker it's not about native dependencies - the scala-cli derivation is currently simply downloading an artifact from GitHub releases, and these don't include ARM variants for either Mac nor Linux. I think the original reason is that GH Actions didn't provide runners for these machines and (specifically macs) couldn't be emulated with something like qemu. Not sure if that's changed now.

I tried to build scala-cli from source in Nix, but with my limited time and knowledge of how Mill can be made reproducible I failed. Might try at some later point.