### Example Checksum Generation Command Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Specific example of the checksum generation command for RustlerPrecompilationExample.Native. ```bash mix rustler_precompiled.download RustlerPrecompilationExample.Native --all --print ``` -------------------------------- ### Mix.exs Package Configuration Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Example of the 'files' configuration in mix.exs to include necessary files for a Hex package, including the checksum file. ```elixir defp package do [ files: [ "lib", "native/my_nif/.cargo", "native/my_nif/src", "native/my_nif/Cargo*", "checksum-*.exs", "mix.exs" ], # ... ] end ``` -------------------------------- ### Define Build Matrix for Targets Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Specify the build matrix for GitHub Actions to compile NIFs for various operating systems, architectures, and NIF versions. This example targets Linux, macOS, and Windows for x86_64 and aarch64 architectures, using NIF version 2.15. ```yaml matrix: nif: ["2.15"] job: - { target: aarch64-unknown-linux-gnu , os: ubuntu-22.04 , use-cross: true } - { target: aarch64-apple-darwin , os: macos-15 } - { target: x86_64-apple-darwin , os: macos-15-intel } - { target: x86_64-unknown-linux-gnu , os: ubuntu-22.04 } - { target: x86_64-unknown-linux-musl , os: ubuntu-22.04 , use-cross: true } - { target: x86_64-pc-windows-gnu , os: windows-2022 } - { target: x86_64-pc-windows-msvc , os: windows-2022 } ``` -------------------------------- ### Configure Rustler NIF Versions in Cargo.toml Source: https://github.com/philss/rustler_precompiled/blob/main/TROUBLESHOOTING.md Specify Rustler NIF versions in your `Cargo.toml` by disabling default features and enabling specific NIF version features. This example shows how to enable NIF version 2.15. ```toml [dependencies] rustler = { version = "0.37", default-features = false } # And then, your features. [features] default = ["nif_version_2_15"] nif_version_2_15 = ["rustler/nif_version_2_15"] nif_version_2_16 = ["rustler/nif_version_2_16"] nif_version_2_17 = ["rustler/nif_version_2_17"] ``` -------------------------------- ### Configure 'musl' ABI Targets in Cargo.toml Source: https://github.com/philss/rustler_precompiled/blob/main/TROUBLESHOOTING.md Add this configuration to your `.cargo/cargo.toml` file to support 'musl' ABI targets like 'x86_64-unknown-linux-musl' by disabling static linking. ```toml # This is needed for "musl". See https://github.com/rust-lang/rust/issues/59302 [target.x86_64-unknown-linux-musl] rustflags = [ "-C", "target-feature=-crt-static" ] ``` -------------------------------- ### Link libatomic for 32-bit ARM Builds Source: https://github.com/philss/rustler_precompiled/blob/main/TROUBLESHOOTING.md Configure your `.cargo/config.yml` to link 'libatomic' for 32-bit ARM targets like 'arm-unknown-linux-gnueabihf', as required by some architectures. ```toml # Libatomic is needed for 32 bits ARM. # See: https://github.com/philss/rustler_precompiled/issues/53 [target.arm-unknown-linux-gnueabihf] rustflags = [ "-l", "dylib=atomic" ] ``` -------------------------------- ### Release Profile Configuration Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Configures the release profile for Rustler projects to optimize build size and compilation time. ```toml [profile.release] lto = true ``` -------------------------------- ### Generate Checksum File Command Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Command to generate a checksum file for downloaded NIFs. This file is mandatory for Hex package distribution. ```bash mix rustler_precompiled.download YourRustlerModule --all --print ``` -------------------------------- ### Configure Cargo for Musl Target Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Provide additional configuration for the Rust compiler in `.cargo/config.toml` when targeting the `x86_64-unknown-linux-musl` platform. This specific configuration is needed to resolve issues related to static linking. ```toml # This is needed for "musl". See https://github.com/rust-lang/rust/issues/59302 [target.x86_64-unknown-linux-musl] rustflags = [ "-C", "target-feature=-crt-static" ] ``` -------------------------------- ### RustlerPrecompiled Module Configuration Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Defines the RustlerPrecompiled module with essential configuration like OTP app, crate name, base URL, and version. Force build option is available via environment variable. ```elixir defmodule RustlerPrecompilationExample.Native do version = Mix.Project.config()[:version] use RustlerPrecompiled, otp_app: :rustler_precompilation_example, crate: "example", base_url: "https://github.com/philss/rustler_precompilation_example/releases/download/v#{version}", force_build: System.get_env("RUSTLER_PRECOMPILATION_EXAMPLE_BUILD") in ["1", "true"], version: version # When your NIF is loaded, it will override this function. def add(_a, _b), do: :erlang.nif_error(:nif_not_loaded) end ``` -------------------------------- ### Configure GitHub Actions Permissions Source: https://github.com/philss/rustler_precompiled/blob/main/PRECOMPILATION_GUIDE.md Set write permissions for contents, id-token, attestations, and artifact-metadata in your GitHub Actions workflow file. This is necessary for creating releases and optionally for using artifact attestations. ```yaml permissions: # For creating a new release. contents: write # The following are needed for the "actions/attest" GH Action. id-token: write attestations: write artifact-metadata: write ``` -------------------------------- ### Add Rustler Precompiled to Mix Dependencies Source: https://github.com/philss/rustler_precompiled/blob/main/README.md Add `rustler_precompiled` to your project's dependencies in `mix.exs`. This is typically an optional dependency used during development. ```elixir def deps do [ {:rustler_precompiled, "~> 0.9"} ] end ``` -------------------------------- ### Specify a Single Rustler NIF Version in Cargo.toml Source: https://github.com/philss/rustler_precompiled/blob/main/TROUBLESHOOTING.md Declare your Rustler dependency to explicitly use a specific NIF version, such as '2.16', by including it in the `features` list. ```toml [dependencies] rustler = { version = "0.37", default-features = false, features = ["nif_version_2_16"] } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.