Packages
rustler
0.22.0-rc.2
0.38.0
0.37.3
0.37.1
0.37.0
retired
0.36.2
0.36.1
0.36.0
0.35.1
0.35.0
0.34.0
0.33.0
0.32.1
0.31.0
0.30.0
0.29.1
0.29.0
0.28.0
0.27.0
0.26.0
0.25.0
0.24.0
0.23.0
0.22.2
0.22.1
0.22.0
0.22.0-rc.2
0.22.0-rc.1
0.22.0-rc.0
0.21.1
0.21.0
0.20.0
0.19.1
0.19.0
0.18.0
0.17.1
0.17.0
0.16.0
0.10.1
0.10.0
0.9.0
0.8.0
0.7.0
0.6.0
0.5.0
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.1
0.1.0
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Mix compiler and runtime helpers for Rustler.
Current section
Files
Jump to
Current section
Files
lib/rustler/compiler/config.ex
defmodule Rustler.Compiler.Config do
@moduledoc false
@type rust_version :: :stable | :beta | :nightly | binary()
@type cargo :: :system | {:rustup, rust_version()} | {:bin, Path.t()}
@type crate :: binary()
@type default_features :: boolean()
@type env :: [{binary(), binary()}]
@type features :: [binary()]
@type mode :: :debug | :release
@type load_data :: term()
@type path :: Path.t()
defstruct cargo: :system,
crate: nil,
default_features: true,
env: [],
external_resources: [],
features: [],
lib: true,
load_data: 0,
load_from: nil,
mode: :release,
otp_app: nil,
path: "",
priv_dir: "",
skip_compilation?: false,
target: nil,
target_dir: ""
alias Rustler.Compiler.Config
def from(otp_app, module, opts) do
config = Application.get_env(otp_app, module, [])
crate = config[:crate] || opts[:crate] || otp_app
# TODO: Remove in 1.0
rustler_crates = Mix.Project.config()[:rustler_crates] || []
legacy_config = rustler_crates[to_atom(crate)] || []
defaults = %Config{
crate: crate,
load_from: {otp_app, "priv/native/lib#{crate}"},
mode: build_mode(Mix.env()),
otp_app: otp_app,
path: "native/#{crate}",
target_dir: Application.app_dir(otp_app, "native/#{crate}")
}
defaults
|> Map.from_struct()
|> Enum.into([])
|> Keyword.merge(legacy_config)
|> Keyword.merge(opts)
|> Keyword.merge(config)
|> build()
end
defp build(opts) do
resources =
opts
|> Keyword.get(:path)
|> external_resources()
opts = Keyword.put(opts, :external_resources, resources)
struct!(Config, opts)
end
defp external_resources(crate_path) do
"#{crate_path}/**/*"
|> Path.wildcard()
|> Enum.reject(fn path ->
String.starts_with?(path, "#{crate_path}/target/")
end)
end
defp build_mode(env) when env in [:prod, :bench], do: :release
defp build_mode(_), do: :debug
defp to_atom(name) when is_binary(name),
do: String.to_atom(name)
defp to_atom(name) when is_atom(name),
do: name
end