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
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"
Return a list of default targets.
find_compatible_nif_version(vsn, available \\ ["2.14", "2.15", "2.16"])
View SourceIn case one is using this lib in a newer OTP version, we try to find the latest compatible NIF version.
maybe_override_with_env_vars(original_sys_arch, get_env \\ &System.get_env/1)
View SourceOverride 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
Normalize the given target system map accordingly
convention
can be :rust
or :zig
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"}
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"
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"}
@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 Variable Maps 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
}