Node-gyp: Overriding default flags in common.gypi

Created on 7 Jan 2017  路  7Comments  路  Source: nodejs/node-gyp

I have a case where I'd like to disable all multi-process builds on windows. Basically I'm wondering if there is a way to negate this msbuild flag /MP on the build machine machine wide.
I took a look at #26 but that seems to be for package developers, rather than as a build step after the fact, please correct me if I'm wrong.
so are there any flags, env vars, configuration files, command line argument, etc that I can set to override that either globally on the machine or when installing any npm packages?

Most helpful comment

FYI: GYP allows for removing items from list with the ! suffix, so the following msvs_settings block removes the /MP:

{
  'targets': [
    {
      'target_name': 'binding',
      'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
      'sources': [ 'binding.cc' ],
      'msvs_settings': {
        'VCCLCompilerTool': {
          'AdditionalOptions!': [
            '/MP'
          ]
        }
      }
    }
  ]
}

or using the = suffix:

...
'msvs_settings': { 'VCCLCompilerTool': { 
  'AdditionalOptions=': []
} }
...

All 7 comments

I think the answer is no. node-gyp doesn't set /MP itself, it inherits it from node's common.gypi. As a workaround:

  1. Download or check out the node source code to $nodedir
  2. Remove the /MP switch from $nodedir/common.gypi
  3. Build your add-on with node-gyp rebuild --nodedir=$nodedir (or pass the switch to npm install.)

Got it. One last question, would that be the same if I wanted to change DebugInformationFormat as well?

You might be able to override that with a 'msvs_settings': { 'VCCLCompilerTool': { ... } } section in your binding.gyp.

If that works for you, you could file an issue with nodejs/node requesting that node switches over to 'MultiProcessorCompilation': 'true'. The /MP switch is set through 'AdditionalOptions': [ '/MP' ] now and that is additive, I think, not overridable.

sounds good. Thank you for the help!

As a follow-up to this:

I am finding that adding MultiProcessorCompilation in the msvs_settings section of binding.gyp has no impact on the /MP that is getting written into AdditionalOptions. This value comes from the default values in common.gypi and I think the only way to get rid of it is from there.

Interestingly, I find in the file nodejs\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\msvs_emulation.py that there is some effort to filter out /MP:

    # ninja handles parallelism by itself, don't have the compiler do it too.
    cflags = filter(lambda x: not x.startswith('/MP'), cflags)
    return cflags

I think this needs to be removed from common.gypi as it makes the MultiProcessorCompilation setting in msvs_settings useless.

FYI: GYP allows for removing items from list with the ! suffix, so the following msvs_settings block removes the /MP:

{
  'targets': [
    {
      'target_name': 'binding',
      'defines': [ 'V8_DEPRECATION_WARNINGS=1' ],
      'sources': [ 'binding.cc' ],
      'msvs_settings': {
        'VCCLCompilerTool': {
          'AdditionalOptions!': [
            '/MP'
          ]
        }
      }
    }
  ]
}

or using the = suffix:

...
'msvs_settings': { 'VCCLCompilerTool': { 
  'AdditionalOptions=': []
} }
...

@refack I'm not being able to remove the /MP flag from my builds, here is my binding.gyp:

{
    "targets": [{
        "target_name": "testaddon",
        "cflags!": [ "-fno-exceptions" ],
        "cflags_cc!": [ "-fno-exceptions" ],
        "sources": [
            "cppsrc/main.cpp",
            "cppsrc/Samples/functionexample.cpp",
            "cppsrc/Samples/actualclass.cpp",
            "cppsrc/Samples/classexample.cpp"
        ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'AdditionalOptions!': [
              '/MP'
            ]
          }
        },
        'include_dirs': [
            "<!@(node -p \"require('node-addon-api').include\")"
        ],
        'libraries': [],
        'dependencies': [
            "<!(node -p \"require('node-addon-api').gyp\")"
        ],
        'defines': [ 'NAPI_DISABLE_CPP_EXCEPTIONS' ]
    }]
}

Build output:

npm run build                                                                                                                                    
> [email protected] build E:\Documentos\Proyectos Personales\Mios\aura-sdk
> node-gyp rebuild


E:\Documentos\Proyectos Personales\Mios\aura-sdk>if not defined npm_config_node_gyp (node "C:\Users\danie\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\danie\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Los proyectos de esta soluci贸n se van a compilar de uno en uno. Para habilitar la compilaci贸n en paralelo, agregue el modificador "/m".
  nothing.vcxproj -> E:\Documentos\Proyectos Personales\Mios\aura-sdk\build\Release\\nothing.lib
  main.cpp
  functionexample.cpp
  actualclass.cpp
  classexample.cpp
  win_delay_load_hook.cc
e:\documentos\proyectos personales\mios\aura-sdk\cppsrc\samples\actualclass.h(1): error C2813: #import is not supported with /MP (compiling source file ..\cppsrc\Samples\actualclass.cpp) [E:\Documentos\Proyectos Personales
\Mios\aura-sdk\build\testaddon.vcxproj]
Was this page helpful?
0 / 5 - 0 ratings