ibmruntimes / node

This repository is moving to: https://github.com/ibmruntimes/node-zos
69 stars 24 forks source link

"npm install" for dependency ffi fails on z/OS #122

Open mgerth opened 5 years ago

mgerth commented 5 years ago

I've a project where I need to call a shared library from Node.js. To achieve this I used "Node.js Foreign Function Interface" (https://github.com/node-ffi/node-ffi)... unfortunately the install stops with an error. I stripped down the package.json file to make it as simple as possible:

bash-4.3$ cat package.json
{
  "name": "ffi-test",
  "version": "1.0.0",
  "description": "FFI test.",
  "main": "index.js",
  "scripts": {
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "ffi": "^2.3.0"
  }
}

Here is the output of the "npm i" command:

bash-4.3$ npm i

ref@1.3.5 install /DA3F/u/ada/ger/code/test/node_modules/ref node-gyp rebuild

make: Entering directory '/DA3F/u/ada/ger/code/test/node_modules/ref/build' CXX(target) Release/obj.target/binding/src/binding.o ../src/binding_temp.cc:325:42: warning: data argument not used by format string [-Wformat-extra-args] snprintf(strbuf, 128, "\x25" PRId64, val);


../src/binding_temp.cc:412:42: warning: data argument not used by format string [-Wformat-extra-args]
    snprintf(strbuf, 128, "\x25" PRIu64, val);
                          ~~~~~~~~~~~~~  ^
