nwjs / nw-gyp

native addon build tool for node-webkit
MIT License
195 stars 46 forks source link

Can't compile for Apple Silicon ARM64 #145

Open gpetrov opened 3 years ago

gpetrov commented 3 years ago

Trying to compile the native node modules for Apple Silicon arm64 - fails. It just doesn't pickup the new arm64 architecture for Darwin.

# Install nw-gyp globally
#npm install -g nw-gyp
# Setup target NW.js version
export npm_config_target=0.50.0
# Setup build architecture, ia32 or x64
export npm_config_arch=arm64
export npm_config_target_arch=arm64
# Setup env for modules built with node-pre-gyp
export npm_config_runtime=node-webkit
export npm_config_build_from_source=true
# Setup nw-gyp as node-gyp
export npm_config_node_gyp=$(which nw-gyp)
# Run npm install
nom install

trying to compile nodegit and node-pty both fail with similar error:

In file included from /Users/george/.nw-gyp/0.50.0/deps/v8/include/v8.h:30:
/Users/george/.nw-gyp/0.50.0/deps/v8/include/v8-internal.h:418:38: error: no
      template named 'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:697:50: note: 
      'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/nodegit/src/async_baton.o] Error 1

tried also running directly: nw-gyp configure --target=0.50.0 --target_arch=arm64

but list afterwrards produces:

nw-gyp list --target=0.50.0 --target_arch=arm64
gyp info it worked if it ends with ok
gyp info using nw-gyp@3.6.5
gyp info using node@14.15.1 | darwin | x64
0.50.0
gyp info ok 

as as you can see x64 is still detected and nw-gyp build fails

@rogerwang can you check this please? it is the final peace to move to Apple Silicon M1 with arm. As the base of NWJS seems to be running fine natively we just need to be able also to compile custom native node modules.

rogerwang commented 3 years ago

It works for me building node-pty. Note that you'll need the MacOSX11.0.sdk that comes with Xcode 12.2.

gpetrov commented 3 years ago

yes of course I have Xcode 12.2, but how did you compile it? I just get:

> node-pty@0.9.0 install /Users/george/Documents/SVN/Wappler/node_modules/node-pty
> node scripts/install.js

  CXX(target) Release/obj.target/pty/src/unix/pty.o
In file included from ../src/unix/pty.cc:20:
In file included from ../../nan/nan.h:54:
In file included from /Users/george/.nw-gyp/0.50.0/src/node.h:67:
In file included from /Users/george/.nw-gyp/0.50.0/deps/v8/include/v8.h:30:
/Users/george/.nw-gyp/0.50.0/deps/v8/include/v8-internal.h:418:38: error: no template named
      'remove_cv_t' in namespace 'std'; did you mean 'remove_cv'?
            !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
                                ~~~~~^~~~~~~~~~~
                                     remove_cv
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:697:50: note: 
      'remove_cv' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
                                                 ^
1 error generated.
make: *** [Release/obj.target/pty/src/unix/pty.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/nw-gyp/lib/build.js:271:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
gyp ERR! System Darwin 20.1.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/bin/nw-gyp" "rebuild"
gyp ERR! cwd /Users/george/Documents/SVN/Wappler/node_modules/node-pty
gyp ERR! node -v v14.15.1
gyp ERR! nw-gyp -v v3.6.5
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-pty@0.9.0 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-pty@0.9.0 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
rogerwang commented 3 years ago

I'm just using the commands you posted.

gpetrov commented 3 years ago

ah seems there was some old std=c++11 in binding.gyp in node-pty (they recently removed it - but it is not published yet) it needs to be now at least std=c++14. or removed

same is also for nodegit - they also have some old c++11 options there

gpetrov commented 3 years ago

Solution mentioned at: https://github.com/nwjs/nw.js/issues/7620#issuecomment-733684392 maybe it can be integrated in a nw-gyp update