mscdex / mmmagic

An async libmagic binding for node.js for detecting content types by data inspection
MIT License
621 stars 50 forks source link

Node 20 Compile Issues #169

Open jack828 opened 1 year ago

jack828 commented 1 year ago

Hello, I am trying to upgrade a project that uses mmmagic to node 20.

The following compile issues occur:

➜ yarn                                                                                                                                                                                                                                                          
yarn install v1.22.19                                                                                                                                                                                                                                           
[1/4] Resolving packages...                                                                                                                                                                                                                                     
[2/4] Fetching packages...                                                                                                                                                                                                                                      
[3/4] Linking dependencies...                                                                                                                                                                                                                                   
[4/4] Building fresh packages...                                                                                                                                                                                                                                
[1/3] ⠐ sharp                                                                                                                                                                                                                                                   
[2/3] ⠐ mmmagic                                                                                                                                                                                                                                                 
error /home/jack/project/node_modules/mmmagic: Command failed.                                                                                                                                                                                       
Exit code: 1                                                                                                                                                                                                                                                    
Command: node-gyp rebuild                                                                                                                                                                                                                                       
Arguments:                                                                                                                                                                                                                                                      
Directory: /home/jack/project/node_modules/mmmagic                                                                                                                                                                                                   
Output:                                                                                                                                                                                                                                                         
gyp info it worked if it ends with ok                                                                                                                                                                                                                           
gyp info using node-gyp@9.3.1                                                                                                                                                                                                                                   
gyp info using node@20.1.0 | linux | x64                                                                                                                                                                                                                        
gyp info find Python using Python version 3.10.6 found at "/usr/bin/python3"                                                                                                                                                                                    
gyp http GET https://nodejs.org/download/release/v20.1.0/node-v20.1.0-headers.tar.gz                                                                                                                                                                            
gyp http 200 https://nodejs.org/download/release/v20.1.0/node-v20.1.0-headers.tar.gz                                                                                                                                                                            
gyp http GET https://nodejs.org/download/release/v20.1.0/SHASUMS256.txt                                                                                                                                                                                         
gyp http 200 https://nodejs.org/download/release/v20.1.0/SHASUMS256.txt                                                                                                                                                                                         
gyp info spawn /usr/bin/python3                                                                                                                                                                                                                                 
gyp info spawn args [                                                                                                                                                                                                                                           
gyp info spawn args   '/home/jack/.nave/installed/20.1.0/lib/node_modules/npm/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   '/home/jack/project/node_modules/mmmagic/build/config.gypi',                                                                                                                                                                   
gyp info spawn args   '-I',                                                                                                                                                                                                                                     
gyp info spawn args   '/home/jack/.nave/installed/20.1.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',                                                                                                                                                
gyp info spawn args   '-I',                                                                                                                                                                                                                                     
gyp info spawn args   '/home/jack/.cache/node-gyp/20.1.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=/home/jack/.cache/node-gyp/20.1.0',                                                                                                                                                                                      
gyp info spawn args   '-Dnode_gyp_dir=/home/jack/.nave/installed/20.1.0/lib/node_modules/npm/node_modules/node-gyp',                                                                                                                                            
gyp info spawn args   '-Dnode_lib_file=/home/jack/.cache/node-gyp/20.1.0/<(target_arch)/node.lib',                                                                                                                                                              
gyp info spawn args   '-Dmodule_root_dir=/home/jack/project/node_modules/mmmagic',                                                                                                                                                                   
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 args ]                                                                                                                                                                                                                                           
gyp info spawn make                                                                                                                                                                                                                                             
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/home/jack/project/node_modules/mmmagic/build'                                                                                                                                                                             
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/apprentice.o                                                                                                                                                                                         
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/apptype.o                                                                                                                                                                                            
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/ascmagic.o                                                                                                                                                                                           
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/cdf.o                                                                                                                                                                                                
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/cdf_time.o                                                                                                                                                                                           
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/compress.o                                                                                                                                                                                           
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/der.o                                                                                                                                                                                                
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/encoding.o                                                                                                                                                                                           
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/fsmagic.o                                                                                                                                                                                            
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/funcs.o                                                                                                                                                                                              
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/is_tar.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/magic.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/print.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/readcdf.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/readelf.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/softmagic.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/fmtcheck.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/strlcat.o
  CC(target) Release/obj.target/libmagic/deps/libmagic/src/strlcpy.o
