doc(wiki): move wiki docs into doc/

This commit is contained in:
Rod Vagg 2021-06-21 14:36:18 +10:00
parent ee8e1c1e53
commit f0a48355d8
7 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,48 @@
This page contains links to some examples of existing `binding.gyp` files that other node modules are using. Take a look at them for inspiration.
To add to this page, just add the link to the project's `binding.gyp` file below:
* [ons](https://github.com/XadillaX/aliyun-ons/blob/master/binding.gyp)
* [thmclrx](https://github.com/XadillaX/thmclrx/blob/master/binding.gyp)
* [libxmljs](https://github.com/polotek/libxmljs/blob/master/binding.gyp)
* [node-buffertools](https://github.com/bnoordhuis/node-buffertools/blob/master/binding.gyp)
* [node-canvas](https://github.com/LearnBoost/node-canvas/blob/master/binding.gyp)
* [node-ffi](https://github.com/rbranson/node-ffi/blob/master/binding.gyp) + [libffi](https://github.com/rbranson/node-ffi/blob/master/deps/libffi/libffi.gyp)
* [node-time](https://github.com/TooTallNate/node-time/blob/master/binding.gyp)
* [node-sass](https://github.com/sass/node-sass/blob/master/binding.gyp) + [libsass](https://github.com/sass/node-sass/blob/master/src/libsass.gyp)
* [node-serialport](https://github.com/voodootikigod/node-serialport/blob/master/binding.gyp)
* [node-weak](https://github.com/TooTallNate/node-weak/blob/master/binding.gyp)
* [pty.js](https://github.com/chjj/pty.js/blob/master/binding.gyp)
* [ref](https://github.com/TooTallNate/ref/blob/master/binding.gyp)
* [appjs](https://github.com/milani/appjs/blob/master/binding.gyp)
* [nwm](https://github.com/mixu/nwm/blob/master/binding.gyp)
* [bcrypt](https://github.com/ncb000gt/node.bcrypt.js/blob/master/binding.gyp)
* [nk-mysql](https://github.com/mmod/nodamysql/blob/master/binding.gyp)
* [nk-xrm-installer](https://github.com/mmod/nk-xrm-installer/blob/master/binding.gyp) + [includable.gypi](https://github.com/mmod/nk-xrm-installer/blob/master/includable.gypi) + [unpack.py](https://github.com/mmod/nk-xrm-installer/blob/master/unpack.py) + [disburse.py](https://github.com/mmod/nk-xrm-installer/blob/master/disburse.py)
<sub>.py files above provide complete reference for examples of fetching source via http, extracting, and moving files.</sub>
* [node-memwatch](https://github.com/lloyd/node-memwatch/blob/master/binding.gyp)
* [node-ip2location](https://github.com/bolgovr/node-ip2location/blob/master/binding.gyp)
* [node-midi](https://github.com/justinlatimer/node-midi/blob/master/binding.gyp)
* [node-sqlite3](https://github.com/developmentseed/node-sqlite3/blob/master/binding.gyp) + [libsqlite3](https://github.com/developmentseed/node-sqlite3/blob/master/deps/sqlite3.gyp)
* [node-zipfile](https://github.com/mapbox/node-zipfile/blob/master/binding.gyp)
* [node-mapnik](https://github.com/mapnik/node-mapnik/blob/master/binding.gyp)
* [node-inotify](https://github.com/c4milo/node-inotify/blob/master/binding.gyp)
* [v8-profiler](https://github.com/c4milo/v8-profiler/blob/master/binding.gyp)
* [airtunes](https://github.com/radioline/node_airtunes/blob/master/binding.gyp)
* [node-fann](https://github.com/c4milo/node-fann/blob/master/binding.gyp)
* [node-talib](https://github.com/oransel/node-talib/blob/master/binding.gyp)
* [node-leveldown](https://github.com/rvagg/node-leveldown/blob/master/binding.gyp) + [leveldb.gyp](https://github.com/rvagg/node-leveldown/blob/master/deps/leveldb/leveldb.gyp) + [snappy.gyp](https://github.com/rvagg/node-leveldown/blob/master/deps/snappy/snappy.gyp)
* [node-expat](https://github.com/astro/node-expat/blob/master/binding.gyp) + [libexpat](https://github.com/astro/node-expat/blob/master/deps/libexpat/libexpat.gyp)
* [node-openvg-canvas](https://github.com/luismreis/node-openvg-canvas/blob/master/binding.gyp) + [node-openvg](https://github.com/luismreis/node-openvg/blob/master/binding.gyp)
* [node-cryptopp](https://github.com/BatikhSouri/node-cryptopp/blob/master/binding.gyp)
* [topcube](https://github.com/creationix/topcube/blob/master/binding.gyp)
* [node-osmium](https://github.com/osmcode/node-osmium/blob/master/binding.gyp)
* [node-osrm](https://github.com/DennisOSRM/node-osrm)
* [node-oracle](https://github.com/joeferner/node-oracle/blob/master/binding.gyp)
* [node-process-list](https://github.com/ReklatsMasters/node-process-list/blob/master/binding.gyp)
* [node-nanomsg](https://github.com/nickdesaulniers/node-nanomsg/blob/master/binding.gyp)
* [Ghostscript4JS](https://github.com/NickNaso/ghostscript4js/blob/master/binding.gyp)
* [nodecv](https://github.com/xudafeng/nodecv/blob/master/binding.gyp)
* [magick-cli](https://github.com/NickNaso/magick-cli/blob/master/binding.gyp)
* [sharp](https://github.com/lovell/sharp/blob/master/binding.gyp)
* [krb5](https://github.com/adaltas/node-krb5/blob/master/binding.gyp)

14
docs/Common-issues.md Normal file
View file

@ -0,0 +1,14 @@
## Python Issues OSX
Make sure you are using the native Python version in OSX. If you use a MacPorts of HomeBrew version, you may run into problems.
If you have issues with `execvp`, be sure to check your `$PYTHON` environment variable. If it is not set to the native version, unset it and try again.
Notes: https://gist.github.com/erichocean/5177582
## npm ERR! `node-gyp rebuild`(Windows)
* just install the build tools from [here](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=BuildTools)
Please note the version as is required in below command e.g **2017**
* Launch cmd, run `npm config set msvs_version 2017`
* close and open new CMD/terminal and all is well :100:

View file

@ -0,0 +1,94 @@
When using `node-gyp` you might see an error like this when attempting to compile/install a node.js native addon:
```
$ npm install bcrypt
npm http GET https://registry.npmjs.org/bcrypt/0.7.5
npm http 304 https://registry.npmjs.org/bcrypt/0.7.5
npm http GET https://registry.npmjs.org/bindings/1.0.0
npm http 304 https://registry.npmjs.org/bindings/1.0.0
> bcrypt@0.7.5 install /home/ubuntu/public/song-swap/node_modules/bcrypt
> node-gyp rebuild
gyp ERR! configure error
gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
gyp ERR! stack at install (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/install.js:69:16)
gyp ERR! stack at Object.self.commands.(anonymous function) [as install] (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/node-gyp.js:56:37)
gyp ERR! stack at getNodeDir (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:219:20)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:105:9
gyp ERR! stack at ChildProcess.exithandler (child_process.js:630:7)
gyp ERR! stack at ChildProcess.EventEmitter.emit (events.js:99:17)
gyp ERR! stack at maybeClose (child_process.js:730:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:5)
gyp ERR! System Linux 3.5.0-21-generic
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/ubuntu/public/song-swap/node_modules/bcrypt
gyp ERR! node -v v0.11.2-pre
gyp ERR! node-gyp -v v0.9.5
gyp ERR! not ok
npm ERR! bcrypt@0.7.5 install: `node-gyp rebuild`
npm ERR! `sh "-c" "node-gyp rebuild"` failed with 1
npm ERR!
npm ERR! Failed at the bcrypt@0.7.5 install script.
npm ERR! This is most likely a problem with the bcrypt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls bcrypt
npm ERR! There is likely additional logging output above.
npm ERR! System Linux 3.5.0-21-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "bcrypt"
npm ERR! cwd /home/ubuntu/public/song-swap
npm ERR! node -v v0.11.2-pre
npm ERR! npm -v 1.2.18
npm ERR! code ELIFECYCLE
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/ubuntu/public/song-swap/npm-debug.log
npm ERR! not ok code 0
```
The main error here is:
```
Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
```
This error is caused when you attempt to compile a native addon using a version of node.js with `-pre` at the end of the version number:
``` bash
$ node -v
v0.10.4-pre
```
## How to avoid (the short answer)
To avoid this error completely just use a stable release of node.js. i.e. `v0.10.4`, and __not__ `v0.10.4-pre`.
## How to fix (the long answer)
This error happens because `node-gyp` does not know what header files were used to compile your "pre" version of node, and therefore it needs you to specify the node source code directory path using the `--nodedir` flag.
For example, if I compiled my development ("pre") version of node.js using the source code in `/Users/nrajlich/node`, then I could invoke `node-gyp` like:
``` bash
$ node-gyp rebuild --nodedir=/Users/nrajlich/node
```
Or install an native addon through `npm` like:
``` bash
$ npm install bcrypt --nodedir=/Users/nrajlich/node
```
### Always use `--nodedir`
__Note:__ This is for advanced users who use `-pre` versions of node more often than tagged releases.
If you're invoking `node-gyp` through `npm`, then you can leverage `npm`'s configuration system and not have to specify the `--nodedir` flag all the time:
``` bash
$ npm config set nodedir /Users/nrajlich/node
```

7
docs/Home.md Normal file
View file

@ -0,0 +1,7 @@
Welcome to the node-gyp wiki!
* [["binding.gyp" files out in the wild]]
* [[Linking to OpenSSL]]
* [[Common Issues]]
* [[Updating npm's bundled node-gyp]]
* [[Error: "pre" versions of node cannot be installed]]

View file

@ -0,0 +1,86 @@
A handful of native addons require linking to OpenSSL in one way or another. This introduces a small challenge since node will sometimes bundle OpenSSL statically (the default for node >= v0.8.x), or sometimes dynamically link to the system OpenSSL (default for node <= v0.6.x).
Good native addons should account for both scenarios. It's recommended that you use the `binding.gyp` file provided below as a starting-point for any addon that needs to use OpenSSL:
``` python
{
'variables': {
# node v0.6.x doesn't give us its build variables,
# but on Unix it was only possible to use the system OpenSSL library,
# so default the variable to "true", v0.8.x node and up will overwrite it.
'node_shared_openssl%': 'true'
},
'targets': [
{
'target_name': 'binding',
'sources': [
'src/binding.cc'
],
'conditions': [
['node_shared_openssl=="false"', {
# so when "node_shared_openssl" is "false", then OpenSSL has been
# bundled into the node executable. So we need to include the same
# header files that were used when building node.
'include_dirs': [
'<(node_root_dir)/deps/openssl/openssl/include'
],
"conditions" : [
["target_arch=='ia32'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/piii" ]
}],
["target_arch=='x64'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/k8" ]
}],
["target_arch=='arm'", {
"include_dirs": [ "<(node_root_dir)/deps/openssl/config/arm" ]
}]
]
}]
]
}
]
}
```
This ensures that when OpenSSL is statically linked into `node` then, the bundled OpenSSL headers are included, but when the system OpenSSL is in use, then only those headers will be used.
## Windows?
As you can see this baseline `binding.gyp` file only accounts for the Unix scenario. Currently on Windows the situation is a little less ideal. On Windows, OpenSSL is _always_ statically compiled into the `node` executable, so ideally it would be possible to use that copy of OpenSSL when building native addons.
Unfortunately it doesn't seem like that is possible at the moment, as there would need to be tweaks made to the generated `node.lib` file to include the openssl glue functions, or a new `openssl.lib` file would need to be created during the node build. I'm not sure which is the easiest/most feasible.
In the meantime, one possible solution is using another copy of OpenSSL, which is what [`node-bcrypt`](https://github.com/ncb000gt/node.bcrypt.js) currently does. Adding something like this to your `binding.gyp` file's `"conditions"` block would enable this:
``` python
[ 'OS=="win"', {
'conditions': [
# "openssl_root" is the directory on Windows of the OpenSSL files.
# Check the "target_arch" variable to set good default values for
# both 64-bit and 32-bit builds of the module.
['target_arch=="x64"', {
'variables': {
'openssl_root%': 'C:/OpenSSL-Win64'
},
}, {
'variables': {
'openssl_root%': 'C:/OpenSSL-Win32'
},
}],
],
'libraries': [
'-l<(openssl_root)/lib/libeay32.lib',
],
'include_dirs': [
'<(openssl_root)/include',
],
}]
```
Now you can direct your users to install OpenSSL on Windows from here (be sure to tell them to install the 64-bit version if they're compiling against a 64-bit version of node): http://slproweb.com/products/Win32OpenSSL.html
Also note that both `node-gyp` and `npm` allow you to overwrite that default `openssl_root` variable on the command line:
``` bash
$ node-gyp rebuild --openssl-root="C:\Users\Nathan\Desktop\openssl"
```

View file

@ -0,0 +1,63 @@
`npm` bundles its own, internal, copy of `node-gyp`. This internal copy is independent of any globally installed copy of node-gyp that
you may have installed via `npm install -g node-gyp`.
This means that while `node-gyp` doesn't get installed into your `$PATH` by default, npm still keeps its own copy to invoke when you
attempt to `npm install` a native add-on.
Sometimes, you may need to update npm's internal node-gyp to a newer version than what is installed. A simple `npm install -g node-gyp`
_won't_ do the trick since npm will still continue to use its internal copy over the global one.
So instead:
## Version of npm
We need to start by knowing your version of `npm`:
```bash
npm --version
```
## Linux, macOS, Solaris, etc.
Unix is easy. Just run the following command.
If your npm is version ___7___, do:
```bash
$ npm explore npm/node_modules/@npmcli/run-script -g -- npm_config_global=false npm install node-gyp@latest
```
Else if your npm is version ___less than 7___, do:
```bash
$ npm explore npm/node_modules/npm-lifecycle -g -- npm install node-gyp@latest
```
If the command fails with a permissions error, please try `sudo` and then the command.
## Windows
Windows is a bit trickier, since `npm` might be installed to the "Program Files" directory, which needs admin privileges in order to
modify on current Windows. Therefore, run the following commands __inside a `cmd.exe` started with "Run as Administrator"__:
First we need to find the location of `node`. If you don't already know the location that `node.exe` got installed to, then run:
```bash
$ where node
```
Now `cd` to the directory that `node.exe` is contained in e.g.:
```bash
$ cd "C:\Program Files\nodejs"
```
If your npm version is ___7___, do:
```bash
cd node_modules\npm\node_modules\@npmcli\run-script
```
Else if your npm version is ___less than 7___, do:
```bash
cd node_modules\npm\node_modules\npm-lifecycle
```
Finish by running:
```bash
$ npm install node-gyp@latest
```

View file

@ -0,0 +1,2 @@
Local<TypedArray> typedArray = Local<TypedArray>::Cast(arg[0]);
why node-gyp not support typedArray