Skip to content

Commit

Permalink
Make Node-API 8 the default
Browse files Browse the repository at this point in the history
Additionally, warn on older versions instead of panicking.
  • Loading branch information
kjvalencik committed Dec 8, 2023
1 parent 625aab0 commit f2ad8fd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
2 changes: 2 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 1.0.0

## Commitment to Compatibility

The release of Neon 1.0 marks our commitment to backwards-compatibility: starting with 1.0.0, Neon users can be confident that future **upgrades to Neon 1.x versions should never require code changes** (with the possible exception of safety bugfixes, which we expect to be rare). We also do not anticipate releasing new major versions often and do not have any plans to do so for now.

## Breaking Changes
Expand All @@ -20,6 +21,7 @@ The release of Neon 1.0 marks our commitment to backwards-compatibility: startin

https://github.com/neon-bindings/neon/pull/1010

* Relaxed error behavior on missing Node-API symbols. Neon will panic on first use instead of aborting the process at module load time.
* Bumped dependency versions
* Changed to edition 2021
* Updated support matrix to Node 18, 20, and 21
Expand Down
2 changes: 1 addition & 1 deletion crates/neon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 21 additions & 6 deletions crates/neon/src/sys/bindings/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
13 changes: 1 addition & 12 deletions crates/neon/src/sys/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f2ad8fd

Please sign in to comment.