rusterlium / rustler

Safe Rust bridge for creating Erlang NIF functions
https://docs.rs/crate/rustler
Apache License 2.0
4.33k stars 225 forks source link

Unable to run tarpaulin on Rustler project #497

Closed thomas9911 closed 1 year ago

thomas9911 commented 1 year ago

When I try to run tarpaulin I get a linker error that the erlang functions cannot be found, for example: undefined reference to enif_binary_to_term

Made a minimal repo to show the problem: https://github.com/thomas9911/rustler_tarpaulin I also linked the full error dump in that repo (under dump.txt)

filmor commented 1 year ago

NIF libraries are not linked to a library containing those symbols. The symbols exist in the BEAM runtime, and when the NIF DLL/so/dylib is loaded into the process, it can use them.

thomas9911 commented 1 year ago

Ah okay, so a method to get code coverage on the Rust part is to move that to a separate library run coverage on that and have a small interface to expose it as a NIF (that calls that library and converts it from/to Terms) ?

filmor commented 1 year ago

That would be an option, yes. An alternative option would be to extend tarpaulin (if it doesn't support this already) to run an arbitrary command-line instrumented and make it run your Erlang/Elixir test-suite instead.

There is an equivalent issue already here https://github.com/xd009642/tarpaulin/issues/1092 (Python extension modules behave in the same way as NIFs, they are loaded at runtime using dlopen or LoadLibrary and access the symbols of the "host" executable).

There is nothing we can do in Rustler directly, as far as I can see.

thomas9911 commented 1 year ago

Thank you for the explaination