Taaitaaiger / jlrs

Julia bindings for Rust
MIT License
408 stars 21 forks source link

Mac OS support / uv.h file not found #93

Closed vyorkin closed 6 days ago

vyorkin commented 1 year ago

Hi! Could you please help me get it to work on Mac OS?

I get the following error:

  cargo:warning=In file included from src/jlrs_cc.c:1:
  cargo:warning=src/jlrs_cc.h:1:10: fatal error: 'uv.h' file not found
  cargo:warning=#include <uv.h>

It fails here. The minimal reproducible example/project: https://github.com/vyorkin/jlrs_macos.git

Here is my env:

$ echo $DYLD_LIBRARY_PATH
/Applications/Julia-1.9.app/Contents/Resources/julia/include/julia
$ cd /Applications/Julia-1.9.app/Contents/Resources/julia/include/julia
$ ls
analyzer_annotations.h  dirpath.h  ENTRY.amd64.h  htable.h     julia.h          julia_fasttls.h  julia_threads.h  MurmurHash3.h  rle.h        tzfile.h  uv
arraylist.h             dtypes.h   ENTRY.i387.h   ios.h        julia_assert.h   julia_gcext.h    julia_version.h  platform.h     strtod.h     utf8.h    uv.h
bitvector.h             END.h      hashing.h      jloptions.h  julia_atomics.h  julia_locks.h    libsupport.h     ptrhash.h      timefuncs.h  utils.h
$ brew list libuv
/opt/homebrew/Cellar/libuv/1.45.0/include/uv/ (5 files)
/opt/homebrew/Cellar/libuv/1.45.0/include/uv.h
/opt/homebrew/Cellar/libuv/1.45.0/lib/libuv.1.dylib
/opt/homebrew/Cellar/libuv/1.45.0/lib/pkgconfig/libuv.pc
/opt/homebrew/Cellar/libuv/1.45.0/lib/ (2 other files)
/opt/homebrew/Cellar/libuv/1.45.0/share/doc/ (28 files)
/opt/homebrew/Cellar/libuv/1.45.0/share/man/man1/libuv.1
$ julia --version
julia version 1.9.1

The output of cargo build: https://gist.github.com/vyorkin/2056bc741d8f11e4ffbed2a8eae5bbda

vyorkin commented 1 year ago

Just tried cloning the repo and running call_julia example, and it fails with the same error on my machine: https://asciinema.org/a/I4msnifn6DduKY8rWdJ00rTcR

Taaitaaiger commented 1 year ago

uv.h is the first file included in jlrs_cc.h, so it seems like the compiler is having trouble finding the include directory. Have you set the JULIA_DIR environment variable?

CI uses the following environment variables:

export JULIA_DIR="$(dirname $(dirname $(which julia)))"
export DYLD_LIBRARY_PATH="${JULIA_DIR}/lib:${JULIA_DIR}/lib/julia:${DYLD_LIBRARY_PATH}"
vyorkin commented 1 year ago

Maybe there is some magic inside that julia github action that makes the env different to what I have following the official installation instructions here https://julialang.org/downloads/platform/#macos.

$ which julia
/usr/local/bin/julia

$ echo $(dirname $(dirname $(which julia)))
/usr/local

$ export JULIA_DIR="$(dirname $(dirname $(which julia)))"
$ echo $JULIA_DIR
/usr/local

$ export DYLD_LIBRARY_PATH="${JULIA_DIR}/lib:${JULIA_DIR}/lib/julia:${DYLD_LIBRARY_PATH}"
$ echo $DYLD_LIBRARY_PATH
/usr/local/lib:/usr/local/lib/julia:

There is no such directory: "/usr/local/lib/julia":

$ cd  /usr/local/lib/julia
cd: no such file or directory: /usr/local/lib/julia
vyorkin commented 1 year ago

I'm sure this path is correct:

echo $DYLD_LIBRARY_PATH
/Applications/Julia-1.9.app/Contents/Resources/julia/include/julia:/Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia

Because:

$ echo $DYLD_LIBRARY_PATH
/Applications/Julia-1.9.app/Contents/Resources/julia/include/julia

$ cd /Applications/Julia-1.9.app/Contents/Resources/julia/include/julia
$ ls | grep uv
uv
uv.h

$ cd cd /Applications/Julia-1.9.app/Contents/Resources/julia/lib/julia
$ ls | grep uv
libuv.2.dylib
libuv.dylib -> libuv.2.dylib

But having uv.h and libuv.dylib in DYLD_LIBRARY_PATH doesn't help, I'm getting the same error

Taaitaaiger commented 1 year ago

The problem isn't that it's not finding the library, it's not finding the header because the headers are not in $JULIA_DIR/include. Could you try setting JULIA_DIR to /Applications/Julia-1.9.app/Contents/Resources/julia/ instead?

I don't have a mac myself so I have to admit I have only experimented with macOS support in CI.

nabeel99 commented 11 months ago

@vyorkin did u ended up finding a fix or a workaround ? facing the same issue.

vyorkin commented 11 months ago

No, unfortunately

nabeel99 commented 11 months ago

Psst it worked for me, setting the env var julia_dir and dyld_library_path as specified in the docs and now its working for me now.