Простой воспроизводимый пример:
binding.gyp
:
{
"targets": [
{
"target_name": "hello",
"sources": [ "./hello.cc" ],
"cflags_cc": [ "-mavx2" ]
}
]
}
hello.cc
// hello.cc
#include <node.h>
namespace demo {
using v8::FunctionCallbackInfo;
using v8::Isolate;
using v8::Local;
using v8::NewStringType;
using v8::Object;
using v8::String;
using v8::Value;
void Method(const FunctionCallbackInfo<Value>& args) {
Isolate* isolate = args.GetIsolate();
args.GetReturnValue().Set(String::NewFromUtf8(
isolate, "world", NewStringType::kNormal).ToLocalChecked());
}
void Initialize(Local<Object> exports) {
NODE_SET_METHOD(exports, "hello", Method);
}
NODE_MODULE(NODE_GYP_MODULE_NAME, Initialize)
} // namespace demo
Предположим, я хочу добавить флаг -mavx2
в c ++компилятор.Но node-gyp
просто игнорирует его и не использует в компиляторе.
Чтобы выяснить это, я запустил node-gyp rebuild --verbose
:
Полный журнал (вам, вероятно, он не нужен):
~/WebstormProjects/shiningExample node-gyp rebuild --verbose
gyp info it worked if it ends with ok
gyp verb cli [ '/Users/andrey/.nvm/versions/node/v10.15.0/bin/node',
gyp verb cli '/usr/local/bin/node-gyp',
gyp verb cli 'rebuild',
gyp verb cli '--verbose' ]
gyp info using node-gyp@3.8.0
gyp info using node@10.15.0 | darwin | x64
gyp verb command rebuild []
gyp verb command clean []
gyp verb clean removing "build" directory
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` succeeded python2 /usr/local/bin/python2
gyp verb check python version `/usr/local/bin/python2 -c "import sys; print "2.7.15
gyp verb check python version .%s.%s" % sys.version_info[:3];"` returned: %j
gyp verb get node dir no --target version specified, falling back to host node version: 10.15.0
gyp verb command install [ '10.15.0' ]
gyp verb install input version string "10.15.0"
gyp verb install installing version: 10.15.0
gyp verb install --ensure was passed, so won't reinstall if already installed
gyp verb install version is already installed, need to check "installVersion"
gyp verb got "installVersion" 9
gyp verb needs "installVersion" 9
gyp verb install version is good
gyp verb get node dir target node version installed: 10.15.0
gyp verb build dir attempting to create "build" dir: /Users/andrey/WebstormProjects/shiningExample/build
gyp verb build dir "build" dir needed to be created? /Users/andrey/WebstormProjects/shiningExample/build
gyp verb build/config.gypi creating config file
gyp verb build/config.gypi writing out config file: /Users/andrey/WebstormProjects/shiningExample/build/config.gypi
gyp verb config.gypi checking for gypi file: /Users/andrey/WebstormProjects/shiningExample/config.gypi
gyp verb common.gypi checking for gypi file: /Users/andrey/WebstormProjects/shiningExample/common.gypi
gyp verb gyp gyp format was not specified; forcing "make"
gyp info spawn /usr/local/bin/python2
gyp info spawn args [ '/Users/andrey/.config/yarn/global/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 '/Users/andrey/WebstormProjects/shiningExample/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/andrey/.config/yarn/global/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/Users/andrey/.node-gyp/10.15.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/Users/andrey/.node-gyp/10.15.0',
gyp info spawn args '-Dnode_gyp_dir=/Users/andrey/.config/yarn/global/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/Users/andrey/.node-gyp/10.15.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/Users/andrey/WebstormProjects/shiningExample',
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 verb command build []
gyp verb build type Release
gyp verb architecture x64
gyp verb node dev dir /Users/andrey/.node-gyp/10.15.0
gyp verb `which` succeeded for `make` /usr/bin/make
gyp info spawn make
gyp info spawn args [ 'V=1', 'BUILDTYPE=Release', '-C', 'build' ]
c++ '-DNODE_GYP_MODULE_NAME=hello' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/andrey/.node-gyp/10.15.0/include/node -I/Users/andrey/.node-gyp/10.15.0/src -I/Users/andrey/.node-gyp/10.15.0/deps/openssl/config -I/Users/andrey/.node-gyp/10.15.0/deps/openssl/openssl/include -I/Users/andrey/.node-gyp/10.15.0/deps/uv/include -I/Users/andrey/.node-gyp/10.15.0/deps/zlib -I/Users/andrey/.node-gyp/10.15.0/deps/v8/include -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/hello/hello.o.d.raw -c -o Release/obj.target/hello/hello.o ../hello.cc
c++ -bundle -undefined dynamic_lookup -Wl,-no_pie -Wl,-search_paths_first -mmacosx-version-min=10.7 -arch x86_64 -L./Release -stdlib=libc++ -o Release/hello.node Release/obj.target/hello/hello.o
gyp info ok
Мне нужна строка:
c++ '-DNODE_GYP_MODULE_NAME=hello' '-DUSING_UV_SHARED=1' '-DUSING_V8_SHARED=1' '-DV8_DEPRECATION_WARNINGS=1' '-D_DARWIN_USE_64_BIT_INODE=1' '-D_LARGEFILE_SOURCE' '-D_FILE_OFFSET_BITS=64' '-DBUILDING_NODE_EXTENSION' -I/Users/andrey/.node-gyp/10.15.0/include/node -I/Users/andrey/.node-gyp/10.15.0/src -I/Users/andrey/.node-gyp/10.15.0/deps/openssl/config -I/Users/andrey/.node-gyp/10.15.0/deps/openssl/openssl/include -I/Users/andrey/.node-gyp/10.15.0/deps/uv/include -I/Users/andrey/.node-gyp/10.15.0/deps/zlib -I/Users/andrey/.node-gyp/10.15.0/deps/v8/include -Os -gdwarf-2 -mmacosx-version-min=10.7 -arch x86_64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++1y -stdlib=libc++ -fno-rtti -fno-exceptions -fno-strict-aliasing -MMD -MF ./Release/.deps/Release/obj.target/hello/hello.o.d.raw -c -o Release/obj.target/hello/hello.o ../hello.cc
, которая не содержит флаг -mavx2
.Что я делаю не так?
Вот что я использую:
~/WebstormProjects/shiningExample node-gyp -v
v3.8.0
~/WebstormProjects/shiningExample node -v
v10.15.0
~/WebstormProjects/shiningExample c++ -v
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Found CUDA installation: /usr/local/cuda, version unknown