node-java icon indicating copy to clipboard operation
node-java copied to clipboard

node-gyp configure fails on ppc64le and target_arch not being set in binding.gyp

Open swsharp opened this issue 8 years ago • 1 comments

Install fails on RHEL 7.5 server running on ppc64le architecture due to two related issues.

$ npm install java

> [email protected] install /home/node/node_modules/java
> node-gyp rebuild

./find_java_libdir.sh: line 63: lib_dir: unbound variable
gyp: Call to './find_java_libdir.sh ppc64 linux' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/apps/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:336:16)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Linux 3.10.0-862.2.3.el7.ppc64le
gyp ERR! command "/apps/node/bin/node" "/apps/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/node/node_modules/java
gyp ERR! node -v v8.11.1
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open '/home/node/package.json'
npm WARN node No description
npm WARN node No repository field.
npm WARN node No README data
npm WARN node No license field.

I fixed the line 63: lib_dir: unbound variable error by changing local lib_dir to local lib_dir=""

I got the configure to complete by adding a condition to find_java_libdir.sh for ppc64le.

elif [[ "${os}" == "linux" ]] && [[ "${target_arch}" == "ppc64le" || "${target_arch}" == "ppcle" ]]; then
    if [[ -d ${jre_dir}/ppc64le/classic ]]; then lib_dir="${jre_dir}"/ppc64le/classic; else lib_dir="${jre_dir}"/ppc64le/server; fi

I tried adding the necessary condition to the binding.gyp file for ppc64le but node-gyp just seemed to ignore the condition.

['uname_m=="ppc64le"', {
  'target_arch': 'ppc64le'
}],

Then I tried altering the existing ppc64 condition but that was also being ignored by node-gyp.

['uname_m=="ppc64"', {
  'target_arch': 'ppc64le'
}],

The target_arch was being passed as ppc64 no matter what changes I tried making to the binding.gyp conditions.

error: Can't find lib dir for linux ppc64, java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-7.b10.el7.ppc64le
gyp: Call to './find_java_libdir.sh ppc64 linux' returned exit status 1 while in binding.gyp. while trying to load binding.gyp

I eventually found that I could override the target_arch variable within node-gyp and, along with my other changes, the configure and build completed.

# node-gyp configure build --target_arch=ppc64le
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | linux | ppc64
gyp info spawn /bin/python2
gyp info spawn args [ '/apps/node/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/apps/nodeapps/node-java/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/apps/node/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/root/.node-gyp/8.11.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/root/.node-gyp/8.11.1',
gyp info spawn args   '-Dnode_gyp_dir=/apps/node/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/root/.node-gyp/8.11.1/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=/apps/nodeapps/node-java',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory `/apps/nodeapps/node-java/build'
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/java.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaObject.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/javaScope.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/methodCallBaton.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/nodeJavaBridge.o
  CXX(target) Release/obj.target/nodejavabridge_bindings/src/utils.o
  SOLINK_MODULE(target) Release/obj.target/nodejavabridge_bindings.node
  COPY Release/nodejavabridge_bindings.node
make: Leaving directory `/apps/nodeapps/node-java/build'
gyp info ok

I have the changes committed in a fork but still wasn't able to get the binding.gyp to work as intended. Perhaps someone else who knows more about node-gyp can figure something out.

swsharp avatar Jun 11 '18 15:06 swsharp

I have another possible commit that deals with this issue fully. Not sure if it's the right way to do it but it works. Rather than trying to set the target_arch variable in binding.gyp it seemed just as reasonable to leave the target architecture as ppc64 as far as node-gyp is concerned. In this version find_java_libdir.sh gets the result of uname -m and uses that as the architecture value in the Java lib path.

elif [[ "${os}" == "linux" ]] && [[ "${target_arch}" == "ppc64" || "${target_arch}" == "ppc" ]]; then
    target_arch=`uname -m`
    if [[ -d ${jre_dir}/${target_arch}/classic ]]; then lib_dir="${jre_dir}"/${target_arch}/classic; else lib_dir="${jre_dir}"/${target_arch}/server; fi

This works on my ppc64le environment and it's no longer necessary to override the node-gyp environment with --target_arch=ppc64le.

Thoughts, @joeferner ?

swsharp avatar Jun 11 '18 18:06 swsharp