Skip to content

Commit

Permalink
fix: Make native modules built with Neon work in Bun
Browse files Browse the repository at this point in the history
  • Loading branch information
kjvalencik committed Jul 8, 2022
1 parent f21146d commit 3ad6d05
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions crates/neon/src/sys/bindings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ macro_rules! generate {

#[inline(never)]
fn panic_load<T>() -> T {
panic!("Must load N-API bindings")
panic!("Node-API symbol has not been loaded")
}

static mut NAPI: Napi = {
Expand All @@ -142,14 +142,24 @@ macro_rules! generate {
) -> Result<(), libloading::Error> {
assert!(
actual_napi_version >= expected_napi_version,
"Minimum required N-API version {}, found {}.",
"Minimum required Node-API version {}, found {}.",
expected_napi_version,
actual_napi_version,
);

NAPI = Napi {
$(
$name: *host.get(napi_name!($name).as_bytes())?,
$name: match host.get(napi_name!($name).as_bytes()) {
Ok(f) => *f,
// Node compatible runtimes may not have full coverage of Node-API
// (e.g., bun). Instead of failing to start, warn on start and
// panic when the API is called.
// https://github.com/Jarred-Sumner/bun/issues/158
Err(err) => {
eprintln!("WARN: {}", err);
NAPI.$name
},
},
)*
};

Expand Down

0 comments on commit 3ad6d05

Please sign in to comment.