简体   繁体   English

nodejs:如何使用较新的openssl编译grpc?

[英]nodejs : how to compile grpc with newer openssl?

I would like to compile grpc with newer openssl( >= 1.1.0 ) in nodejs project, but I have no idea how to get along with it. 我想在nodejs项目中用较新的openssl(> = 1.1.0)编译grpc,但是我不知道如何与它相处。

Here is the package.json in the whole project. 这是整个项目中的package.json

{
    "name": "fabcar",
    "version": "1.0.0",
    "description": "FabCar application implemented in JavaScript",
    "engines": {
        "node": ">=8",
        "npm": ">=5"
    },
    "scripts": {
        "lint": "eslint .",
        "pretest": "npm run lint",
        "test": "nyc mocha --recursive"
    },
    "engineStrict": true,
    "author": "Hyperledger",
    "license": "Apache-2.0",
    "dependencies": {
        "fabric-ca-client": "~1.4.0",
        "fabric-network": "~1.4.0"
    },
    "devDependencies": {
        "chai": "^4.2.0",
        "eslint": "^5.9.0",
        "mocha": "^5.2.0",
        "nyc": "^13.1.0",
        "sinon": "^7.1.1",
        "sinon-chai": "^3.3.0"
    },
    "nyc": {
        "exclude": [
            "coverage/**",
            "test/**"
        ],
        "reporter": [
            "text-summary",
            "html"
        ],
        "all": true,
        "check-coverage": true,
        "statements": 100,
        "branches": 100,
        "functions": 100,
        "lines": 100
    }
}

And in this project, the fabrc-ca-client , fabric-network will uses grpc . 在这个项目中, fabrc-ca-clientfabric-network将使用grpc

here is some env: 这是一些环境:

$ npm version

{ npm: '6.4.1',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  napi: '4',
  nghttp2: '1.33.0',
  node: '8.16.0',
  openssl: '1.0.2r',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.23.2',
  v8: '6.2.414.77',
  zlib: '1.2.11' }

$ node -v
v8.16.0

Please help on compile grpc in nodejs with newer openssl(>=1.1.0) . compile grpc in nodejs with newer openssl(>=1.1.0)帮助在compile grpc in nodejs with newer openssl(>=1.1.0)

I am using Ubuntu 18.04 and only need to building on linux. 我正在使用Ubuntu 18.04,只需要在Linux上构建即可。

Any advice would be greatful! 任何建议将是巨大的!

Thanks! 谢谢!

There are three major obstacles to building grpc with a different OpenSSL library. 使用不同的OpenSSL库构建grpc存在三个主要障碍。 First, Node.js already exports the OpenSSL symbols for native modules to dynamically link against. 首先,Node.js已经导出了本机模块要动态链接的OpenSSL符号。 This means that you won't be able to dynamically link your own OpenSSL library; 这意味着您将无法动态链接自己的OpenSSL库。 it would cause symbol collision errors. 这会导致符号冲突错误。 You would need to statically link the library, and be sure to hide the symbols. 您需要静态链接库,并确保隐藏符号。 This can require either explicitly linking the relevant .a file if you already have one, or compiling the library from source as part of the build process. 这可能需要显式链接相关的.a文件(如果已存在),或者在构建过程中从源代码编译库。 This is not an issue when building for Windows or for Electron, so you should be able to get away with dynamically linking in those cases 对于Windows或Electron而言,这不是问题,因此在这种情况下,您应该能够摆脱动态链接的困扰

Second, the OpenSSL headers are included in the Node headers that are included by default when building native addons like grpc. 其次,OpenSSL标头包含在构建诸如grpc之类的本机插件时默认包含的Node标头中。 If you want to use your own version of OpenSSL, you will need to use your own headers for that version instead of those headers. 如果要使用自己的OpenSSL版本,则需要为该版本使用自己的标头,而不是那些标头。 We currently need to do this to use BoringSSL in the Windows library, so we have node-gyp download the headers, then we go in and delete the openssl directory, then build the library for real. 当前,我们需要执行此操作以在Windows库中使用BoringSSL,因此,我们必须先node-gyp下载标头,然后进入并删除openssl目录,然后构建真实库。 You will likely need to do that in this situation too. 在这种情况下,您可能也需要这样做。 This isn't an issue on Electron. 在Electron上这不是问题。

Third, grpc is written to use a variety of specific APIs in OpenSSL. 第三,grpc被编写为在OpenSSL中使用各种特定的API。 Depending on which other version you want to use, there is a chance that it will not be compatible. 根据您要使用的其他版本,它可能会不兼容。 I am not sure what the usable version range is here, but this is something to keep in mind. 我不确定这里可用的版本范围是什么,但是要记住这一点。

If you can solve all of these problems, you will need to make some significant edits to grpc's binding.gyp file to accomplish this. 如果你能解决所有这些问题,你将需要做出一些显著编辑GRPC的binding.gyp文件来实现这一点。 If you are building OpenSSL from source, the existing boringssl target should be a good template. 如果要从源代码构建OpenSSL,则现有的boringssl目标应该是一个很好的模板。 You can add a similar target for openssl and then have the grpc target depend on it. 您可以为openssl添加类似的目标,然后使grpc目标依赖于它。 If you already have a .a file, you should be able to add a linker flag to the grpc target to link it. 如果您已经有一个.a文件,则应该能够将链接器标志添加到grpc目标以进行链接。 In either case, make sure to remove references to other OpenSSL headers in various parts of the file. 无论哪种情况,请确保在文件的各个部分中删除对其他OpenSSL标头的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM