@@ -14,11 +14,10 @@ changes in the underlying JavaScript engine and allow modules
1414compiled for one major version to run on later major versions of Node.js without
1515recompilation. The [ABI Stability][] guide provides a more in-depth explanation.
1616
17- Addons are built/packaged with the same approach/tools
18- outlined in the section titled [C++ Addons](addons.html).
19- The only difference is the set of APIs that are used by the native code.
20- Instead of using the V8 or [Native Abstractions for Node.js][] APIs,
21- the functions available in the N-API are used.
17+ Addons are built/packaged with the same approach/tools outlined in the section
18+ titled [C++ Addons][]. The only difference is the set of APIs that are used by
19+ the native code. Instead of using the V8 or [Native Abstractions for Node.js][]
20+ APIs, the functions available in the N-API are used.
2221
2322APIs exposed by N-API are generally used to create and manipulate
2423JavaScript values. Concepts and operations generally map to ideas specified
@@ -76,8 +75,7 @@ if (status != napi_ok) {
7675The end result is that the addon only uses the exported C APIs. As a result,
7776it still gets the benefits of the ABI stability provided by the C API.
7877
79- When using `node-addon-api` instead of the C APIs, start with the API
80- [docs](https://github.com/nodejs/node-addon-api#api-documentation)
78+ When using `node-addon-api` instead of the C APIs, start with the API [docs][]
8179for `node-addon-api`.
8280
8381## Implications of ABI Stability
@@ -118,11 +116,95 @@ must make use exclusively of N-API by restricting itself to using
118116and by checking, for all external libraries that it uses, that the external
119117library makes ABI stability guarantees similar to N-API.
120118
119+ ## Building
120+
121+ Unlike modules written in JavaScript, developing and deploying Node.js
122+ native addons using N-API requires an additional set of tools. Besides the
123+ basic tools required to develop for Node.js, the native addon developer
124+ requires a toolchain that can compile C and C++ code into a binary. In
125+ addition, depending upon how the native addon is deployed, the *user* of
126+ the native addon will also need to have a C/C++ toolchain installed.
127+
128+ For Linux developers, the necessary C/C++ toolchain packages are readily
129+ available. [GCC][] is widely used in the Node.js community to build and
130+ test across a variety of plarforms. For many developers, the [LLVM][]
131+ compiler infrastructure is also a good choice.
132+
133+ For Mac developers, [Xcode][] offers all the required compiler tools.
134+ However, it is not necessary to install the entire Xcode IDE. The following
135+ command installs the necessary toolchain:
136+
137+ ```bash
138+ xcode-select --install
139+ ```
140+
141+ For Windows developers, [Visual Studio][] offers all the required compiler
142+ tools. However, it is not necessary to install the entire Visual Studio
143+ IDE. The following command installs the necessary toolchain:
144+
145+ ```bash
146+ npm install --global --production windows-build-tools
147+ ```
148+
149+ The sections below describe the additional tools available for developing
150+ and deploying Node.js native addons.
151+
152+ ### Build tools
153+
154+ Both the tools listed here require that *users* of the native
155+ addon have a C/C++ toolchain installed in order to successfully install
156+ the native addon.
157+
158+ #### node-gyp
159+
160+ [node-gyp][] is a build system based on Google's [GYP][] tool and comes
161+ bundled with npm. GYP, and therefore node-gyp, requires that Python be
162+ installed.
163+
164+ Historically, node-gyp has been the tool of choice for building native
165+ addons. It has widespread adoption and documentation. However, some
166+ developers have run into limitations in node-gyp.
167+
168+ #### CMake.js
169+
170+ [CMake.js][] is an alternative build system based on [CMake][].
171+
172+ CMake.js is a good choice for projects that already use CMake or for
173+ developers affected by limitations in node-gyp.
174+
175+ ### Uploading precompiled binaries
176+
177+ The three tools listed here permit native addon developers and maintainers
178+ to create and upload binaries to public or private servers. These tools are
179+ typically integrated with CI/CD build systems like [Travis CI][] and
180+ [AppVeyor][] to build and upload binaries for a variety of platforms and
181+ architectures. These binaries are then available for download by users who
182+ do not need to have a C/C++ toolchain installed.
183+
184+ #### node-pre-gyp
185+
186+ [node-pre-gyp][] is a tool based on node-gyp that adds the ability to
187+ upload binaries to a server of the developer's choice. node-pre-gyp has
188+ particularly good support for uploading binaries to Amazon S3.
189+
190+ #### prebuild
191+
192+ [prebuild][] is a tool that supports builds using either node-gyp or
193+ CMake.js. Unlike node-pre-gyp which supports a variety of servers, prebuild
194+ uploads binaries only to [GitHub releases][]. prebuild is a good choice for
195+ GitHub projects using CMake.js.
196+
197+ #### prebuildify
198+
199+ [prebuildify][] is tool based on node-gyp. The advantage of prebuildify is
200+ that the built binaries are bundled with the native module when it's
201+ uploaded to npm. The binaries are downloaded from npm and are immediately
202+ available to the module user when the native module is installed.
203+
121204## Usage
122205
123- In order to use the N-API functions, include the file
124- [`node_api.h`](https://github.com/nodejs/node/blob/master/src/node_api.h)
125- which is located in the src directory in the node development tree:
206+ In order to use the N-API functions, include the file [`node_api.h`][] which is
207+ located in the src directory in the node development tree:
126208
127209```C
128210#include <node_api.h>
@@ -5195,3 +5277,20 @@ This API may only be called from the main thread.
51955277[context-aware addons]: addons.html#addons_context_aware_addons
51965278[node-addon-api]: https://github.com/nodejs/node-addon-api
51975279[worker threads]: https://nodejs.org/api/worker_threads.html
5280+ [C++ Addons]: addons.html
5281+ [docs]: https://github.com/nodejs/node-addon-api#api-documentation
5282+ [GCC]: https://gcc.gnu.org
5283+ [LLVM]: https://llvm.org
5284+ [Xcode]: https://developer.apple.com/xcode/
5285+ [Visual Studio]: https://visualstudio.microsoft.com
5286+ [node-gyp]: https://github.com/nodejs/node-gyp
5287+ [GYP]: https://gyp.gsrc.io
5288+ [CMake.js]: https://github.com/cmake-js/cmake-js
5289+ [CMake]: https://cmake.org
5290+ [Travis CI]: https://travis-ci.org
5291+ [AppVeyor]: https://www.appveyor.com
5292+ [node-pre-gyp]: https://github.com/mapbox/node-pre-gyp
5293+ [prebuild]: https://github.com/prebuild/prebuild
5294+ [GitHub releases]: https://help.github.com/en/github/administering-a-repository/about-releases
5295+ [prebuildify]: https://github.com/prebuild/prebuildify
5296+ [`node_api.h`]: https://github.com/nodejs/node/blob/master/src/node_api.h
0 commit comments