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

标签 node.js recursion compilation native node-gyp

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

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

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

最佳答案

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

{
    '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/$/:*/)'],
        }
    ]
}

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

{
  "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": "."
        }
      ]
    }
  ]
}

关于node.js - node-gyp:在所有子目录中运行 binding.gyp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38693619/

相关文章:

c++ - 如何判断 `constexpr`是否在编译时求值(无需人工检查)

node.js - npm安装Mongoose Kerberos报错gss_acquire_cred_impersonate_name

javascript - 删除有条件的重复元素

node.js - 如何在 krakenjs 中使用中间件来实现特定路由?

python - 递归函数后获取数据列表

python - 递归如何跟踪答案?

java - 为什么在空引用上调用方法可以成功编译?

node.js - 火狐插件错误: Module `http` is not found

c++ - 递归 -> 迭代

compilation - 简单的 Ada 程序,输出错误