Batamanta.Target (batamanta v1.5.0)

Copy Markdown View Source

Handles target platform resolution and Rust target mapping.

Provides functions to resolve ERTS targets into Rust target triples and platform-specific configuration.

Use :erts_target atoms for unified platform specification:

iex> Batamanta.Target.erts_target_to_rust(:ubuntu_22_04_x86_64)
"x86_64-unknown-linux-gnu"
Target AtomOSArchLibcRust Target
:ubuntu_22_04_x86_64Linuxx86_64glibcx86_64-unknown-linux-gnu
:ubuntu_22_04_arm64Linuxaarch64glibcaarch64-unknown-linux-gnu
:alpine_3_19_x86_64Linuxx86_64muslx86_64-unknown-linux-musl
:alpine_3_19_arm64Linuxaarch64muslaarch64-unknown-linux-musl
:macos_12_x86_64macOSx86_64-x86_64-apple-darwin
:macos_12_arm64macOSaarch64-aarch64-apple-darwin
:windows_x86_64Windowsx86_64msvcx86_64-pc-windows-msvc

Summary

Functions

Detects the host platform and returns the matching ERTS target.

Detects the libc type of the current Linux system.

Gets the OS string for binary naming (e.g., "x86_64-linux").

Converts an ERTS target atom to a user-friendly binary name.

Converts an ERTS target atom to a Rust target triple.

Legacy compatibility: converts old target_os/target_arch to new erts_target.

Gets the target info map for a given target atom.

Resolves an ERTS target atom to comprehensive target information.

Resolves :auto or string/atom target to a concrete ERTS target atom.

Lists all valid ERTS target atoms.

Validates that the detected libc matches an expected target.

Types

erts_target()

@type erts_target() :: atom()

rust_target()

@type rust_target() :: String.t()

target_info()

@type target_info() :: %{
  os: String.t(),
  arch: String.t(),
  libc: String.t() | nil,
  rust_target: rust_target(),
  display: String.t()
}

Functions

detect_host()

@spec detect_host() :: {:ok, erts_target()} | {:error, String.t()}

Detects the host platform and returns the matching ERTS target.

Delegates to Batamanta.ERTS.Fetcher.detect_host_target/0.

iex> Batamanta.Target.detect_host()
{:ok, :ubuntu_22_04_x86_64}

detect_libc()

@spec detect_libc() :: :gnu | :musl | :unknown

Detects the libc type of the current Linux system.

Delegates to Batamanta.ERTS.LibcDetector.detect/0.

iex> Batamanta.Target.detect_libc()
:gnu

iex> Batamanta.Target.detect_libc()
:musl

erts_target_to_binary_suffix(erts_target)

@spec erts_target_to_binary_suffix(erts_target()) :: String.t()

Gets the OS string for binary naming (e.g., "x86_64-linux").

erts_target_to_display(erts_target)

@spec erts_target_to_display(erts_target()) :: String.t()

Converts an ERTS target atom to a user-friendly binary name.

iex> Batamanta.Target.erts_target_to_display(:ubuntu_22_04_x86_64)
"Linux x86_64 (glibc)"

erts_target_to_rust(erts_target)

@spec erts_target_to_rust(erts_target()) :: rust_target()

Converts an ERTS target atom to a Rust target triple.

iex> Batamanta.Target.erts_target_to_rust(:ubuntu_22_04_x86_64)
"x86_64-unknown-linux-gnu"

iex> Batamanta.Target.erts_target_to_rust(:alpine_3_19_x86_64)
"x86_64-unknown-linux-musl"

from_legacy(os, arch)

@spec from_legacy(String.t() | :auto, String.t() | :auto) :: erts_target()

Legacy compatibility: converts old target_os/target_arch to new erts_target.

iex> Batamanta.Target.from_legacy("linux", "x86_64")
:ubuntu_22_04_x86_64

get_target_info(target)

@spec get_target_info(erts_target()) :: map() | nil

Gets the target info map for a given target atom.

iex> Batamanta.Target.get_target_info(:ubuntu_22_04_x86_64)
%{os: "linux", arch: "x86_64", libc: "gnu", ...}

resolve(erts_target)

@spec resolve(erts_target()) :: {:ok, target_info()} | {:error, String.t()}

Resolves an ERTS target atom to comprehensive target information.

  • erts_target - Target atom (e.g., :ubuntu_22_04_x86_64)

{:ok, target_info_map} or {:error, reason}

iex> Batamanta.Target.resolve(:ubuntu_22_04_x86_64)
{:ok, %{os: "linux", arch: "x86_64", libc: "gnu", ...}}

resolve_auto(target, config \\ %{})

@spec resolve_auto(atom() | String.t() | nil, map()) ::
  {:ok, erts_target()} | {:error, String.t()}

Resolves :auto or string/atom target to a concrete ERTS target atom.

  • target - :auto, atom, or string
  • config - Optional config map with :force_os, :force_arch, :force_libc

{:ok, erts_target_atom} or {:error, reason}

iex> Batamanta.Target.resolve_auto(:auto, %{})
{:ok, :ubuntu_22_04_x86_64}

iex> Batamanta.Target.resolve_auto(:alpine_3_19_x86_64, %{})
{:ok, :alpine_3_19_x86_64}

valid_targets()

@spec valid_targets() :: [atom()]

Lists all valid ERTS target atoms.

validate_libc!(target)

@spec validate_libc!(erts_target()) :: :ok

Validates that the detected libc matches an expected target.

Shows a warning if there's a mismatch but doesn't fail.

iex> Batamanta.Target.validate_libc!(:ubuntu_22_04_x86_64)
:ok