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

[RFC] Pseudo-reload #276

Open
filmor opened this issue Nov 12, 2019 · 0 comments
Open

[RFC] Pseudo-reload #276

filmor opened this issue Nov 12, 2019 · 0 comments

Comments

@filmor
Copy link
Member

filmor commented Nov 12, 2019

As explained in #13 it's not feasible to allow for "real" module unloading for rustler-based nif-modules. However, by (automatically) versioning the nif-modules we could achieve something similar:

In my rebar3_rust update branch I already place crates in versioned directories and generate a header-file that contains the location of the binaries relative to priv on build. We could now go one step further and generate a "wrapper" nif module that refers to exactly one version and make the rustler_codegen generate its name from the crate version and compile mode. A nif crate of name my_nifs with a single nif func/1 of version 1.0 would then generate a module like:

-module('my_nifs_crate_1.0_release').

-export([func/1]).

-on_load(init/0).

init() -> erlang:load_nif("/path/to/output").

func(Arg1) -> erlang:nif_error(not_loaded).

The actual module to expose this would then be recompiled on version change and look like this, where crates.hrl is regenerated on build to refer to the respective current generated module:

-module(my_nifs).

-include("crates.hrl").

-spec func(number()) -> ok.
func(MyNumber) ->
    ?crate_my_nifs:func(MyNumber).

The user-defined my_nifs module would then, on reload, pick up a new generated module which in turn would load the new so/dll.

Since 'my_nifs_crate_1.0_release' should be generated on build, we could incorporate it into rustler_codegen's init! implementation and even add auto-generated specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant