Using cargo to build dynamic libraries on mac sets id/name for linker to something questionable

If I build a "cdylib" using cargo build --release, it tells the linker that the library is located in the target/release directory.

Here is the output for otool -l:

Load command 4
          cmd LC_ID_DYLIB
      cmdsize 96
         name /Users/vanessa/dev/rust/forks/regex/target/release/deps/librure.dylib (offset 24)
   time stamp 1 Wed Dec 31 19:00:01 1969
      current version 0.0.0
compatibility version 0.0.0

This means I can't install the shared library by copying the .dylib to /usr/local/lib; I have to run install_name_tool on the build result before distributing.

I think cargo build --release should set the name to something like @rpath/librure.dylib; is it worth filing an issue in cargo? Is there some known workaround?

Apparently there is a env var DYLD_LIBRARY_PATH which can be used.

I tried that! It doesn't set the ID of the library itself however.