1
- node-gyp
2
- =========
3
- ## Node.js native addon build tool
1
+ # ` node-gyp ` - Node.js native addon build tool
4
2
5
3
` node-gyp ` is a cross-platform command-line tool written in Node.js for compiling
6
- native addon modules for Node.js. It bundles the [ gyp] ( https://gyp.gsrc.io )
4
+ native addon modules for Node.js. It bundles the [ gyp] ( https://gyp.gsrc.io )
7
5
project used by the Chromium team and takes away the pain of dealing with the
8
- various differences in build platforms. It is the replacement to the ` node-waf `
9
- program which is removed for node ` v0.8 ` . If you have a native addon for node that
10
- still has a ` wscript ` file, then you should definitely add a ` binding.gyp ` file
11
- to support the latest versions of node.
6
+ various differences in build platforms.
12
7
13
- Multiple target versions of node are supported (i.e. ` 0.8 ` , ..., ` 4 ` , ` 5 ` , ` 6 ` ,
14
- etc.), regardless of what version of node is actually installed on your system
8
+ Multiple target versions of Node.js are supported (i.e. ` 0.8 ` , ..., ` 4 ` , ` 5 ` , ` 6 ` ,
9
+ etc.), regardless of what version of Node.js is actually installed on your system
15
10
(` node-gyp ` downloads the necessary development files or headers for the target version).
16
11
17
12
## Features
18
13
19
14
* Easy to use, consistent interface
20
15
* Same commands to build your module on every platform
21
- * Supports multiple target versions of Node
16
+ * Supports multiple target versions of Node.js
22
17
23
-
24
- Installation
25
- ------------
18
+ ## Installation
26
19
27
20
You can install with ` npm ` :
28
21
@@ -80,16 +73,15 @@ version `node-gyp` uses by setting the '--python' variable:
80
73
$ node-gyp --python /path/to/python2.7
81
74
```
82
75
83
- If ` node-gyp ` is called by way of ` npm ` * and* you have multiple versions of
76
+ If ` node-gyp ` is called by way of ` npm ` , * and* you have multiple versions of
84
77
Python installed, then you can set ` npm ` 's 'python' config key to the appropriate
85
78
value:
86
79
87
80
``` bash
88
81
$ npm config set python /path/to/executable/python2.7
89
82
```
90
83
91
- How to Use
92
- ----------
84
+ ## How to Use
93
85
94
86
To compile your native addon, first go to its root directory:
95
87
@@ -110,33 +102,30 @@ needs to be added (not needed when run by npm as configured above):
110
102
$ node-gyp configure --msvs_version=2015
111
103
```
112
104
113
- __ Note__ : The ` configure ` step looks for the ` binding.gyp ` file in the current
114
- directory to process. See below for instructions on creating the ` binding.gyp ` file.
105
+ __ Note__ : The ` configure ` step looks for a ` binding.gyp ` file in the current
106
+ directory to process. See below for instructions on creating a ` binding.gyp ` file.
115
107
116
108
Now you will have either a ` Makefile ` (on Unix platforms) or a ` vcxproj ` file
117
- (on Windows) in the ` build/ ` directory. Next invoke the ` build ` command:
109
+ (on Windows) in the ` build/ ` directory. Next, invoke the ` build ` command:
118
110
119
111
``` bash
120
112
$ node-gyp build
121
113
```
122
114
123
115
Now you have your compiled ` .node ` bindings file! The compiled bindings end up
124
- in ` build/Debug/ ` or ` build/Release/ ` , depending on the build mode. At this point
125
- you can require the ` .node ` file with Node and run your tests!
116
+ in ` build/Debug/ ` or ` build/Release/ ` , depending on the build mode. At this point,
117
+ you can require the ` .node ` file with Node.js and run your tests!
126
118
127
119
__ Note:__ To create a _ Debug_ build of the bindings file, pass the ` --debug ` (or
128
- ` -d ` ) switch when running either the ` configure ` , ` build ` or ` rebuild ` command.
129
-
120
+ ` -d ` ) switch when running either the ` configure ` , ` build ` or ` rebuild ` commands.
130
121
131
- The "binding.gyp" file
132
- ----------------------
122
+ ## The ` binding.gyp ` file
133
123
134
- Previously when node had ` node-waf ` you had to write a ` wscript ` file. The
135
- replacement for that is the ` binding.gyp ` file, which describes the configuration
136
- to build your module in a JSON-like format. This file gets placed in the root of
137
- your package, alongside the ` package.json ` file.
124
+ A ` binding.gyp ` file describes the configuration to build your module, in a
125
+ JSON-like format. This file gets placed in the root of your package, alongside
126
+ ` package.json ` .
138
127
139
- A barebones ` gyp ` file appropriate for building a node addon looks like:
128
+ A barebones ` gyp ` file appropriate for building a Node.js addon could look like:
140
129
141
130
``` python
142
131
{
@@ -158,8 +147,7 @@ Some additional resources for addons and writing `gyp` files:
158
147
* [ * "binding.gyp" files out in the wild* wiki page] ( https://github.com/nodejs/node-gyp/wiki/%22binding.gyp%22-files-out-in-the-wild )
159
148
160
149
161
- Commands
162
- --------
150
+ ## Commands
163
151
164
152
` node-gyp ` responds to the following commands:
165
153
@@ -170,86 +158,74 @@ Commands
170
158
| ` clean ` | Removes the ` build ` directory if it exists
171
159
| ` configure ` | Generates project build files for the current platform
172
160
| ` rebuild ` | Runs ` clean ` , ` configure ` and ` build ` all in a row
173
- | ` install ` | Installs node header files for the given version
174
- | ` list ` | Lists the currently installed node header versions
175
- | ` remove ` | Removes the node header files for the given version
161
+ | ` install ` | Installs Node.js header files for the given version
162
+ | ` list ` | Lists the currently installed Node.js header versions
163
+ | ` remove ` | Removes the Node.js header files for the given version
176
164
177
165
178
- Command Options
179
- --------
166
+ ## Command Options
180
167
181
168
` node-gyp ` accepts the following command options:
182
169
183
170
| ** Command** | ** Description**
184
171
|:----------------------------------|:------------------------------------------
185
- | ` -j n ` , ` --jobs n ` | Run make in parallel
186
- | ` --target=v6.2.1 ` | Node version to build for (default= process.version)
172
+ | ` -j n ` , ` --jobs n ` | Run ` make ` in parallel
173
+ | ` --target=v6.2.1 ` | Node.js version to build for (default is ` process.version ` )
187
174
| ` --silly ` , ` --loglevel=silly ` | Log all progress to console
188
175
| ` --verbose ` , ` --loglevel=verbose ` | Log most progress to console
189
176
| ` --silent ` , ` --loglevel=silent ` | Don't log anything to console
190
- | ` debug ` , ` --debug ` | Make Debug build (default= Release)
177
+ | ` debug ` , ` --debug ` | Make Debug build (default is ` Release ` )
191
178
| ` --release ` , ` --no-debug ` | Make Release build
192
179
| ` -C $dir ` , ` --directory=$dir ` | Run command in different directory
193
- | ` --make=$make ` | Override make command (e.g. gmake)
180
+ | ` --make=$make ` | Override ` make ` command (e.g. ` gmake ` )
194
181
| ` --thin=yes ` | Enable thin static libraries
195
182
| ` --arch=$arch ` | Set target architecture (e.g. ia32)
196
183
| ` --tarball=$path ` | Get headers from a local tarball
197
- | ` --devdir=$path ` | SDK download directory (default= ~ /.node-gyp)
184
+ | ` --devdir=$path ` | SDK download directory (default is ` ~/.node-gyp ` )
198
185
| ` --ensure ` | Don't reinstall headers if already present
199
186
| ` --dist-url=$url ` | Download header tarball from custom URL
200
187
| ` --proxy=$url ` | Set HTTP proxy for downloading header tarball
201
188
| ` --cafile=$cafile ` | Override default CA chain (to download tarball)
202
189
| ` --nodedir=$path ` | Set the path to the node source code
203
- | ` --python=$path ` | Set path to the python (2) binary
204
- | ` --msvs_version=$version ` | Set Visual Studio version (win)
205
- | ` --solution=$solution ` | Set Visual Studio Solution version (win)
206
-
207
-
208
- Configuration
209
- --------
210
-
211
- __ ` node-gyp ` responds to environment variables or ` npm ` configuration__
212
- 1 . Environment variables take the form ` npm_config_OPTION_NAME ` for any of the
213
- options listed above (dashes in option names should be replaced by underscores).
214
- These work also when ` node-gyp ` is invoked directly:
215
- ` $ export npm_config_devdir=/tmp/.gyp `
216
- or on Windows
217
- ` > set npm_config_devdir=c:\temp\.gyp `
218
- 2 . As ` npm ` configuration, variables take the form ` OPTION_NAME ` .
219
- This way only works when ` node-gyp ` is executed by ` npm ` :
220
- ` $ npm config set [--global] devdir /tmp/.gyp `
221
- ` $ npm i buffertools `
222
-
223
-
224
-
225
- License
226
- -------
227
-
228
- (The MIT License)
229
-
230
- Copyright (c) 2012 Nathan Rajlich
< ; [email protected] > ;
231
-
232
- Permission is hereby granted, free of charge, to any person obtaining
233
- a copy of this software and associated documentation files (the
234
- 'Software'), to deal in the Software without restriction, including
235
- without limitation the rights to use, copy, modify, merge, publish,
236
- distribute, sublicense, and/or sell copies of the Software, and to
237
- permit persons to whom the Software is furnished to do so, subject to
238
- the following conditions:
239
-
240
- The above copyright notice and this permission notice shall be
241
- included in all copies or substantial portions of the Software.
242
-
243
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
244
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
245
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
246
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
247
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
248
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
249
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
250
-
251
-
252
- [ python-v2.7.10 ] : https://www.python.org/downloads/release/python-2710/
253
- [ msvc2013 ] : https://www.microsoft.com/en-gb/download/details.aspx?id=44914
254
- [ win7sdk ] : https://www.microsoft.com/en-us/download/details.aspx?id=8279
255
- [ compiler update for the Windows SDK 7.1 ] : https://www.microsoft.com/en-us/download/details.aspx?id=4422
190
+ | ` --python=$path ` | Set path to the Python 2 binary
191
+ | ` --msvs_version=$version ` | Set Visual Studio version (Windows only)
192
+ | ` --solution=$solution ` | Set Visual Studio Solution version (Windows only)
193
+
194
+ ## Configuration
195
+
196
+ ### Environment variables
197
+
198
+ Use the form ` npm_config_OPTION_NAME ` for any of the command options listed
199
+ above (dashes in option names should be replaced by underscores).
200
+
201
+ For example, to set ` devdir ` equal to ` /tmp/.gyp ` , you would:
202
+
203
+ Run this on Unix:
204
+
205
+ ``` bash
206
+ $ export npm_config_devdir=/tmp/.gyp
207
+ ```
208
+
209
+ Or this on Windows:
210
+
211
+ ``` console
212
+ > set npm_config_devdir=c:\t emp\. gyp
213
+ ```
214
+
215
+ ### ` npm ` configuration
216
+
217
+ Use the form ` OPTION_NAME ` for any of the command options listed above.
218
+
219
+ For example, to set ` devdir ` equal to ` /tmp/.gyp ` , you would run:
220
+
221
+ ``` bash
222
+ $ npm config set [--global] devdir /tmp/.gyp
223
+ ```
224
+
225
+ ** Note:** Configuration set via ` npm ` will only be used when ` node-gyp `
226
+ is run via ` npm ` , not when ` node-gyp ` is run directly.
227
+
228
+ ## License
229
+
230
+ ` node-gyp ` is available under the MIT license. See the [ LICENSE
231
+ file] ( LICENSE ) for details.
0 commit comments