openlang

Can several beam files become a single beam?

I'm treating .beam as a script so I can conceal my code and execute it any where.

Normally several files cooperate, for example:


entry.erl
helper.erl
....

Can several beam files be combined into a single beam?

My only idea is embedding the beam inside an erl file before compiling that, for example


["[",
lists:map(fun(Artifact) ->
  {ok, Payload} = prim_file:read_file(Artifact),
  ["{", filename:basename(Artifact, ".beam"), ",", io_lib:format("~w", [Payload]), "},"]
end, Artifacts)
"ok]"]

producing


[{module, <<"....">>}]

then loading it via code:load_file

The conversation continues 2

Follow the reasoning
  1. Permalink

    I can conceal my code and execute it any where

    .beam files aren't completely portable. The Erlang VM won't accept files built with a later OTP release, or with a release that's too old.

    I'm treating .beam as a script

    The usual answer here is escript (https://www.erlang.org/doc/apps/stdlib/escript.html), an archive format capable of holding several beam files together with an Erlang runtime. The Erlang runtime supplies an escript program which can unpack these archives and execute them. Building escripts is supported by rebar3.

Other sides of the same question

  1. Reducing docker-compose console noise

    Several of my containers produce hundreds upon hundreds of output lines when docker-compose up starts all the services in my…

    Replies 3Latest activity bash
  2. Could D produce Python extension modules rather than using C?

    Apparently D can link against C. I want to write a Python extension module using D. Is there a reason this approach could nev…

    Replies 2Latest activity d
  3. Micro plugins declared through Nix?🤔

    With python we can write this: Python.withPackages (q: with q; [ fastapi ]) Is an equivalent mechanism available for the Micr…

    Replies 3Latest activity nix