Skip to content

In 1.18, escript generated when consolidate_protocols: false stopped working #14096

@angelikatyborska

Description

@angelikatyborska

Elixir and Erlang/OTP versions

Erlang/OTP 27 [erts-15.2] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]

Elixir 1.18.0 (compiled with Erlang/OTP 27)

Operating system

macOS 14.5

Current behavior

We have a project that's an escript that accepts user-submitted Elixir code and spits out static code analysis hints, including warnings from the compiler. To avoid reporting warnings about protocols being already consolidated, we compile the escript with consolidate_protocols: false.

That escript stopped working in Elixir 1.18. The size of the generated binary is surprisingly smaller than before, and trying to run it spits out an error error: {error,{elixir,{"no such file or directory","elixir.app"}}}. Details below.

I created a reproduction repository with the simplest possible reproduction: https://github.com/angelikatyborska/elixir-1-18-escript-consolidate-protocols-false-bug

Step 1: generate working escript

When we don't set consolidate_protocols: false, we're able to generate a working escript.

Generate and execute the escript:

$ mix escript.build
Generated orange app
Generated escript orange with MIX_ENV=dev
$ ./orange 
Orange you glad you ran this binary? Have a nice day 🍊

Note the size of the generated working binary: 1.3M

$ ls orange 
-rwxr-xr-x  1 angelika  staff   1.3M Dec 21 10:42 orange

Step 2: set consolidate_protocols: false

In mix.exs, add consolidate_protocols: false:

diff --git a/mix.exs b/mix.exs
index ed076a0..5e181c9 100644
--- a/mix.exs
+++ b/mix.exs
@@ -8,6 +8,7 @@ defmodule Orange.MixProject do
       elixir: "~> 1.18",
       start_permanent: Mix.env() == :prod,
       deps: deps(),
+      consolidate_protocols: false,
       escript: [main_module: Orange]
     ]
   end

Then try generating the escript again:

$ mix escript.build
Generated orange app
Generated escript orange with MIX_ENV=dev
$ ./orange 
ERROR! Failed to start Elixir.
error: {error,{elixir,{"no such file or directory","elixir.app"}}}

The script doesn't run anymore. Note the size of the generated broken binary: 1.6K compared to 1.3M, significantly smaller than expected.

$ ls orange
-rwxr-xr-x  1 angelika  staff   1.6K Dec 21 10:45 orange

I have also tested this in Elixir 1.17.3 and there, a working binary compiled with consolidate_protocols: false has the size of 1.2M.

Expected behavior

I would expect to be able to build an escript with the option consolidate_protocols: false and for the escript to execute.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions