Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

n-api,doc: add info about building n-api addons #30032

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions doc/api/n-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,89 @@ must make use exclusively of N-API by restricting itself to using
and by checking, for all external libraries that it uses, that the external
library makes ABI stability guarantees similar to N-API.

## Building

Unlike addons coded in JavaScript, developing and deploying Node native
jschlight marked this conversation as resolved.
Show resolved Hide resolved
addons using N-API requires an additional set of tools. Besides the basic
tools required to develop for Node, the native addon developer requires a
jschlight marked this conversation as resolved.
Show resolved Hide resolved
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.

For Linux developers, the necessary C/C++ toolchain is typically already
installed. For systems lacking the necessary toolchain, the
jschlight marked this conversation as resolved.
Show resolved Hide resolved
[LLVM](https://llvm.org) compiler infrastructure is a good choice.

For Mac developers, [Xcode](https://developer.apple.com/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:

```bash
xcode-select --install
```

For Windows developers, [Visual Studio](https://visualstudio.microsoft.com)
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:

```bash
npm install --global --production windows-build-tools
```

The sections below describe the additional tools available for developing
and deploying Node native addons.
jschlight marked this conversation as resolved.
Show resolved Hide resolved

### Build tools

> Both the tools listed here require that *users* of the native
> addon have a C/C++ toolchain installed in order to successfully install
> the native addon.
jschlight marked this conversation as resolved.
Show resolved Hide resolved

#### node-gyp

[node-gyp](https://github.com/nodejs/node-gyp) is a build system based on
Google's [GYP](https://gyp.gsrc.io) tool and comes bundled with npm. GYP,
and therefore node-gyp, requires that Python be installed.

Historically, node-gyp has been the tool of choice for building native
addons. However, Google has stopped development on GYP and some developers
are concerned about the dependency of some GYP versions on Python 2.7 which
has a sunset date of 2020.
jschlight marked this conversation as resolved.
Show resolved Hide resolved

#### CMake.js

[CMake.js](https://github.com/cmake-js/cmake-js) is an alternative build
jschlight marked this conversation as resolved.
Show resolved Hide resolved
system based on [CMake](https://cmake.org).

CMake.js is a good choice for projects that already use CMake or for
developers affected by limitations in node-gyp.

### Uploading precompiled binaries

The two tools listed here permit native addon developers and maintainers to
create and upload binaries to public or private servers. These tools are
typically integrated with CI/CD build systems like
[Travis CI](https://travis-ci.org) and [AppVeyor](https://www.appveyor.com)
to build and upload binaries for a variety of platforms and architectures.
These binaries are then available for download by users who do not need to
have a C/C++ toolchain installed.

#### node-pre-gyp

[node-pre-gyp](https://github.com/mapbox/node-pre-gyp) is a tool based on
node-gyp that adds the ability to upload binaries to a server of the
developer's choice. node-pre-gyp has particularly good support for
uploading binaries to Amazon S3.

#### prebuild

[prebuild](https://github.com/prebuild/prebuild) is a tool that supports
builds using either node-gyp or CMake.js. Unlike node-pre-gyp which
supports a variety of servers, prebuild uploads binaries only to
[GitHub releases](https://github.com/prebuild/prebuild). prebuild is a
jschlight marked this conversation as resolved.
Show resolved Hide resolved
good choice for GitHub projects using CMake.js.

jschlight marked this conversation as resolved.
Show resolved Hide resolved
## Usage

In order to use the N-API functions, include the file
Expand Down