-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Make native modules built with Neon work in Bun #914
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 = { | ||
|
@@ -139,21 +139,31 @@ macro_rules! generate { | |
host: &libloading::Library, | ||
actual_napi_version: u32, | ||
expected_napi_version: u32, | ||
) -> 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, | ||
); | ||
|
||
let print_warn = |err| eprintln!("WARN: {}", err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sample output:
|
||
|
||
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) => { | ||
print_warn(err); | ||
NAPI.$name | ||
}, | ||
}, | ||
)* | ||
}; | ||
|
||
Ok(()) | ||
} | ||
|
||
$( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently this panic stack looks like:
The panic message itself doesn't explain what symbol is missing; instead it requires the backtrace to determine. This is by design because it's never expected to happen on Node and only having a single panic method for the defaults reduces binary bloat.
Do you think it's worth the cost to binary sizes (a bunch of unique functions that should never be executed) to have more clear error messages in
bun
? I personally feel that the backtrace is sufficient since eventually all symbols should be implemented.