../src/binding_temp.cc:640:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("\x65\x6e\x64\x69\x61\x6e\x6e\x65\x73\x73").ToLocalChecked(), Nan::New<v8::String>(CheckEndianness()).ToLocalChecked(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../nan/nan_maybe_43_inl_temp.h:130:35: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
                                  ^
../src/binding_temp.cc:641:8: warning: 'ForceSet' is deprecated [-Wdeprecated-declarations]
  Nan::ForceSet(target, Nan::New<v8::String>("\x4e\x55\x4c\x4c").ToLocalChecked(), WrapNullPointer(), static_cast<PropertyAttribute>(ReadOnly|DontDelete));
       ^
../../nan/nan_maybe_43_inl_temp.h:130:35: note: 'ForceSet' has been explicitly marked deprecated here
NAN_DEPRECATED inline Maybe<bool> ForceSet(
                                  ^
4 warnings generated.
  SOLINK_MODULE(target) Release/obj.target/binding.node
  COPY Release/binding.node
make: Leaving directory '/DA3F/u/ada/ger/code/test/node_modules/ref/build'

> ffi@2.3.0 install /DA3F/u/ada/ger/code/test/node_modules/ffi
> node-gyp rebuild

make: Entering directory '/DA3F/u/ada/ger/code/test/node_modules/ffi/build'
  CC(target) Release/obj.target/ffi/deps/libffi/src/prep_cif.o
../deps/libffi/src/prep_cif.c:26:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^
../deps/libffi/src/prep_cif_temp.c:27:10: fatal error: 'ffi.h' file not found
#include <ffi.h>
         ^
1 error generated.
Error while processing ../deps/libffi/src/prep_cif_temp.c.
CNJ0793(I) Compilation failed for file ../deps/libffi/src/prep_cif_temp.c.  Object file not created.
deps/libffi/ffi.target.mk:103: recipe for target 'Release/obj.target/ffi/deps/libffi/src/prep_cif.o' failed
make: *** [Release/obj.target/ffi/deps/libffi/src/prep_cif.o] Error 12
make: Leaving directory '/DA3F/u/ada/ger/code/test/node_modules/ffi/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/DA3F/u/ada/ger/bin/node-v6.17.0-os390-s390x/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:219:12)
gyp ERR! System OS/390 25.00
gyp ERR! command "/DA3F/u/ada/ger/bin/node-v6.17.0-os390-s390x/bin/node" "/DA3F/u/ada/ger/bin/node-v6.17.0-os390-s390x/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /DA3F/u/ada/ger/code/test/node_modules/ffi
gyp ERR! node -v v6.17.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm WARN ffi-test@1.0.0 No repository field.
npm ERR! OS/390 25.00
npm ERR! argv "/DA3F/u/ada/ger/bin/node-v6.17.0-os390-s390x/bin/node" "/DA3F/u/ada/ger/bin/node-v6.17.0-os390-s390x/bin/npm" "i"
npm ERR! node v6.17.0
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE

npm ERR! ffi@2.3.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ffi@2.3.0 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ffi package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs ffi
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls ffi
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /DA3F/u/ada/ger/code/test/npm-debug.log
bash-4.3$

My environment is the following:

bash-4.3$ uname -a OS/390 DA3F 25.00 04 2965 bash-4.3$ node --version v6.17.0 bash-4.3$ npm --version 3.10.10

I assume that it is a problem of the node-ffi package, but perhaps has someone run into a similar problem. Any suggestions to solve the problem are appreciated ...

richardlau commented 5 years ago

Looking at the build scripts for node-ffi, when building its deps/libffi it has this for include_dirs: https://github.com/node-ffi/node-ffi/blob/169773db0d56c4c99225b307b3dc86a46f3af34d/deps/libffi/libffi.gyp#L106-L110

      'include_dirs': [
        'include',
        # platform and arch-specific headers
        'config/<(OS)/<(target_arch)'
      ],

Looking at https://github.com/node-ffi/node-ffi/tree/master/deps/libffi/config there is no generated configuration for OS/390. Steps to generate a configuration are listed in https://github.com/node-ffi/node-ffi/blob/master/deps/libffi/config/README.

mgerth commented 5 years ago

@richardlau: Thanks for the quick answer ...

Unfortunately the configure fails:

bash-4.3$ ./configure --enable-static --disable-shared --disable-builddir --with-pic
checking build system type... i370-ibm-openedition
checking host system type... i370-ibm-openedition
checking target system type... i370-ibm-openedition
checking for gsed... sed
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking whether make sets $(MAKE)... yes
checking for gcc... no
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... no
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... unsupported
checking for style of include used by make... GNU
checking dependency style of cc... none
checking dependency style of cc... none
checking whether cc understands -c and -o together... no
checking how to print strings... printf
checking for a sed that does not truncate output... /DA3F/u/ada/mm/p/python-2017-04-12-py27/python27/bin/sed
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for fgrep... /bin/grep -F
checking for non-GNU ld... /bin/ld
checking if the linker (/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /bin/nm -p
checking the name lister (/bin/nm -p) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert i370-ibm-openedition file names to i370-ibm-openedition format... func_convert_file_noop
checking how to convert i370-ibm-openedition file names to toolchain format... func_convert_file_noop
checking for /bin/ld option to reload object files... -r
checking for objdump... no
checking how to recognize dependent libraries... unknown
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... no
checking command to parse /bin/nm -p output from /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc object... failed
checking for sysroot... no
checking for mt... no
checking if : is a manifest tool... no
checking how to run the C preprocessor... /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking for /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc option to produce PIC...  -DPIC
checking if /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc PIC flag  -DPIC works... yes
checking if /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc static flag  works... yes
checking if /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc supports -c -o file.o... yes
checking if /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc supports -c -o file.o... (cached) yes
checking whether the /DA3F/u/ada/ger/code/node-ffi/deps/libffi/compile cc linker (/bin/ld) supports shared libraries... no
checking dynamic linker characteristics... no
checking how to hardcode library paths into programs... unsupported
checking whether stripping libraries is possible... no
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for C compiler vendor... ibm
checking whether C compiler accepts -qarch=auto -qtune=auto... no
******************************************************
*  You seem to have the IBM  C compiler.  It is      *
*  recommended for best performance that you use:    *
*                                                    *
*    CFLAGS=-O3 -qarch=xxx -qtune=xxx -qansialias -w *
*                      ^^^        ^^^                *
*  where xxx is pwr2, pwr3, 604, or whatever kind of *
*  CPU you have.  (Set the CFLAGS environment var.   *
*  and re-run configure.)  For more info, man cc.    *
******************************************************
checking whether C compiler accepts -O3 -qansialias -w... no
********************************************************`
* WARNING: The guessed CFLAGS don't seem to work with  *
* your compiler.                                       *
* Use ./configure CFLAGS=... to specify your own flags *
********************************************************
checking CFLAGS for maximum warnings... +w1
checking whether to enable maintainer-specific portions of Makefiles... no
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for mmap... no
checking for sys/mman.h... (cached) yes
checking for mmap... (cached) no
configure: error: "libffi has not been ported to i370-ibm-openedition."
richardlau commented 5 years ago
configure: error: "libffi has not been ported to i370-ibm-openedition."

Looks like this is from here https://github.com/node-ffi/node-ffi/blob/d9b843c03b35b99f205d001ebcbedd1b6c63b3d0/deps/libffi/configure.ac#L212 which has a case statement a few lines above it.