构建
【Building】
与使用 JavaScript 编写的模块不同,使用 Node-API 开发和部署 Node.js 原生插件需要额外的一套工具。除了开发 Node.js 所需的基本工具外,原生插件开发者还需要一套能够将 C 和 C++ 代码编译为二进制文件的工具链。此外,根据原生插件的部署方式,原生插件的用户也可能需要安装 C/C++ 工具链。
【Unlike modules written in JavaScript, developing and deploying Node.js native addons using Node-API requires an additional set of tools. Besides the basic tools required to develop for Node.js, the native addon developer requires a toolchain that can compile C and C++ code into a binary. In addition, depending upon how the native addon is deployed, the user of the native addon will also need to have a C/C++ toolchain installed.】
对于 Linux 开发者来说,所需的 C/C++ 工具链包很容易获取。海湾阿拉伯国家合作委员会 在 Node.js 社区中被广泛用于在各种平台上构建和测试。对于许多开发者来说,LLVM 编译器基础设施也是一个不错的选择。
【For Linux developers, the necessary C/C++ toolchain packages are readily available. GCC is widely used in the Node.js community to build and test across a variety of platforms. For many developers, the LLVM compiler infrastructure is also a good choice.】
对于 Mac 开发者,Xcode 提供了所有所需的编译器工具。然而,并不需要安装完整的 Xcode IDE。以下命令会安装所需的工具链:
【For Mac developers, Xcode offers all the required compiler tools. However, it is not necessary to install the entire Xcode IDE. The following command installs the necessary toolchain:】
xcode-select --install 对于 Windows 开发者,Visual Studio 提供了所有必需的编译工具。然而,并不需要安装完整的 Visual Studio IDE。以下命令会安装所需的工具链:
【For Windows developers, Visual Studio offers all the required compiler tools. However, it is not necessary to install the entire Visual Studio IDE. The following command installs the necessary toolchain:】
npm install --global windows-build-tools 下面的各节描述了用于开发和部署 Node.js 原生插件的额外工具。
【The sections below describe the additional tools available for developing and deploying Node.js native addons.】