CargoSense / dart_sass

Install and run Dart Sass using Elixir.
https://hex.pm/packages/dart_sass
MIT License
102 stars 23 forks source link

mix.install fails on Docker container built on M1 Mac #16

Closed kuroda closed 2 years ago

kuroda commented 2 years ago

When I try to install dart_sass on Docker container built on M1 Macs, mix.install fails with the following message:

** (RuntimeError) could not download dart_sass for architecture: aarch64-unknown-linux-gnu
    (dart_sass 0.3.0) lib/dart_sass.ex:271: DartSass.target/0
    (dart_sass 0.3.0) lib/dart_sass.ex:211: DartSass.install/0
    (mix 1.12.2) lib/mix/task.ex:394: anonymous fn/3 in Mix.Task.run_task/3
    (mix 1.12.2) lib/mix/cli.ex:84: Mix.CLI.run_task/2
    (elixir 1.12.2) lib/code.ex:1261: Code.require_file/2

The docker container was created from the official elixir 1.12.3 image, which is based on Debian 10 (buster).

zacky1972 commented 2 years ago

I read the related following issue: https://github.com/CargoSense/dart_sass/issues/7.

The following commit indicates dart_sass emulates x86_64 in the case of M1: https://github.com/CargoSense/dart_sass/commit/75ab0f064591e72e042725838cd970bbfa483fd9

However, @kuroda seems to run it on Docker with the ARM image. On Docker, Rosetta 2 may be inactive. Then, dart_sass can't emulate x86_64.

I found dart_sass seems to try to load binary corresponding to the architecture and OS from https://sass-lang.com/dart-sass. So I guess publishing the binary compiled for aarch64 from the site solves the issue.

If the maintainers of dart_sass don't have any machine with aarch64, I have such a machine, so I'll compile it if you give me the source.

kuroda commented 2 years ago

As a test, I made the following changes to docker-compose.yml.

version: "3"
services:
  app:
    build: .
    platform: linux/x86_64

Then, the aforementioned error disappeared and dart_sass was downloaded successfully with the following message.

Downloading esbuild from https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.13.6.tgz

However, Docker stops with the following message.

... exited with code 139

Unfortunately, there were no further clues and no solution was found.

mcrumm commented 2 years ago

Hi @kuroda, and apologies for the delay. I think we will only be able to resolve this once sass/dart-sass begins releasing arm64 binaries. Building on M1 Macs (without Docker) only works because we are overriding the detected architecture to download the x86 binary instead.

I am curious about your last message, though. You wrote that dart_sass was downloaded successfully, but the message is the one for esbuild, not dart_sass. Can you verify that dart_sass did download successfully? I am afraid that even if the x86 binary did download, it may be the cause of the segfault (exited with code 139).

mcrumm commented 2 years ago

@zacky1972 hello and thank you for the offer– to my knowledge, aarch64 releases for sass/dart-sass are blocked by required changes and a new release to the Dart SDK, as well as support for aarch64 in GitHub actions. Iirc the updated SDK has been released, so now we are just waiting for CI to catch up. Hopefully soon! :)

kuroda commented 2 years ago

@mcrumm

You are right. I misunderstood that the download of dart_sass was successful instead of esbuild.

jgelens commented 2 years ago

Until then you can maybe use the npm package "sass", the binaries have the same interface.

nathany-copia commented 2 years ago

@mcrumm

Building on M1 Macs (without Docker) only works because we are overriding the detected architecture to download the x86 binary instead.

It's curious that this override happens outside of Docker, but if we RUN mix assets.deploy inside a Docker image (FROM elixir:1.12.3-alpine) then it wants to find aarch64-unknown-linux-musl.

I'm new to running Docker on M1 though -- so I wasn't sure what to expect since the Docker image I'm building doesn't specify aarch64 anywhere -- and it's eventual target is still x86.

Related issue: https://github.com/sass/dart-sass/issues/1125

mcrumm commented 2 years ago

@anmlnath @kuroda I have just published v0.4.0 which includes some bugfixes carried over from the esbuild project. I am not sure they will have any effect, but if you would like to try the latest version and reply with any change in behaviour, or reply to say there was no change, I would really appreciate it :)

nathany-copia commented 2 years ago

@mcrumm Thanks for letting me know.

We have since switched that project over to node-sass, so it's not trivial to test out the new build, but I can keep it in mind for the next time we need sass on a project.

mcrumm commented 2 years ago

@anmlnath No worries, thanks for the update!

iautom8things commented 2 years ago

@mcrumm Thank you for the update. I have a project that I was able to test this on and I'm still seeing the same results, with the latest update (0.4.0).

We're getting by by just using the pure javascript implementation of dart sass.

barkerja commented 2 years ago

Hi @kuroda, and apologies for the delay. I think we will only be able to resolve this once sass/dart-sass begins releasing arm64 binaries. Building on M1 Macs (without Docker) only works because we are overriding the detected architecture to download the x86 binary instead.

It appears dart-sass was just updated to build and deploy arm64 binaries. See https://github.com/sass/dart-sass/commit/55157a576e941f7c97cd11ba3c0b8b8c16e80e8a

mize85 commented 2 years ago

yup, works, without overriding the detected architecture (https://github.com/CargoSense/dart_sass/blob/main/lib/dart_sass.ex#L328) and adding a clause for aarch64 in the case block below 👍

"aarch64" -> "#{platform}-arm64"
mcrumm commented 2 years ago

Sweet, I see there's a published release now :) I will gladly accept a PR for proper arm64 support, otherwise I will try to get to it myself later this week.

mize85 commented 2 years ago

@mcrumm what i have so far.. https://github.com/CargoSense/dart_sass/compare/main...mize85:fix/aarch?expand=1 Not 100% sure if everything else is still working as before though, and if changing the version is ok... Plus.. a test is failing locally, as the file does not exist in version < 1.49.11 (https://github.com/CargoSense/dart_sass/blob/main/test/dart_sass_test.exs#L19)

sax commented 2 years ago

The linked branch works for me on an M1 without Rosetta 2 installed.

mcrumm commented 2 years ago

@mize85 looks good! Please open a PR :)

mize85 commented 2 years ago

👌 https://github.com/CargoSense/dart_sass/pull/24

mcrumm commented 2 years ago

Resolved by e77e988 – thanks @mize85!

adarsh1021 commented 2 years ago

I hope there is a release with these changes soon, so we can directly specify the version in mix.exs without having to mention the github repo and branch @mcrumm :) After installing it, I was facing this error - app/_build/sass-linux-arm64: No such file or directory - would be really grateful if someone could help me out with this! Thanks!

barkerja commented 2 years ago

@adarsh1021 if you're using an alpine image, that is likely why. See https://github.com/sass/dart-sass/issues/617#issuecomment-470936879

adarsh1021 commented 2 years ago

Ah yes, thank you @barkerja !!