Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend load_from to allow loading from an absolute path #558

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions rustler_mix/lib/rustler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,18 @@ defmodule Rustler do
loaded from at runtime. By default the compiled artifact is loaded from the
owning `:otp_app`'s `priv/native` directory. This option comes in handy in
combination with the `:skip_compilation?` option in order to load pre-compiled
artifacts. To override the default behaviour specify a tuple:
`{:my_app, "priv/native/<artifact>"}`. Due to the way `:erlang.load_nif/2`
works, the artifact should not include the file extension (i.e. `.so`, `.dll`).
artifacts. The configuration format:

```
{otp_app :: atom(), path :: String.t()} | abspath :: String.t()}
```

The tuple version defines that the artifact shall be found relative to `otp_app`,
for example `{:my_app, "priv/native/<artifact>"}`. The non-tuple alternative requires
an absolute path.

Due to the way `:erlang.load_nif/2` works, the artifact should not
include the file extension (i.e. `.so`, `.dll`).

* `:mode` - Specify which mode to compile the crate with (default: `:release`)

Expand Down Expand Up @@ -123,12 +132,16 @@ defmodule Rustler do
# {:error, {:upgrade, 'Upgrade not supported by this NIF library.'}}
:code.purge(__MODULE__)

{otp_app, path} = @load_from

load_path =
otp_app
|> Application.app_dir(path)
|> to_charlist()
case @load_from do
{otp_app, path} ->
otp_app
|> Application.app_dir(path)
|> to_charlist()

path ->
to_charlist(path)
end

load_data = Rustler.construct_load_data(@load_data, @load_data_fun)

Expand Down
Loading