Batamanta.EscriptBuilder (batamanta v1.5.0)

Copy Markdown View Source

Builds escripts for batamanta packaging.

This module handles the generation of escripts using mix escript.build and provides utilities for locating and validating the generated output.

escript_path = EscriptBuilder.build(config, banner_ctx, erts_path)

Escripts are lightweight executables that embed the Elixir runtime directly, unlike releases which include the full OTP system.

AspectEscriptRelease
Size~15-30 MB~80-150 MB
StartupFastSlower
Supervisor TreeNoYes
Daemon ModeNoYes
Hot UpgradesNoYes

Use escripts when:

  • Building CLI tools
  • Size is critical
  • No need for full OTP supervision

Use releases when:

  • Building services
  • Need supervisor trees
  • Need distributed Erlang

Summary

Functions

Finds the escript path in the build directory.

Gets the main module from escript configuration.

Checks if the project has valid escript configuration.

Validates that the escript is a valid executable.

Functions

build(config, banner_ctx, erts_path)

@spec build(keyword(), any(), Path.t()) :: Path.t()

Builds an escript using mix escript.build.

  • config - Mix project config (from Mix.Project.config())
  • banner_ctx - Banner context for logging
  • erts_path - Path to the ERTS that will be embedded (for build consistency)

Path to the generated escript binary.

find_escript_path(config)

@spec find_escript_path(keyword()) :: Path.t()

Finds the escript path in the build directory.

Escripts are generated by default at:

  • ./<app_name> (in project root, default for CLI tools)

Or at a custom path if specified in the :escript config.

get_main_module(config)

@spec get_main_module(keyword()) :: module() | nil

Gets the main module from escript configuration.

Returns nil if not configured.

valid_config?(config)

@spec valid_config?(keyword()) :: boolean()

Checks if the project has valid escript configuration.

validate_escript!(escript_path)

@spec validate_escript!(Path.t()) :: :ok | no_return()

Validates that the escript is a valid executable.

  1. File exists
  2. File is executable
  3. File is not empty
  4. File has shebang or is an ELF binary