elixir-lang / elixir

Elixir is a dynamic, functional language for building scalable and maintainable applications

Home Page:https://elixir-lang.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

compilation fails on Windows Arm because the MixProject module is already compiled

simonmcconnell opened this issue · comments

Elixir and Erlang/OTP versions

Erlang/OTP 25 [erts-13.2.2.9] [source] [64-bit] [smp:6:6] [ds:6:6:10] [async-threads:1] [jit:ns]

Elixir 1.16.3 (compiled with Erlang/OTP 25)

Operating system

Windows 11 Arm (in vmware Fusion on M3 macbook)

Current behavior

mix new arm
* creating README.md
* creating .formatter.exs
* creating .gitignore
* creating mix.exs
* creating lib
* creating lib/arm.ex
* creating test
* creating test/test_helper.exs
* creating test/arm_test.exs

Your Mix project was created successfully.
You can use "mix" to compile it, test it, and more:

    cd arm
    mix test

Run "mix help" for more commands.
cd arm
mix test
Compiling 1 file (.ex)

== Compilation error in file lib/arm.ex ==
** (ArgumentError) could not call Module.put_attribute/3 because the module Arm.MixProject is already compiled
    (elixir 1.16.3) lib/module.ex:2360: Module.assert_not_readonly!/2
    (elixir 1.16.3) lib/module.ex:2041: Module.__put_attribute__/5
    lib/arm.ex:2: (module)
mix compile
Compiling 1 file (.ex)

== Compilation error in file lib/arm.ex ==
** (ArgumentError) could not call Module.put_attribute/3 because the module Arm.MixProject is already compiled
    (elixir 1.16.3) lib/module.ex:2360: Module.assert_not_readonly!/2
    (elixir 1.16.3) lib/module.ex:2041: Module.__put_attribute__/5
    lib/arm.ex:2: (module)
mix compile --force
Compiling 1 file (.ex)

== Compilation error in file lib/arm.ex ==
** (ArgumentError) could not call Module.put_attribute/3 because the module Arm.MixProject is already compiled
    (elixir 1.16.3) lib/module.ex:2360: Module.assert_not_readonly!/2
    (elixir 1.16.3) lib/module.ex:2041: Module.__put_attribute__/5
    lib/arm.ex:2: (module)
tree /F
C:.
│   .formatter.exs
│   .gitignore
│   erl_crash.dump
│   mix.exs
│   README.md
│
├───lib
│       arm.ex
│
├───test
│       arm_test.exs
│       test_helper.exs
│
└───_build
    ├───dev
    │   └───lib
    │       └───arm
    │           └───ebin
    └───test
        └───lib
            └───arm
                └───ebin

Expected behavior

projects compile

Because Elixir does not ship with any native code, this is most likely caused by Erlang or the OS. How did you compile Erlang? Are you using Windows translation layer? When Apple released their translation layer, it also had issues. I would at least try to compile Erlang with the emulator instead of the JIT and give that a try.

As I understand, Windows will translate the x86 programs to arm at runtime, which it does for other apps I'm using. I presume this is what you mean by the translation layer?

I get it all from scoop, which gets Erlang from GitHub releases and elixir from hexcs builder. I will try without the JIT.

what you mean by the translation layer?

Yes, exactly. We had very similar bugs when Apple launched their own (called Rosetta). It was not reliable with JIT.

I’ve been seeing similar bugs on ARM/Windows before and no longer on OTP 27.0 so I’d consider upgrading. I believe 26.2.5 was working well for me too.

I'd love to but I can't get things to start on OTP 26 or 27 on Windows, be it in the VM on my mac, on my Windows workstation or a VM on the Windows workstation. There's an open issue on the OTP repo.

@simonmcconnell I'm using Windows 11 with Parallels on M2 Mac. Could you link to the OTP issue?

@wojtekmach it's one of those issues that only occurs for some people. I'm pretty sure I'm getting the same error on the Windows 11 Arm VM as I was on the other machines but I'll double check tonight. I'm using VMware Fusion 13.5 on an M3.

erlang/otp#7621

I have the same problem when I try to cross build on M1 my phoenix docker image with

docker buildx build --platform linux/amd64 .

ERROR [builder 14/25] RUN mix deps.compile [builder 14/25] RUN mix deps.compile
1.582 ==> decimal
1.582 Compiling 4 files (.ex)
2.212 Generated decimal app
2.221 ==> nest
2.223 Error while loading project :mime at /app/deps/mime
2.225 ** (ArgumentError) could not call Module.put_attribute/3 because the module Nest.MixProject is already compiled
2.225 (elixir 1.17.1) lib/module.ex:2365: Module.assert_not_readonly!/2
2.225 (elixir 1.17.1) lib/module.ex:2046: Module.put_attribute/5
2.225 /app/deps/mime/mix.exs:2: (module)
Dockerfile:56
54 | # to be re-compiled.
55 | COPY config/config.exs config/${MIX_ENV}.exs config/
56 | >>> RUN mix deps.compile
57 |
58 | COPY priv priv
ERROR: failed to solve: process "/bin/sh -c mix deps.compile" did not complete successfully: exit code: 1

With OTP 27.0 and Elixir 1.17.1-otp-27 I could get a new mix project to compile. I was hoping to get the error message (it is different to the one in the OTP issue above) but I can't reproduce it now. With my app I got the same Module.put_attribute error on typed_struct (from sourceror's mix project), tried again and got it on file_system (from ecto_sql's mix project), tried again and it finished compiling. I could then start and iex session.

I just created a phoenix project that reproduce the problem with docker building on M1 for linux/x86.
Just clone the project https://github.com/ChristopheBelpaire/crosscompile and run : docker build --platform linux/amd64 .

Cross compilation does not work with the JIT out of the box: https://elixirforum.com/t/cross-compiling-a-release-with-apple-m1-and-docker/55615/3

You can try disabling JIT and using the emulator (slower). You can also set ERL_AFLAGS=“+JMsingle true” and make the JIT more amenable to emulation. Or compile it on a matching machine.

I will go ahead and close this one, as I believe the cross compilation issue is not related to Elixir. Thanks!