unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

on macos homebrew install, native/compiled executable can't find libb2 #5365

Closed aryairani closed 1 month ago

aryairani commented 1 month ago

Describe and demonstrate the bug

After using compile.native main /dest/executable for a main that uses blake2, when running the executable, the system may not find libb2. It's looking in /usr/lib which was reasonable before Apple Silicon; now homebrew puts libb2 in /opt/homebrew/lib.

libb2: blake2s
ffi-lib: could not load foreign library
  path: libb2.1.dylib
  system error: dlopen(libb2.1.dylib, 0x0006): tried: 'libb2.1.dylib' (no such file), '/System/Volumes/Preboot/Cryptexes/OSlibb2.1.dylib' (no such file), '/usr/lib/libb2.1.dylib' (no such file, not in dyld cache), 'libb2.1.dylib' (no such file), '/usr/local/lib/libb2.1.dylib' (no such file), '/usr/lib/libb2.1.dylib' (no such file, not in dyld cache)
  context...:
   .../ffi/unsafe.rkt:134:0: get-ffi-lib
   body of '#%embedded:unison/crypto:

  context...:
   .../unison/crypto.rkt:250:0: hashBytes-raw
   .../unison/simple-wrappers.ss:2308:0: builtin-crypto.hashBytes:impl
   .../tmp/jit-tests.rkt:4508:0: ref-00uhcb3m1ppu5insfo13ubplffhigh7j06trgl8gk7er7u6hapnas:impl
   .../tmp/jit-tests.rkt:1379:0: ref-007497f80fg1ptro01sjktjlrbbfrifva7ktejlvjgno3s7k1f9n8:impl
   .../tmp/jit-tests.rkt:2387:0: ref-00f53dg082fnq63i3cuc21hj1hg6q4av64ourm984hdnr9s2qradk:impl
   .../racket/control.rkt:137:30
   .../tmp/jit-tests.rkt:16108:0: ref-037mnlieva5dohs9m3vcvm9g7vd14jd9nejfirdiidcbjqg2t9hva:impl
   .../tmp/jit-tests.rkt:7446:0: ref-01gq56askk3m7mi7lcc8c5dhkae38eo4ktg081hbuum2561jblb1s:impl
   .../racket/control.rkt:137:30
   body of '#%mzc:jit-tests

Screenshots If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

Additional context Until we figure out how to have the system look in the right place, you can work around it with

DYLD_FALLBACK_LIBRARY_PATH=<dir containing libb2> <executable>

e.g.

DYLD_FALLBACK_LIBRARY_PATH=/opt/homebrew/lib /tmp/jit-tests
aryairani commented 1 month ago

Idea: static linking somehow? but it would have to be done by raco.

aryairani commented 1 month ago

https://docs.racket-lang.org/raco/exe-dist.html <-- this process is supposed to bundle / set-up required DLLs, but it isn't working in the case of libb2.

aryairani commented 1 month ago

Maybe could do this

On Windows and Mac OS, native libraries tend to be included with the output of raco distribute. On Unix platforms, native libraries tend not to be included, so system libraries will be used on the host machine. The difference is whether a Racket installation itself includes bundled native libraries or relies on system-installed libraries. Adding a symbolic link in Racket’s "lib" directory to a system-installed library causes that library to be included with a distribution directory created by raco distribute; see also define-runtime-path.

as of https://github.com/unisonweb/homebrew-unison/pull/11, which wasn't possible before due to homebrew sandboxing.

aryairani commented 1 month ago

presumed fixed by https://github.com/unisonweb/homebrew-unison/commit/7c91c7e22fabd60a7759f40d3405467798dc1683