jpy-consortium / jpy

Apache License 2.0
68 stars 16 forks source link

Jpy will not build on Mac OSX if the installed JDK has a `libexec` directory and not a `lib` directory #118

Closed chipkent closed 6 months ago

chipkent commented 7 months ago

I am attempting to install jpy into a python 3.12 development environment on Mac OSX M1. As is standard, brew is used to install most dependencies. jenv is used to switch between JDKs -- including switching JAVA_HOME.

Case 1 -- zulu64-21.0.1 JDK (BUILD WORKS)

Here the Zulu JDK was installed from https://www.azul.com/downloads/?package=jdk#zulu.

jenv add /Library/Java/JavaVirtualMachines/zulu-21.jdk/Contents/Home
jenv global zulu64-21.0.1

The directory structure of Zulu is:

(venv12_newos) ➜  test_avi_4839 ls $JAVA_HOME/
DISCLAIMER   Welcome.html bin          conf         demo         include      jmods        legal        lib          man          readme.txt   release

Note that there is a lib directory and no libexec directory.

(Run these lines one at a time so that env vars get set right)

deactivate
jenv global zulu64-21.0.1
rm -rf ./venv_zulu
python3.12 -m venv ./venv_zulu
source ./venv_zulu/bin/activate
pip cache purge
pip install jpy

It works:

Collecting jpy
  Using cached jpy-0.14.0-cp312-cp312-macosx_12_0_arm64.whl
Installing collected packages: jpy
Successfully installed jpy-0.14.0

Case 2 -- OpenJDK@17 (BUILD FAILS)

Here OpenJDK@17 is installed using brew install openjdk@17.

brew install openjdk@17
jenv add /opt/homebrew/opt/openjdk@17/
jenv global 17.0.9

The directory structure of OpenJDK is:

(venv12_newos) ➜  test_avi_4839 ls $JAVA_HOME/
INSTALL_RECEIPT.json  LICENSE               README.md             bin/                  include/              libexec/              share/

Note that there is a libexec directory and no lib directory.

(Run these lines one at a time so that env vars get set right)

deactivate
jenv global 17.0.9
rm -rf ./venv_ojdk
python3.12 -m venv ./venv_ojdk
source ./venv_ojdk/bin/activate
pip cache purge
pip install jpy

It fails:

Collecting jpy
  Downloading jpy-0.14.0.tar.gz (172 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 172.2/172.2 kB 1.4 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [1 lines of output]
      Error: environment variable "JAVA_HOME" must be set to a JDK (>= v1.7) installation directory
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

In this case when jpy tries to build against OpenJDK, it claims JAVA_HOME is not set.

Soruce of the problem

The error message is coming from https://github.com/jpy-consortium/jpy/blob/14b19a72371c473f022b668965f5b62036536ab8/setup.py#L104 because jdk_home_dir is None. This is coming from https://github.com/jpy-consortium/jpy/blob/14b19a72371c473f022b668965f5b62036536ab8/jpyutil.py#L143. Here there is a requirement that there be a lib dir without also checking for a libexec dir.

devinrsmith commented 7 months ago

I think there are also more fundamental 3.12 concerns that need to be addressed too - see https://github.com/jpy-consortium/jpy/issues/115