Skip to content

Commit

Permalink
rename internal NAPI_VERSION definition (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi authored Jun 28, 2023
1 parent 5870859 commit aed0ee1
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
{
"name": "Emscripten",
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=2147483647"],
"compilerPath": "${env:EMSDK}/upstream/emscripten/emcc",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
Expand All @@ -58,7 +58,7 @@
},
{
"name": "Win32 Emscripten",
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=2147483647"],
"compilerPath": "${env:EMSDK}\\upstream\\emscripten\\emcc.bat",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
Expand Down
2 changes: 1 addition & 1 deletion packages/bench/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TY
set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}" CACHE PATH "pdb output")
project(emnapibench)
add_compile_definitions(
"NAPI_VERSION=8"
"NAPI_VERSION=9"
"NAPI_DISABLE_CPP_EXCEPTIONS"
"NODE_ADDON_API_ENABLE_MAYBE"
)
Expand Down
4 changes: 2 additions & 2 deletions packages/emnapi/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ function _napi_get_version (env: napi_env, result: Pointer<uint32_t>): napi_stat
const envObject = emnapiCtx.envStore.get(env)!
$CHECK_ARG!(envObject, result)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const NAPI_VERSION = Version.NAPI_VERSION
$makeSetValue('result', 0, 'NAPI_VERSION', 'u32')
const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX
$makeSetValue('result', 0, 'NODE_API_SUPPORTED_VERSION_MAX', 'u32')
return envObject.clearLastError()
}

