rustler icon indicating copy to clipboard operation
rustler copied to clipboard

rebar3 integration?

Open benoitc opened this issue 8 years ago • 29 comments

Do you know about any rebar3 plugin to compile nifs built with rustler?

benoitc avatar Feb 21 '17 10:02 benoitc

I know @goertzenator has been working on some stuff related to that, namely cargo-erlangapp.

I am fairly sure this could be used relatively easily with rustler, and it would be worth having a look.

hansihe avatar Feb 21 '17 15:02 hansihe

Did you try this one?

goertzenator avatar Feb 21 '17 16:02 goertzenator

@goertzenator nope i didn't find it at first time. Thanks for the link :)

benoitc avatar Feb 26 '17 20:02 benoitc

Just for rerefence for people looking at this issue, rebar3-rust works on linux, but is missing some logic to pass specific compile options on macos. cargo-erlangapp works on both linux and osx.

fbernier avatar Feb 28 '17 20:02 fbernier

I just use hooks for now https://github.com/tsloughter/rebar3_run/tree/rust

tsloughter avatar Mar 01 '17 04:03 tsloughter

@tsloughter Neat. Unfortunately this looks like it's working only on linux.

It should be slightly more complicated to get it to work on linux, macos and windows. See https://github.com/goertzenator/cargo-erlangapp/blob/master/src/lib.rs#L166 and https://github.com/goertzenator/cargo-erlangapp/blob/master/src/lib.rs#L19.

fbernier avatar Mar 01 '17 05:03 fbernier

Ah yea, it takes architecture patterns to match on in the hooks it can use for that. Not sure if that'd be enough to do whatever is needed though. So yea, nm, hopefully one of the plugins fills in the gaps :).

tsloughter avatar Mar 01 '17 05:03 tsloughter

And it needs to parse JSON provided by cargo to discover all the binary artifacts.

An Erlang port of cargo-erlangapp would put us a stone's throw from having a portable Rust plugin for rebar3.

goertzenator avatar Mar 01 '17 14:03 goertzenator

@goertzenator I'm just starting erlang but I would work toward shipping a rust NIF in production eventually. Could you elaborate on your though on the best process we should build?

You wish someone would rewrite cargo-erlangapp in erlang, or just write an erlang wrapper around it?

fbernier avatar Mar 01 '17 14:03 fbernier

Thinking about this a little more, a good way forward is to fork https://github.com/sdwolf/rebar3_rust and then port in the capabilities of cargo-erlangapp. I'll eventually get to this myself, but I'll happily help if somebody starts this before me.

The main problem with cargo-erlangapp is that it takes a while (30-60 sec?) to compile on account of having to bring in JSON crates. Managing the installation would also be a hassle. There's nothing in cargo-erlangapp that can't be easily done in Erlang.

goertzenator avatar Mar 01 '17 15:03 goertzenator

It would be nice if rustler_mix and the rebar3 plugin could share the same logic for compilation. If something gets implemented in erlang, I would be very interested in making rustler_mix use that.

hansihe avatar Mar 01 '17 15:03 hansihe

I've got a good start on a rebar3 plugin. It does compile crates on linux, but definitely needs a little more work.

@hansihe : Is rustler_mix a generic crate builder or is it coupled to the rest of Rustler in some way?

goertzenator avatar Mar 07 '17 15:03 goertzenator

@goertzenator There is a boilerplate generator for Rustler in there, but the crate builder itself should be fully generic.

hansihe avatar Mar 07 '17 15:03 hansihe

Ok, good. I'll make a point of getting this plugin tidy and well documented so that it's logic can be ported more easily to rustler_mix. I'll give you heads up when I think it is ready for that.

goertzenator avatar Mar 07 '17 15:03 goertzenator

@goertzenator Great work. I had started something but what you have seems better I think. I'll check it out more and try to help.

fbernier avatar Mar 07 '17 16:03 fbernier

any updates ?

Jxck avatar Oct 22 '18 05:10 Jxck

I've started work on updating goertzenator's project here: https://github.com/filmor/rebar3_rust/tree/update.

It works slightly differently now than before, but I'm so far very content with the new behaviour. It's used in https://github.com/filmor/faster_xml and https://github.com/filmor/arrow-erlang. The plugin is still agnostic to whether you use rustler or rustler_sys (or erlang_nif-sys) and does away with the need of something like find_crate. Documentation will follow as soon as it's ready for public consumption, and I'll probably upload it to Hex then.

filmor avatar Oct 13 '19 21:10 filmor

awesome. thanks!

benoitc avatar Oct 14 '19 05:10 benoitc

Just thinking about naming...does it make more sense to call it rebar3_cargo?

scrogson avatar Oct 14 '19 14:10 scrogson

It could make more sense, yes. I think that the current name is a bit more googleable and it's more obvious for non-Rust BEAM users what it's about.

filmor avatar Oct 14 '19 19:10 filmor

Seems that non-Rust BEAM users wouldn't be using it directly right? It would be NIF devs that would configure their lib to use the rebar3 plugin?

scrogson avatar Oct 14 '19 20:10 scrogson

I just upgraded my simple app to use rustler 0.22 rc.0 and loving it. code is now just:

mod atoms {
    rustler::atoms! { ok }
}

#[rustler::nif]
fn console(path: String) -> NifResult<Atom> {
    // Run release with console
    let _ = Command::new(path).arg("console").exec();

    Ok(atoms::ok())
}

rustler::init!("rebar3_run", [console]);

But I'm still using the rebar3 hooks and want to get a good plugin done before using this for any real projects.

@filmor are you still maintaining? And is @goertzenator still around so updates can be upstreamed?

And then what about having the plugin as part of the @rusterlium org? :)

After all that I can worry about poking @lpil about it generating typed functions for NIFs used from @gleam-lang :)

tsloughter avatar Mar 08 '20 03:03 tsloughter

I'm still working on it, I forked goertzenator's work as rebar3_cargo depending on a new cargo package for Erlang. I'm currently working on getting Rustler's Elixir tooling use that as well s.t. we have a common base. Moving it to rusterlium when releasing to Hex is a good idea.

filmor avatar Mar 08 '20 10:03 filmor

After all that I can worry about poking @lpil about it generating typed functions for NIFs used from @gleam-lang :)

That would be so cool!

lpil avatar Mar 08 '20 11:03 lpil

I don't see myself doing any more work on https://github.com/goertzenator/rebar3_rust . I will happily hand the repo over to someone else if they want it.

goertzenator avatar Mar 08 '20 14:03 goertzenator

what about having the plugin as part of the @rusterlium org?

Yes, that would be excellent 👍

scrogson avatar Mar 09 '20 23:03 scrogson

I've transferred erlang-cargo and rebar3_cargo into the rusterlium org.

filmor avatar Mar 10 '20 09:03 filmor

rebar3_cargo is nearly done, the only functionality missing is handling of executables. As soon as that is done, I'll publish things to Hex.

filmor avatar May 03 '20 13:05 filmor

Sweet!

tsloughter avatar May 03 '20 13:05 tsloughter