Error compiling elixir 1.15.2 on amazon linux with otp-26.0.2

The error

Generated elixir app
==> bootstrap (compile)
error: defmacro var!/2 defines defaults multiple times. Elixir allows defaults to be declared once per definition. Instead of:

    def foo(:first_clause, b \\ :default) do ... end
    def foo(:second_clause, b \\ :default) do ... end

one should write:

    def foo(a, b \\ :default)
    def foo(:first_clause, b) do ... end
    def foo(:second_clause, b) do ... end

  /tmp/elixir-1.15.2/lib/elixir/lib/kernel.ex:4618

Function: 'MACRO-!'/2
error: undef
stacktrace: [{'Elixir.CompileError',exception,
                 [[{description,
                       <<"internal error in pass beam_ssa_bool:\nexception error: undefined function 'Elixir.CompileError':exception/1\n  in function  elixir_errors:raise/3 (src/elixir_errors.erl, line 300)\n  in call from elixir_def:store_definition/9 (src/elixir_def.erl, line 283)\n  in call from elixir_def:store_definition/10 (src/elixir_def.erl, line 211)\n  in call from beam_digraph:in_degree/2 (beam_digraph.erl, line 125)\n  in call from beam_ssa_bool:build_mapping/4 (beam_ssa_bool.erl, line 822)\n  in call from beam_ssa_bool:build_digraph/3 (beam_ssa_bool.erl, line 805)\n  in call from beam_ssa_bool:bool_opt_rewrite/5 (beam_ssa_bool.erl, line 633)">>},
                   {file,<<"/tmp/elixir-1.15.2/lib/elixir/lib/kernel.ex">>},
                   {line,0}]],
                 []},
             {elixir_errors,raise,3,
                 [{file,"src/elixir_errors.erl"},{line,300}]},
             {lists,foreach_1,2,[{file,"lists.erl"},{line,1686}]},
             {elixir_erl,load_form,5,[{file,"src/elixir_erl.erl"},{line,440}]},
             {elixir_module,'-compile/7-fun-1-',9,
                 [{file,"src/elixir_module.erl"},{line,186}]},
             {elixir_erl_compiler,'-spawn/1-fun-0-',2,
                 [{file,"src/elixir_erl_compiler.erl"},{line,12}]}]
make: *** [lib/elixir/ebin/Elixir.Kernel.beam] Error 1

What I have tried

  • using elixir versions 1.13.4, 1.15.1
  • using otp 25.3
  • using amazon linux 2.0.20220419.0

All the above scenarios still fail to compile with the same reason

My docker file

FROM amazonlinux:2.0.20230612.0

ENV ELIXIR_VERSION="1.15.2"
ENV OTP_VERSION="26.0"


RUN yum groupinstall -y "Development Tools" && \
    yum install      -y ncurses-devel openssl-devel jq wget

ENV LANG=en_US.UTF-8 \
    LANGUAGE=en_US:en \
    LC_ALL=en_US.UTF-8 \
    PATH="${PATH}:/usr/local/bin" 

RUN mkdir -p tmp && \
    cd tmp && \
    wget -O "/tmp/erlang.tar.gz" "http://erlang.org/download/otp_src_${OTP_VERSION}.tar.gz" && \
    tar xfz erlang.tar.gz && \
    cd "otp_src_${OTP_VERSION}" && \
    ./configure && \
    make && make install

# Elixir install
RUN cd tmp && \
    wget -O "/tmp/elixir.tar.gz" "https://github.com/elixir-lang/elixir/archive/v${ELIXIR_VERSION}.tar.gz" && \
    tar xfz elixir.tar.gz && \
    cd "elixir-${ELIXIR_VERSION}" && \
    make && make install clean

Edit

I am using an M1 macos with 13.4.1 Ventura

1 Like

Just to establish a possibly working configuration, have you tried using one of asdf or rtx version managers to install? Have you tried the APT packages? Though I wouldn’t recommend them, usually there’s stuff from Erlang missing there.

No I havent tried using ASDF yet. The apt packages are rarely compiled to the latest available OTP and elixir versions. I read a little bit on possibility of using asdf in a production machine and looks like its generally frowned upon

I agree it shouldn’t be used on a production machine, just thought of how can you pinpoint the problem.

btw why not use the official Docker images of the hexpm namespace in the DockerHub? They have many combinations of Erlang and Elixir already built in.

Let me try that

There are different elixir versions for different OTPs, have you tried downloading a elixir version for your specific OTP version?

Example: elixir 1.15.2-otp-25

I thought the releases that come with OTP versions are precompiled versions only.
I am pulling down the source code and compiling erlang then elixir

What’s wrong with them being precompiled?

Ah OK, I thought this has to do with some interfaces to erlang, but it does seem that elixir is precompiled in asdf.

Absolutely nothing, I used that and it never worked too.

Seems like the problem might be that I am using an M1 mac while the target OS is an linux/amd64 architecture.

Docker should solve that nicely.

But I am also confused about your stuff never working. Shouldn’t be the case, can you show us a Dockerfile where you used a pre-baked hexpm image with your app in it and what errors are being output?

I also did not quiet understand. I managed to compile using the docker file above on a linux machine and it worked. Maybe docker on mac is using xcode-tools to do some of the compilations (just a maybe)

Using the hexpm images worked okay though they dont support amazon linux ( i am trying to maintain the legacy OS without diving too deep into changing everything on one go)

You can’t do that.

For some reason OTP will not be able to be built on emulated machines.

Neither can I build OTP from source on my x86 for aarch64 (both Linux), nor can I build it in an amd64 Linux docker on “my” M1.

Both situations will eventually end up in a segfault.

Please make sure to use at least a prebuild OTP.

I believe your issue is the same as the one describe here:

The good news is that the issue has been solved: target/arm: Handle IC IVAU to improve compatibility with JITs (9719f125) · Commits · QEMU / QEMU · GitLab

Now may be just a matter of time until this QEMU version is incorporated into the mac version of Docker.

1 Like

Note that while it’s the same underlying issue, that fix is only for aarch64 targets. x86 targets would require a far more blunt approach which I’m not sure they would accept.

1 Like