diff --git a/crates/neon/Cargo.toml b/crates/neon/Cargo.toml index 4988d3f5b..9c7045642 100644 --- a/crates/neon/Cargo.toml +++ b/crates/neon/Cargo.toml @@ -40,7 +40,7 @@ features = ["sync"] optional = true [features] -default = ["napi-1"] +default = ["napi-8"] # Enable the creation of external binary buffers. This is disabled by default # since these APIs fail at runtime in environments that enable the V8 memory diff --git a/crates/neon/src/sys/bindings/functions.rs b/crates/neon/src/sys/bindings/functions.rs index a708a4548..55bc5038b 100644 --- a/crates/neon/src/sys/bindings/functions.rs +++ b/crates/neon/src/sys/bindings/functions.rs @@ -437,21 +437,36 @@ pub(crate) unsafe fn load(env: Env) -> Result<(), libloading::Error> { // This never fail since `get_version` is in N-API Version 1 and the module will fail // with `Error: Module did not self-register` if N-API does not exist. - let version = get_version(&host, env).expect("Failed to find N-API version"); + let actual_version = get_version(&host, env).expect("Failed to find N-API version"); - napi1::load(&host, version, 1); + let expected_version = match () { + _ if cfg!(feature = "napi-8") => 8, + _ if cfg!(feature = "napi-7") => 7, + _ if cfg!(feature = "napi-6") => 6, + _ if cfg!(feature = "napi-5") => 5, + _ if cfg!(feature = "napi-4") => 4, + _ if cfg!(feature = "napi-3") => 3, + _ if cfg!(feature = "napi-2") => 2, + _ => 1, + }; + + if actual_version < expected_version { + eprintln!("Minimum required Node-API version {expected_version}, found {actual_version}.\n\nSee the Node-API support matrix for more details: https://nodejs.org/api/n-api.html#node-api-version-matrix"); + } + + napi1::load(&host); #[cfg(feature = "napi-4")] - napi4::load(&host, version, 4); + napi4::load(&host); #[cfg(feature = "napi-5")] - napi5::load(&host, version, 5); + napi5::load(&host); #[cfg(feature = "napi-6")] - napi6::load(&host, version, 6); + napi6::load(&host); #[cfg(feature = "napi-8")] - napi8::load(&host, version, 8); + napi8::load(&host); Ok(()) } diff --git a/crates/neon/src/sys/bindings/mod.rs b/crates/neon/src/sys/bindings/mod.rs index 1a5a23d9b..cdd8559e1 100644 --- a/crates/neon/src/sys/bindings/mod.rs +++ b/crates/neon/src/sys/bindings/mod.rs @@ -137,18 +137,7 @@ macro_rules! generate { } }; - pub(super) unsafe fn load( - host: &libloading::Library, - actual_napi_version: u32, - expected_napi_version: u32, - ) { - assert!( - actual_napi_version >= expected_napi_version, - "Minimum required Node-API version {}, found {}.", - expected_napi_version, - actual_napi_version, - ); - + pub(super) unsafe fn load(host: &libloading::Library) { let print_warn = |err| eprintln!("WARN: {}", err); NAPI = Napi {