goertzenator / rebar3_rust

Rebar3 plugin to build Rust crates (unmaintained). See https://github.com/filmor/rebar3_rust/tree/update for more recent work.
Apache License 2.0
9 stars 5 forks source link

Prepare directories to handle --target #6

Open erlanger opened 6 years ago

erlanger commented 6 years ago

I would suggest to change the directory structure in priv/crates to include the architecture. For example:

priv/crates/x86_64-pc-windows-gnu/foo_nif/
                                 /bar_port/
priv/crates/x86_64-unknown-linux-gnu/foo_nif
                                 /bar_port/

The problem would be to decide which architecture string to use, the erlang one returned by erlang:system_info(system_architecture) or the rust one used by cargo with --target.

The erlang one has the advantage that it would be easier to find the port/nif from the erlang code when it is time to load the nif or open the port.

The rust one is easier to obtain simply from --target but some way needs to be provided to map from the rust architectures to the erlang architecture in order to find the .so or binary at runtime from the erlang environment.

goertzenator commented 6 years ago

Do you mean this to be used only when --target is specified, or for all cases?

erlanger commented 6 years ago

It would simplify the nif/port finding code (in erlang) if it is used for all cases.

goertzenator commented 6 years ago

I don't think that should be default behavior, but a flag to turn that on would be sensible. Perhaps in conjunction with an additional option to build multiple architectures in one go. The reasons to make it non-default are:

erlanger commented 6 years ago

I can see the first two points; it's okay to make it optional with a flag to turn it on.