Skip to content

Commit

Permalink
build: expose napi_build_version variable
Browse files Browse the repository at this point in the history
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 <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>
  • Loading branch information
NickNaso authored and Gabriel Schulhof committed Jul 2, 2019
1 parent e008ca8 commit 9868126
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
# imports in tools/
sys.path.insert(0, 'tools')
import getmoduleversion
import getnapibuildversion
from gyp_node import run_gyp

# imports in deps/v8/tools/node
Expand Down Expand Up @@ -1147,6 +1148,10 @@ def configure_node(o):
else:
o['variables']['node_target_type'] = 'executable'

def configure_napi(output):
version = getnapibuildversion.get_napi_version()
output['variables']['napi_build_version'] = version

def configure_library(lib, output):
shared_lib = 'shared_' + lib
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
Expand Down Expand Up @@ -1626,6 +1631,7 @@ def make_bin_override():
flavor = GetFlavor(flavor_params)

configure_node(output)
configure_napi(output)
configure_library('zlib', output)
configure_library('http_parser', output)
configure_library('libuv', output)
Expand Down
1 change: 1 addition & 0 deletions doc/api/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ An example of the possible output looks like:
variables:
{
host_arch: 'x64',
napi_build_version: 4,
node_install_npm: 'true',
node_prefix: '',
node_shared_cares: 'false',
Expand Down
7 changes: 6 additions & 1 deletion src/js_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
#ifdef NAPI_EXPERIMENTAL
#define NAPI_VERSION NAPI_VERSION_EXPERIMENTAL
#else
// The baseline version for N-API
// The baseline version for N-API.
// The NAPI_VERSION controls which version will be used by default when
// compilling a native addon. If the addon developer specifically wants to use
// functions available in a new version of N-API that is not yet ported in all
// LTS versions, they can set NAPI_VERSION knowing that they have specifically
// depended on that version.
#define NAPI_VERSION 4
#endif
#endif
Expand Down
3 changes: 2 additions & 1 deletion src/node_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
*/
#define NODE_MODULE_VERSION 74

// the NAPI_VERSION provided by this version of the runtime
// The NAPI_VERSION provided by this version of the runtime. This is the version
// which the Node binary being built supports.
#define NAPI_VERSION 4

#endif // SRC_NODE_VERSION_H_
3 changes: 3 additions & 0 deletions test/parallel/test-process-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,6 @@ for (let i = 0; i < expected_keys.length; i++) {
const descriptor = Object.getOwnPropertyDescriptor(process.versions, key);
assert.strictEqual(descriptor.writable, false);
}

assert.strictEqual(process.config.variables.napi_build_version,
process.versions.napi);
26 changes: 26 additions & 0 deletions tools/getnapibuildversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from __future__ import print_function
import os
import re


def get_napi_version():
napi_version_h = os.path.join(
os.path.dirname(__file__),
'..',
'src',
'node_version.h')

f = open(napi_version_h)

regex = '^#define NAPI_VERSION'

for line in f:
if re.match(regex, line):
napi_version = line.split()[2]
return napi_version

raise Exception('Could not find pattern matching %s' % regex)


if __name__ == '__main__':
print(get_napi_version())

0 comments on commit 9868126

Please sign in to comment.