构建


¥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++ 工具链包很容易获得。GCC 在 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.