tweag/inline-java

Cannot compile on MacOS

AlexeyRaga opened this issue · 5 comments

I am having problems compiling inline-java on MacOS.

Particularly, jni package cannot be built because it can't find the jvm library:

$ stack build jni --extra-lib-dirs=$JAVA_HOME/jre/lib/server/ --extra-include-dirs $JAVA_HOME/include --extra-include-dirs $JAVA_HOME/include/darwin
jni-0.6.0: configure
jni-0.6.0: build

--  While building custom Setup.hs for package jni-0.6.0 using:
      /Users/araga/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.0.1.0 build --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1
    Logs have been written to: /Users/araga/src/arbor/sparkle-attacks/.stack-work/logs/jni-0.6.0.log

    Configuring jni-0.6.0...
    Preprocessing library for jni-0.6.0..
    dyld: Library not loaded: @rpath/libjvm.dylib
      Referenced from: /private/var/folders/3x/l50y6rts50j_9jqyp0fl7lqh0000gn/T/stack58755/jni-0.6.0/.stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/Foreign/JNI/NativeMethod_hsc_make
      Reason: image not found
    running .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/Foreign/JNI/NativeMethod_hsc_make failed (exit code -6)
    command was: .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/Foreign/JNI/NativeMethod_hsc_make  >.stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/Foreign/JNI/NativeMethod.hs

I have tried providing --ghc-options "-optl-Wl,-rpath,$JAVA_HOME/jre/lib/server" but it doesn't help.

I have also tried adding these options to my stack.yaml file:

ghc-options:
  "*": -optl-Wl,-rpath,$JAVA_HOME/jre/lib/server

and

ghc-options:
  jni: -optl-Wl,-rpath,/Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home/jre/lib/server

but it doesn't help either.

Can anyone advice on how to configure my project to build it successfully with inline-java?

mboes commented

macOS unsupported at the moment. You might need to add the path using DYLD_LIBRARY_PATH.

Oh sorry, I should have mentioned it, but I tried setting this variable too:

DYLD_LIBRARY_PATH=$JAVA_HOME/jre/lib/server/ stack build --extra-lib-dirs=$JAVA_HOME/jre/lib/server/ --extra-include-dirs $JAVA_HOME/include --extra-include-dirs $JAVA_HOME/include/darwin

with (unfortunately) the same effect

mboes commented

So the following seems to work fine for me on master, using Brew's AdoptJDK cask:

$ brew tap AdoptOpenJDK/openjdk
$ brew install adoptopenjdk-openjdk8
$ stack build \
    --extra-lib-dirs=/usr/local/Cellar/adoptopenjdk-openjdk8/jdk8u144-b01/jre/lib/server/ \
    --extra-include-dirs=/usr/local/Cellar/adoptopenjdk-openjdk8/jdk8u144-b01/include/ \
    --extra-include-dirs=/usr/local/Cellar/adoptopenjdk-openjdk8/jdk8u144-b01/include/darwin/

Will add a CI job to test this over time.

mboes commented

@AlexeyRaga OK I got a CI job for macOS running over at #116. I hope you can use that as a reference point.

@mboes thank you very much!