Expand Down
4 changes: 2 additions & 2 deletions packages/node/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
"name": "Emscripten",
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=2147483647"],
"compilerPath": "${env:EMSDK}/upstream/emscripten/emcc",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
Expand All @@ -57,7 +57,7 @@
},
{
"name": "Win32 Emscripten",
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=8"],
"defines": ["${defines}", "__wasm__", "__EMSCRIPTEN_PTHREADS__", "NAPI_VERSION=2147483647"],
"compilerPath": "${env:EMSDK}\\upstream\\emscripten\\emcc.bat",
"intelliSenseMode": "linux-clang-x86",
"cStandard": "c11",
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
_Buffer,
_MessageChannel,
version,
NAPI_VERSION,
NODE_API_SUPPORTED_VERSION_MAX,
NAPI_VERSION_EXPERIMENTAL,
NODE_API_DEFAULT_MODULE_API_VERSION
} from './util'
Expand Down Expand Up @@ -145,7 +145,7 @@ export class Context {
getRuntimeVersions () {
return {
version,
NAPI_VERSION,
NODE_API_SUPPORTED_VERSION_MAX,
NAPI_VERSION_EXPERIMENTAL,
NODE_API_DEFAULT_MODULE_API_VERSION
}
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { IStoreValue } from './Store'
import {
TryCatch,
_setImmediate,
NAPI_VERSION,
NODE_API_SUPPORTED_VERSION_MAX,
NAPI_VERSION_EXPERIMENTAL,
NODE_API_DEFAULT_MODULE_API_VERSION
} from './util'
Expand All @@ -15,7 +15,7 @@ function throwNodeApiVersionError (moduleName: string, moduleApiVersion: number)
const errorMessage = `${
moduleName} requires Node-API version ${
moduleApiVersion}, but this version of Node.js only supports version ${
NAPI_VERSION} add-ons.`
NODE_API_SUPPORTED_VERSION_MAX} add-ons.`
throw new Error(errorMessage)
}

Expand Down Expand Up @@ -314,7 +314,7 @@ export function newEnv (
// Validate module_api_version.
if (moduleApiVersion < NODE_API_DEFAULT_MODULE_API_VERSION) {
moduleApiVersion = NODE_API_DEFAULT_MODULE_API_VERSION
} else if (moduleApiVersion > NAPI_VERSION && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
} else if (moduleApiVersion > NODE_API_SUPPORTED_VERSION_MAX && moduleApiVersion !== NAPI_VERSION_EXPERIMENTAL) {
throwNodeApiVersionError(filename, moduleApiVersion)
}
const env = new NodeEnv(ctx, filename, moduleApiVersion, makeDynCall_vppp, makeDynCall_vp, abort, nodeBinding)
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export {
isReferenceType,
TryCatch,
version,
NAPI_VERSION,
NODE_API_SUPPORTED_VERSION_MIN,
NODE_API_SUPPORTED_VERSION_MAX,
NAPI_VERSION_EXPERIMENTAL,
NODE_API_DEFAULT_MODULE_API_VERSION
} from './util'
3 changes: 2 additions & 1 deletion packages/runtime/src/typings/common.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ declare const enum Ownership {
}

declare const enum Version {
NODE_API_SUPPORTED_VERSION_MIN = 1,
NODE_API_DEFAULT_MODULE_API_VERSION = 8,
NAPI_VERSION = 9,
NODE_API_SUPPORTED_VERSION_MAX = 9,
NAPI_VERSION_EXPERIMENTAL = 2147483647 // INT_MAX
}
3 changes: 2 additions & 1 deletion packages/runtime/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const _Buffer: BufferCtor | undefined = typeof Buffer === 'function'
// Versions defined in runtime
declare const __VERSION__: string
export const version = __VERSION__
export const NAPI_VERSION = Version.NAPI_VERSION
export const NODE_API_SUPPORTED_VERSION_MIN = Version.NODE_API_SUPPORTED_VERSION_MIN
export const NODE_API_SUPPORTED_VERSION_MAX = Version.NODE_API_SUPPORTED_VERSION_MAX
export const NAPI_VERSION_EXPERIMENTAL = Version.NAPI_VERSION_EXPERIMENTAL
export const NODE_API_DEFAULT_MODULE_API_VERSION = Version.NODE_API_DEFAULT_MODULE_API_VERSION
4 changes: 1 addition & 3 deletions packages/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ if(MSVC AND CMAKE_JS_NODELIB_DEF AND CMAKE_JS_NODELIB_TARGET)
execute_process(COMMAND ${CMAKE_AR} /def:${CMAKE_JS_NODELIB_DEF} /out:${CMAKE_JS_NODELIB_TARGET} ${CMAKE_STATIC_LINKER_FLAGS})
endif()

# add_compile_definitions("NAPI_VERSION=8")

if(CMAKE_SYSTEM_NAME STREQUAL "Emscripten")
set(IS_EMSCRIPTEN ON)
else()
Expand Down Expand Up @@ -212,7 +210,7 @@ function(add_naa_test NAME SOURCE_LIST DEFINES ENABLE_EXCEPTION)
target_link_libraries(${NAME} PRIVATE ${CMAKE_JS_LIB})
endif()

target_compile_definitions(${NAME} PRIVATE "NAPI_VERSION=8")
target_compile_definitions(${NAME} PRIVATE "NAPI_VERSION=9")

set_target_properties(${NAME} PROPERTIES
BUILD_RPATH "$ORIGIN")
Expand Down
2 changes: 1 addition & 1 deletion packages/test/script/test-build-all-napi-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { spawn } = require('../../../script/spawn.js')
const { which } = require('../../../script/which.js')

async function main () {
const testVersions = [1, 2, 3, 4, 5, 6, 7, 8]
const testVersions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 2147483647]
const cwd = path.join(__dirname, '../../..')
let emcmake = process.platform === 'win32' ? 'emcmake.bat' : 'emcmake'
if (process.env.EMSDK) {
Expand Down
11 changes: 11 additions & 0 deletions script/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ async function main () {
? ['-G', 'Ninja']
: (process.platform === 'win32' ? ['-G', 'MinGW Makefiles', '-DCMAKE_MAKE_PROGRAM=make'] : [])

let runtimeNapiVersion
try {
runtimeNapiVersion = require('@emnapi/runtime').NAPI_VERSION_EXPERIMENTAL
} catch (_) {
runtimeNapiVersion = 0x7fffffff
}

await spawn('cmake', [
...generatorOptions,
'-DCMAKE_TOOLCHAIN_FILE=./cmake/wasm32.cmake',
`-DLLVM_PREFIX=${LLVM_PATH}`,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_VERBOSE_MAKEFILE=1',
`-DNAPI_VERSION=${runtimeNapiVersion}`,
'-H.',
'-Bbuild/wasm32'
], cwd)
Expand All @@ -67,6 +75,7 @@ async function main () {
`-DWASI_SDK_PREFIX=${WASI_SDK_PATH}`,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_VERBOSE_MAKEFILE=1',
`-DNAPI_VERSION=${runtimeNapiVersion}`,
'-H.',
'-Bbuild/wasm32-wasi'
], cwd)
Expand Down Expand Up @@ -97,6 +106,7 @@ async function main () {
`-DWASI_SDK_PREFIX=${WASI_SDK_PATH}`,
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_VERBOSE_MAKEFILE=1',
`-DNAPI_VERSION=${runtimeNapiVersion}`,
'-H.',
'-Bbuild/wasm32-wasi-threads'
], cwd)
Expand All @@ -120,6 +130,7 @@ async function main () {
'-DCMAKE_BUILD_TYPE=Release',
'-DCMAKE_VERBOSE_MAKEFILE=1',
'-DEMNAPI_INSTALL_SRC=1',
`-DNAPI_VERSION=${runtimeNapiVersion}`,
'-H.',
'-Bbuild/emscripten'
], cwd)
Expand Down

0 comments on commit aed0ee1

Please sign in to comment.