rm -f Release/obj.target/deps/libmagic/magic.a Release/obj.target/deps/libmagic/magic.a.ar-file-list; mkdir -p `dirname Release/obj.target/deps/libmagic/magic.a`
ar crs Release/obj.target/deps/libmagic/magic.a @Release/obj.target/deps/libmagic/magic.a.ar-file-list
  COPY Release/magic.a
  CXX(target) Release/obj.target/magic/src/binding.o
In file included from ../../nan/nan.h:176,
                 from ../src/binding.cc:3:
../../nan/nan_callbacks.h:55:23: error: ‘AccessorSignature’ is not a member of ‘v8’
   55 | typedef v8::Local<v8::AccessorSignature> Sig;
      |                       ^~~~~~~~~~~~~~~~~
../../nan/nan_callbacks.h:55:40: error: template argument 1 is invalid
   55 | typedef v8::Local<v8::AccessorSignature> Sig;
      |                                        ^
In file included from ../src/binding.cc:3:
../../nan/nan.h: In function ‘bool Nan::IdleNotification(int)’:
../../nan/nan.h:682:63: warning: ‘bool v8::Isolate::IdleNotificationDeadline(double)’ is deprecated: Use MemoryPressureNotification() to influence the GC schedule. [-Wdeprecated-declarations]
  682 |     return v8::Isolate::GetCurrent()->IdleNotificationDeadline(
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
  683 |         idle_time_in_ms * 0.001);
      |         ~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/jack/.cache/node-gyp/20.1.0/include/node/v8-initialization.h:13,
                 from /home/jack/.cache/node-gyp/20.1.0/include/node/v8.h:34,
                 from /home/jack/.cache/node-gyp/20.1.0/include/node/node.h:73,
                 from ../src/binding.cc:1:
/home/jack/.cache/node-gyp/20.1.0/include/node/v8-isolate.h:1293:8: note: declared here
 1293 |   bool IdleNotificationDeadline(double deadline_in_seconds);
      |        ^~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../src/binding.cc:3:
../../nan/nan.h: In function ‘void Nan::SetAccessor(v8::Local<v8::ObjectTemplate>, v8::Local<v8::String>, Nan::GetterCallback, Nan::SetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyAttribute, Nan::imp::Sig)’:
../../nan/nan.h:2542:19: error: no matching function for call to ‘v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>&, void (*&)(v8::Local<v8::Name>, const v8::PropertyCallbackInfo<v8::Value>&), void (*&)(v8::Local<v8::Name>, v8::Local<v8::Value>, const
 v8::PropertyCallbackInfo<void>&), v8::Local<v8::Object>&, v8::AccessControl&, v8::PropertyAttribute&, Nan::imp::Sig&)’
 2542 |   tpl->SetAccessor(
      |   ~~~~~~~~~~~~~~~~^
 2543 |       name
      |       ~~~~
 2544 |     , getter_
      |     ~~~~~~~~~
 2545 |     , setter_
      |     ~~~~~~~~~
 2546 |     , obj
      |     ~~~~~
 2547 |     , settings
      |     ~~~~~~~~~~
 2548 |     , attribute
      |     ~~~~~~~~~~~
 2549 |     , signature);
      |     ~~~~~~~~~~~~
In file included from /home/jack/.cache/node-gyp/20.1.0/include/node/v8-function.h:15,
                 from /home/jack/.cache/node-gyp/20.1.0/include/node/v8.h:33,
                 from /home/jack/.cache/node-gyp/20.1.0/include/node/node.h:73,
                 from ../src/binding.cc:1:
