Skip to content

Commit 248df1b

Browse files
NickNasoGabriel Schulhof
authored and
Gabriel Schulhof
committed
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: nodejs#27835 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Gabriel Schulhof <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent d065960 commit 248df1b

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

configure.py

+6
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)

doc/api/process.md

+1
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',

src/node_api.h

+6-1
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

test/parallel/test-process-versions.js

+3
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);

tools/getnapibuildversion.py

+26
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)