rusterlium / rustler

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

Missing `priv` library does not trigger re-compile #616

Closed ggwpez closed 3 months ago

ggwpez commented 4 months ago

Hey thanks for the project, really useful πŸ˜„

When I delete the .so files in the priv/native/ folder, then the following mix test invocation will error that they are not found:

error: module ErasureCoding.Native is not loaded and could not be found
    β”‚
  3 β”‚   doctest ErasureCoding.Native
    β”‚   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    β”‚
    └─ test/bindings/erasure_coding_test.exs:3: Bindings.ErasureCoding.Test (module)

20:57:18.167 [warning] The on_load function for module Elixir.ErasureCoding.Native returned:
{:error,
 {:load_failed,
  ~c"Failed to load NIF library: 'dlopen(... 'graymatter/priv/native/liberasure_coding.so' (no such file)'"}}

I got around this by adding:

@external_resource "priv/native/liberasure_coding.so"

To my NIF module here. Is this expected or could maybe Rustler already generate this attribute in its derive macro?

Having it auto recompile in these cases helps when Ctrl-C-ing the build or in CI where caching does not restore everything. Hopefully this is easy to reproduce, otherwise I will make an example project.


{:rustler, "~> 0.33.0"},
$ elixir -v
Erlang/OTP 26 [erts-14.2.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.16.3 (compiled with Erlang/OTP 26)

on MacOS 14.5
filmor commented 3 months ago

The issue is simply that we currently don't count the copied build artifacts themselves as "external resources". It's not hard to fix this.