/home/jack/.cache/node-gyp/20.1.0/include/node/v8-template.h:809:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::String>, v8::AccessorGetterCallback, v8::AccessorSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::PropertyA
ttribute, v8::SideEffectType, v8::SideEffectType)’
  809 |   void SetAccessor(
      |        ^~~~~~~~~~~
/home/jack/.cache/node-gyp/20.1.0/include/node/v8-template.h:814:22: note:   no known conversion for argument 7 from ‘Nan::imp::Sig’ {aka ‘int’} to ‘v8::SideEffectType’
  814 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jack/.cache/node-gyp/20.1.0/include/node/v8-template.h:816:8: note: candidate: ‘void v8::ObjectTemplate::SetAccessor(v8::Local<v8::Name>, v8::AccessorNameGetterCallback, v8::AccessorNameSetterCallback, v8::Local<v8::Value>, v8::AccessControl, v8::Pro
pertyAttribute, v8::SideEffectType, v8::SideEffectType)’
  816 |   void SetAccessor(
      |        ^~~~~~~~~~~
/home/jack/.cache/node-gyp/20.1.0/include/node/v8-template.h:821:22: note:   no known conversion for argument 7 from ‘Nan::imp::Sig’ {aka ‘int’} to ‘v8::SideEffectType’
  821 |       SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect,
      |       ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/binding.cc: In static member function ‘static void Magic::DetectFile(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/binding.cc:184:34: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
  184 |                                  (uv_after_work_cb)Magic::DetectAfter);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/binding.cc: In static member function ‘static void Magic::Detect(const Nan::FunctionCallbackInfo<v8::Value>&)’:
../src/binding.cc:217:34: warning: cast between incompatible function types from ‘void (*)(uv_work_t*)’ {aka ‘void (*)(uv_work_s*)’} to ‘uv_after_work_cb’ {aka ‘void (*)(uv_work_s*, int)’} [-Wcast-function-type]
  217 |                                  (uv_after_work_cb)Magic::DetectAfter);
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../src/binding.cc:1:
../src/binding.cc: At global scope:
/home/jack/.cache/node-gyp/20.1.0/include/node/node.h:1153:7: warning: cast between incompatible function types from ‘void (*)(v8::Local<v8::Object>)’ to ‘node::addon_register_func’ {aka ‘void (*)(v8::Local<v8::Object>, v8::Local<v8::Value>, void*)’} [-Wca
st-function-type]
 1153 |       (node::addon_register_func) (regfunc),                          \
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/jack/.cache/node-gyp/20.1.0/include/node/node.h:1187:3: note: in expansion of macro ‘NODE_MODULE_X’
 1187 |   NODE_MODULE_X(modname, regfunc, NULL, 0)  // NOLINT (readability/null_usage)
      |   ^~~~~~~~~~~~~
../src/binding.cc:415:3: note: in expansion of macro ‘NODE_MODULE’
  415 |   NODE_MODULE(magic, init);
      |   ^~~~~~~~~~~
make: *** [magic.target.mk:124: Release/obj.target/magic/src/binding.o] Error 1
make: Leaving directory '/home/jack/project/node_modules/mmmagic/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/jack/.nave/installed/20.1.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:203:23)
gyp ERR! stack     at ChildProcess.emit (node:events:511:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:293:12)
gyp ERR! System Linux 5.15.0-71-generic
gyp ERR! command "/home/jack/.nave/installed/20.1.0/bin/node" "/home/jack/.nave/installed/20.1.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/jack/project/node_modules/mmmagic
gyp ERR! node -v v20.1.0
gyp ERR! node-gyp -v v9.3.1
mscdex commented 1 year ago

As far as I know the latest version of nan should be node v20.x compatible.

garaboncias commented 1 year ago

true update nan to 2.17 solve the issue

amit777 commented 1 year ago

Apologies, I ran into this issue, but it's not clear what you mean by update non to 2.17? Where would I do this?

garaboncias commented 1 year ago

actually in package.json we add an override node-gyp version :

"resolutions": {
    "node-gyp": "9.4.0"
  },

but since then we move forward to @picturae/mmmagic to fix an other issue too.

amit777 commented 11 months ago

so I was able to install @picturae/mmmagic without issue.. the weird thing is that it looks like exactly the same code base as the default mmmagic in this repo.

jonmaim commented 9 months ago

In @picturae/mmmagic node-20 branch has to be selected: https://github.com/picturae/mmmagic/commit/eb0091adae967e55bc57b865f72479ae43290696

flowluap commented 8 months ago

Thanks @jonmaim!

We adoped the following changes via pnpm patch:

package.json

"nan": "^2.17.0"

binding.gyp

'MACOSX_DEPLOYMENT_TARGET': '10.15',
'CLANG_CXX_LANGUAGE_STANDARD': 'c++17',  # -std=gnu++1y

those changes came from this commit: https://github.com/mscdex/mmmagic/commit/35978fb29faa3848651e417537b87b4463061f81#diff-7ae45ad102eab3b6d7e7896acd08c427a9b25b346470d7bc6507b6481575d519

We plan to stay with @mscdex / mmmagic, so it would be nice to have those changes merged, when verified no other conflicts occur.

Edit: It already has an pr: https://github.com/mscdex/mmmagic/pull/171

dthornley commented 5 months ago

I've just updated the @picturae/mmmagic package to support node 22 as well. It's now all in the master branch, but I've left the node-20 branch for now. An updated scoped version (@picturae/mmmagic) has also been published to npm.org (v0.5.5)

ZachMilne commented 3 months ago

@dthornley Thank you. @picturae/mmmagic solve our issues with installation on node 20 (mac)