View Source FennecPrecompile (fennec_precompile v0.1.1)
Drop-in library for :elixir_make
for precompiling and using precompiled NIF
binaries.
example
Example
defmodule MyNative do
use FennecPrecompile,
otp_app: Mix.Project.config()[:app],
version: "0.1.0",
base_url: "https://github.com/me/my_project/releases/download/v0.1.0",
nif_filename: "native_nif",
force_build: false
end
options
Options
:otp_app
. Required.Specifies the name of the app.
:version
. Optional.Defaults to
Mix.Project.config()[:version]
.Specifies the version of the app.
:base_url
. Required.Specifies the base download URL of the precompiled binaries.
:nif_filename
. Required.Specifies the name of the precompiled binary file, excluding the file extension.
:force_build
. Required.Indicates whether to force the app to be built.
The value of this option will always be
true
for pre-releases (like "2.1.0-dev").When this value is
false
and there are no local or remote precompiled binaries, a compilation error will be raised.:force_build_args
. Optional.Defaults to
[]
.This option will be used when
:force_build
istrue
. The optional compiliation args will be forwarded to:elixir_make
.:force_build_using_zig
. Optional.Defaults to
false
.This option will be used when
:force_build
istrue
. Set this option totrue
to always usingzig
as the C/C++ compiler.:targets
. Optional.A list of targets supported by Zig for which precompiled assets are avilable. By default the following targets are configured:
on-macos
on macOSx86_64-macos
x86_64-linux-gnu
x86_64-linux-musl
x86_64-windows-gnu
aarch64-macos
aarch64-linux-gnu
aarch64-linux-musl
riscv64-linux-musl
on-linux
on Linuxx86_64-linux-gnu
x86_64-linux-musl
x86_64-windows-gnu
aarch64-linux-gnu
aarch64-linux-musl
riscv64-linux-musl
:targets
in theuse
-clause will only be used in the following cases::force_build
is set totrue
. In this case, the:targets
acts as a list of compatible targets in terms of the source code. For example, NIFs that are specifically written for ARM64 Linux will fail to compile for other OS or CPU architeture. If the source code is not compatible with the current node, the build will fail.:force_build
is set tofalse
. In this case, the:targets
acts as a list of available targets of the precompiled binaries. If there is no match with the current node, no precompiled NIF will be downloaded and the app will fail to start.
Link to this section Summary
Functions
Returns URLs for NIFs based on its module name. The module name is the one that defined the NIF and this information is stored in a metadata file.
Returns the file URL to be downloaded for current target. It receives the NIF module.
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 Zig. The returned string has the following format
Link to this section Functions
Returns URLs for NIFs based on its module name. The module name is the one that defined the NIF and this information is stored in a metadata file.
Returns the file URL to be downloaded for current target. It receives the NIF module.
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 Zig. The returned string has the following format:
"ARCHITECTURE-OS-ABI"
examples
Examples
iex> FennecPrecompile.target()
{:ok, "x86_64-linux-gnu"}
iex> FennecPrecompile.target()
{:ok, "aarch64-macos"}