Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b83f9a5

Browse filesBrowse files
NickNasorichardlau
authored andcommitted
build: expose napi_build_version variable
Expose `napi_build_version` to allow `node-gyp` to make it available for building native addons. Fixes: nodejs/node-gyp#1745 Refs: nodejs/abi-stable-node#371 PR-URL: #27835 Backport-PR-URL: #35266 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
1 parent 2eb6273 commit b83f9a5
Copy full SHA for b83f9a5

File tree

Expand file treeCollapse file tree

5 files changed

+42
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+42
-1
lines changed
Open diff view settings
Collapse file

‎configure.py‎

Copy file name to clipboardExpand all lines: configure.py
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
# imports in tools/
3535
sys.path.insert(0, 'tools')
3636
import getmoduleversion
37+
import getnapibuildversion
3738
from gyp_node import run_gyp
3839

3940
# imports in deps/v8/tools/node
@@ -1131,6 +1132,10 @@ def configure_node(o):
11311132
else:
11321133
o['variables']['node_target_type'] = 'executable'
11331134

1135+
def configure_napi(output):
1136+
version = getnapibuildversion.get_napi_version()
1137+
output['variables']['napi_build_version'] = version
1138+
11341139
def configure_library(lib, output):
11351140
shared_lib = 'shared_' + lib
11361141
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1603,6 +1608,7 @@ def make_bin_override():
16031608
flavor = GetFlavor(flavor_params)
16041609

16051610
configure_node(output)
1611+
configure_napi(output)
16061612
configure_library('zlib', output)
16071613
configure_library('http_parser', output)
16081614
configure_library('libuv', output)
Collapse file

‎doc/api/process.md‎

Copy file name to clipboardExpand all lines: doc/api/process.md
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ An example of the possible output looks like:
661661
variables:
662662
{
663663
host_arch: 'x64',
664+
napi_build_version: 4,
664665
node_install_npm: 'true',
665666
node_prefix: '',
666667
node_shared_cares: 'false',
Collapse file

‎src/node_api.h‎

Copy file name to clipboardExpand all lines: src/node_api.h
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
// Use INT_MAX, this should only be consumed by the pre-processor anyway.
1010
#define NAPI_VERSION 2147483647
1111
#else
12-
// The baseline version for N-API
12+
// The baseline version for N-API.
13+
// The NAPI_VERSION controls which version will be used by default when
14+
// compilling a native addon. If the addon developer specifically wants to use
15+
// functions available in a new version of N-API that is not yet ported in all
16+
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
17+
// depended on that version.
1318
#define NAPI_VERSION 6
1419
#endif
1520
#endif
Collapse file

‎test/parallel/test-process-versions.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-process-versions.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ for (let i = 0; i < expected_keys.length; i++) {
4343
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
4444
assert.strictEqual(descriptor.writable, false);
4545
}
46+
47+
assert.strictEqual(process.config.variables.napi_build_version,
48+
process.versions.napi);
Collapse file

‎tools/getnapibuildversion.py‎

Copy file name to clipboard
+26Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from __future__ import print_function
2+
import os
3+
import re
4+
5+
6+
def get_napi_version():
7+
napi_version_h = os.path.join(
8+
os.path.dirname(__file__),
9+
'..',
10+
'src',
11+
'node_version.h')
12+
13+
f = open(napi_version_h)
14+
15+
regex = '^#define NAPI_VERSION'
16+
17+
for line in f:
18+
if re.match(regex, line):
19+
napi_version = line.split()[2]
20+
return napi_version
21+
22+
raise Exception('Could not find pattern matching %s' % regex)
23+
24+
25+
if __name__ == '__main__':
26+
print(get_napi_version())

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.