Skip to content

Commit cd71aad

Browse files
NickNasotargos
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 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 8a64b70 commit cd71aad

File tree

6 files changed

+44
-2
lines changed

6 files changed

+44
-2
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
@@ -1147,6 +1148,10 @@ def configure_node(o):
11471148
else:
11481149
o['variables']['node_target_type'] = 'executable'
11491150

1151+
def configure_napi(output):
1152+
version = getnapibuildversion.get_napi_version()
1153+
output['variables']['napi_build_version'] = version
1154+
11501155
def configure_library(lib, output):
11511156
shared_lib = 'shared_' + lib
11521157
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1626,6 +1631,7 @@ def make_bin_override():
16261631
flavor = GetFlavor(flavor_params)
16271632

16281633
configure_node(output)
1634+
configure_napi(output)
16291635
configure_library('zlib', output)
16301636
configure_library('http_parser', output)
16311637
configure_library('libuv', output)

doc/api/process.md

+1
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ An example of the possible output looks like:
662662
variables:
663663
{
664664
host_arch: 'x64',
665+
napi_build_version: 4,
665666
node_install_npm: 'true',
666667
node_prefix: '',
667668
node_shared_cares: 'false',

src/js_native_api.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
#ifdef NAPI_EXPERIMENTAL
1313
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
1414
#else
15-
// The baseline version for N-API
15+
// The baseline version for N-API.
16+
// The NAPI_VERSION controls which version will be used by default when
17+
// compilling a native addon. If the addon developer specifically wants to use
18+
// functions available in a new version of N-API that is not yet ported in all
19+
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
20+
// depended on that version.
1621
#define NAPI_VERSION 4
1722
#endif
1823
#endif

src/node_version.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
*/
9292
#define NODE_MODULE_VERSION 72
9393

94-
// the NAPI_VERSION provided by this version of the runtime
94+
// The NAPI_VERSION provided by this version of the runtime. This is the version
95+
// which the Node binary being built supports.
9596
#define NAPI_VERSION 4
9697

9798
#endif // SRC_NODE_VERSION_H_

test/parallel/test-process-versions.js

+3
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ for (let i = 0; i < expected_keys.length; i++) {
4545
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
4646
assert.strictEqual(descriptor.writable, false);
4747
}
48+
49+
assert.strictEqual(process.config.variables.napi_build_version,
50+
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)