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

PoC to allow NIFs to be loaded from escripts #658

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
23 changes: 19 additions & 4 deletions rustler_mix/lib/rustler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,28 @@ defmodule Rustler do
:code.purge(__MODULE__)

{otp_app, path} = @load_from
app_dir = Application.app_dir(otp_app, path)

load_path =
otp_app
|> Application.app_dir(path)
|> to_charlist()
case System.get_env("ESCRIPT_NAME") do
nil ->
app_dir

escript_path ->
if String.starts_with?(app_dir, escript_path) do
tmp = System.tmp_dir!()
:zip.extract(escript_path,
file_list: [Path.join(otp_app |> Atom.to_string(), path)],
cwd: tmp
)

Path.join(tmp, path)
else
app_dir
end
end

:erlang.load_nif(load_path, _construct_load_data())
:erlang.load_nif(load_path |> to_charlist(), _construct_load_data())
end
end
end
Expand Down
Loading