View Source RustlerPrecompiled (rustler_precompiled v0.4.1)

Download and use precompiled NIFs safely with checksums.

Rustler Precompiled is a tool for library maintainers that rely on Rustler. It helps by removing the need to have the Rust compiler installed in the user's machine.

Check the Precompilation Guide for details.

example

Example

defmodule MyNative do
  use RustlerPrecompiled,
    otp_app: :my_app,
    crate: "my_app_nif",
    base_url: "https://github.com/me/my_project/releases/download/v0.1.0",
    version: "0.1.0"
end

options

Options

  • :otp_app - The OTP app name that the dynamic library will be loaded from.

  • :crate - The name of Rust crate if different from the :otp_app. This is optional.

  • :base_url - A valid URL that is used as base path for the NIF file.

  • :version - The version of precompiled assets (it is part of the NIF filename).

  • :force_build - Force the build with Rustler. This is false by default, but if your :version is a pre-release (like "2.1.0-dev"), this option will always be set true. You can also configure this option by setting an application env like this:

    config :rustler_precompiled, :force_build, your_otp_app: true  

    It is important to add the ":rustler" package to your dependencies in order to force the build. To do that, just add it to your mix.exs file:

    {:rustler, ">= 0.0.0", optional: true}

In case "force build" is used, all options except :base_url, :version and :force_build are going to be passed down to Rustler. So if you need to configure the build, check the Rustler options.

Link to this section Summary

Functions

Returns URLs for NIFs based on its module name.

List all default available targets.

Returns the file URL to be downloaded for current target.

Returns the target triple for download or compile and load.

Link to this section Functions

Link to this function

available_nif_urls(nif_module)

View Source

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.

List all default available targets.

Link to this function

current_target_nif_url(nif_module)

View Source

Returns the file URL to be downloaded for current target.

It receives the NIF module.

Link to this function

target(config \\ target_config())

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 Rust.

The returned string has the following format:

"nif-NIF_VERSION-ARCHITECTURE-VENDOR-OS-ABI"

examples

Examples

iex> RustlerPrecompiled.target()
{:ok, "nif-2.16-x86_64-unknown-linux-gnu"} 

iex> RustlerPrecompiled.target()
{:ok, "nif-2.15-aarch64-apple-darwin"}