View Source FennecPrecompile.SystemInfo (fennec_precompile v0.2.0)

Link to this section Summary

Functions

Returns user cache directory.

Get nif version for current node.

Return a list of default targets.

In case one is using this lib in a newer OTP version, we try to find the latest compatible NIF version.

Override system architeture map with environment variables to support systems like Nerves.

Normalize the given target system map accordingly

Parse :erlang.system_info(:system_architecture) into a map

Convert system architecture map to its string form.

Returns the target triple for download or compile and load.

Get a config map for current node.

Link to this section Functions

Link to this function

cache_dir(sub_dir \\ "")

View Source

Returns user cache directory.

@spec current_nif_version() :: String.t()

Get nif version for current node.

example

Example

iex> FennecPrecompile.SystemInfo.current_nif_version() "2.16"

Link to this function

default_targets(convention)

View Source

Return a list of default targets.

Link to this function

find_compatible_nif_version(vsn, available \\ ["2.14", "2.15", "2.16"])

View Source
@spec find_compatible_nif_version(String.t(), [String.t()]) ::
  {:ok, String.t()} | :error

In case one is using this lib in a newer OTP version, we try to find the latest compatible NIF version.

Link to this function

maybe_override_with_env_vars(original_sys_arch, get_env \\ &System.get_env/1)

View Source

Override system architeture map with environment variables to support systems like Nerves.

See: https://hexdocs.pm/nerves/compiling-non-beam-code.html#target-cpu-arch-os-and-abi

Link to this function

normalize_target_system(target_system, convention)

View Source

Normalize the given target system map accordingly

convention can be :rust or :zig

@spec system_architecture() :: %{required(atom()) => String.t()} | %{}

Parse :erlang.system_info(:system_architecture) into a map

The result map may include :arch, :vendor, :os and :abi keys if :erlang.system_info/1 returns "ARCH-VENDOR-OS-ABI".

Or the result will include :arch, :os and :abi keys if :erlang.system_info/1 returns "ARCH-OS-ABI".

For other cases, an empty map is returned.

examples

Examples

iex> FennecPrecompile.SystemInfo.system_architecture()
%{abi: "darwin21.4.0", arch: "aarch64", os: "apple"}
Link to this function

system_architecture_to_string(system_architecture)

View Source

Convert system architecture map to its string form.

example

Example

iex> system_architecture = FennecPrecompile.SystemInfo.system_architecture() %{abi: "darwin21.4.0", arch: "aarch64", os: "apple"} iex> FennecPrecompile.SystemInfo.system_architecture_to_string(system_architecture) "aarch64-apple-darwin21.4.0"

Link to this function

target(convention, opts \\ [])

View Source

Returns the target triple for download or compile and load.

This function is translating and adding more info to the system architecture returned by Elixir/Erlang to one used by convention.

examples

Examples

iex> FennecPrecompile.SystemInfo.target(:rust)
{:ok, "aarch64-apple-darwin"}
iex> FennecPrecompile.SystemInfo.target(:zig)
{:ok, "aarch64-macos"}
Link to this function

target_config(allow_env_var_override \\ true)

View Source
@spec target_config(boolean()) :: %{
  os_type: {:unix, atom()} | {:win32, atom()},
  target_system: %{},
  word_size: 4 | 8,
  nif_version: String.t()
}

Get a config map for current node.

parameters

Parameters

  • allow_env_var_override.

    Defaults to true.

    Indicating whether allows environment variables to override values for :arch, :vendor, :os and :abi.

    The following environment variables will be tested and replace correspondingly if not empty.

    Environment VariableMaps to Key
    TARGET_ARCH:arch
    TARGET_VENDOR:vendor
    TARGET_OS:os
    TARGET_ABI:abi

return

Return

The map includes 4 keys:

  • :os_type. Value returned from :os.type().
  • :target_system.
  • :word_size. Value returned from :erlang.system_info(:wordsize).
  • :nif_version. Exact or compatible nif version for current node.

example

Example

iex> FennecPrecompile.SystemInfo.target_config(false)
%{
  nif_version: "2.16",
  os_type: {:unix, :darwin},
  target_system: %{abi: "darwin21.4.0", arch: "aarch64", os: "apple"},
  word_size: 8
}

iex> System.put_env("TARGET_ARCH", "x86_64")
:ok
iex> FennecPrecompile.SystemInfo.target_config(true)
%{
  nif_version: "2.16",
  os_type: {:unix, :darwin},
  target_system: %{abi: "darwin21.4.0", arch: "x86_64", os: "apple"},
  word_size: 8
}