node-gyp:在所有子目录中运行 binding.gyp

JeB*_*JeB 0 recursion native compilation node.js node-gyp

我正在开发一个大型node.js项目,其中还包括几个本机库。
为了在 JavaScript 中使用这些库,我使用node-gyp.node将它们编译为节点插件 ( ) 。

我想从根目录运行一次node-gypbinding.gyp以递归地编译所有可用的文件(在所有子目录中)。

有什么办法可以做到这一点吗?

pme*_*med 5

GYP 允许为目标设置依赖项列表。type: none您可以在顶层创建一个目标bindings.gyp并列出子目录中的依赖项:

{
    'targets': [
        {
            'target_name': 'build_all',
            'type': 'none',
            'dependencies': ['subdir1/bindings.gyp:*', 'subdir/subdir2/bindings.gyp:*'],
            # or generate dependencies list with a command expansion
            'dependencies': ['<!@(find -mindepth 2 -name binding.gyp | sed -e s/$/:*/)'],
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

这将编译所有依赖项并将它们放入build/根目录中。
要将每个插件放入其相应的目录中,请postbuild在插件的内部添加一个目标binding.gyp:

{
  "targets": [
    {
      "target_name": "my-target",
      "sources": [ "example.cpp" ]      
    },      
    {
      "target_name": "action_after_build",
      "type": "none",
      "dependencies": [ "my-target" ],
      "copies": [
        {
          "files": [ "<(PRODUCT_DIR)/my-target.node" ],
          "destination": "."
        }
      ]
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)