mapbox / node-cpp-skel

Skeleton for bindings to C++ libraries for Node.js using node-addon-api
Creative Commons Zero v1.0 Universal
72 stars 10 forks source link

Avoiding hardcoded build options #133

Open artemp opened 6 years ago

artemp commented 6 years ago

Currently in order to build on Ubuntu Linux (18.04) using either system g++7 or source compiled clang++7 I had to apply following patch:

CXX=/usr/bin/g++ make
diff --git a/common.gypi b/common.gypi
index 803f217..6ae5c84 100644
--- a/common.gypi
+++ b/common.gypi
@@ -38,11 +38,8 @@
           'NDEBUG'
         ],
         'cflags': [
-         '-flto'
         ],
         'ldflags': [
-         '-flto',
-         '-fuse-ld=<(module_root_dir)/mason_packages/.link/bin/ld'
         ],
         'xcode_settings': {
           'OTHER_CPLUSPLUSFLAGS!': [
springmeyer commented 6 years ago

@artemp thanks for creating this / catching the problem. I thought I tested well enough on linux, but I must have missed something. LTO, in my experience, is hard to get working on linux, so I'm open to reverting this change and having LTO be opt-in rather than opt-out.

But, before reverting I'm interested in what the exact errors you are seeing with CXX=/usr/bin/g++ make before removing LTO? Also (again with the -flto still in place) what happens if you try:

CXX=/usr/bin/g++ LINK=/usr/bin/g++ make

or

CXX=/usr/bin/g++ LINK=/usr/bin/g++ AR="gcc-ar" NM="gcc-nm" RANLIB="gcc-ranlib" make

Refs:

artemp commented 6 years ago

CXX=clang++ make

/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/clang++ -shared -pthread -rdynamic -m64 -Wl,-z,now -flto -flto  -Wl,-soname=module.node -o /home/artem/projects/node-cpp-skel/lib/binding/module.node -Wl,--start-group Release/obj.target/module/src/module.o Release/obj.target/module/src/standalone/hello.o Release/obj.target/module/src/standalone_async/hello_async.o Release/obj.target/module/src/object_sync/hello.o Release/obj.target/module/src/object_async/hello_async.o -Wl,--end-group 
Intrinsic has incorrect argument type!
void (i8*, i8*, i64, i1)* @llvm.memcpy.p0i8.p0i8.i64
LLVM ERROR: Broken function found, compilation aborted!

CXX=g++ make

/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/ld: Release/obj.target/module/src/module.o: plugin needed to handle lto object
/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/ld: Release/obj.target/module/src/standalone/hello.o: plugin needed to handle lto object
/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/ld: Release/obj.target/module/src/standalone_async/hello_async.o: plugin needed to handle lto object
/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/ld: Release/obj.target/module/src/object_sync/hello.o: plugin needed to handle lto object
/home/artem/projects/node-cpp-skel/mason_packages/.link/bin/ld: Release/obj.target/module/src/object_async/hello_async.o: plugin needed to handle lto object
  rm -rf "Release/module.node" && cp -af "/home/artem/projects/node-cpp-skel/lib/binding/module.node" "Release/module.node"
make[1]: Leaving directory '/home/artem/projects/node-cpp-skel/build'
artemp commented 6 years ago

CXX=/usr/bin/g++ LINK=/usr/bin/g++ make

works!

CXX=/usr/bin/clang++ LINK=/usr/bin/clang make

/usr/bin/ld: /opt/llvm/bin/../lib/LLVMgold.so: error loading plugin: /opt/llvm/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory
clang-7.0: error: linker command failed with exit code 1 (use -v to see invocation)
module.target.mk:167: recipe for target '/home/artem/projects/node-cpp-skel/lib/binding/module.node' failed
make[1]: *** [/home/artem/projects/node-cpp-skel/lib/binding/module.node] Error 1
make[1]: Leaving directory '/home/artem/projects/node-cpp-skel/build'