Skip to content

feat(compile): support for ffi and node native addons #28934

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

Merged

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Apr 16, 2025

This extracts out the shared libraries and .node native modules to a temp file and opens them from there. This means that this implementation will not work in every scenario. For example, a library could require other files that only exist in the in-memory file system. To solve that, we'll introduce #28918 later or adapt this solution to solve more issues.

Additionally, this will not work when run on readonly file systems.

Closes #23266

@dsherret dsherret changed the title feat(compile): support for node native addons feat(compile): support for ffi and node native addons Apr 16, 2025
@dsherret dsherret added this to the 2.3.0 milestone Apr 16, 2025
@@ -87,6 +87,7 @@ impl CliCjsCodeAnalyzer {
source: &str,
esm_analysis_mode: EsmAnalysisMode,
) -> Result<CliCjsAnalysis, JsErrorBox> {
let source = source.strip_prefix('\u{FEFF}').unwrap_or(source); // strip BOM
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran into this while testing.

@dsherret dsherret marked this pull request as ready for review April 17, 2025 17:54
@dsherret dsherret requested a review from Copilot April 17, 2025 18:26
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for FFI and Node native addons by extracting shared libraries and .node modules to a temporary file, introducing new runtime options and helper functionality.

  • Introduces a new option (deno_rt_native_addon_loader) to various worker service options.
  • Updates initialization calls for deno_ffi and deno_napi extensions to pass native addon loader parameters.
  • Adds a new helper library (denort_helper) for native addon loading and associated error handling.

Reviewed Changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated no comments.

Show a summary per file
File Description
runtime/worker.rs Added new option and updated extension initialization.
runtime/web_worker.rs Added native addon loader option to web worker service options.
runtime/snapshot_info.rs & snapshot.rs Updated snapshot extension initialization calls.
runtime/examples/extension/main.rs Example now provides a native addon loader parameter.
ext/rt_helper/* Introduced new helper library for native addon loading.
ext/napi/* and ext/ffi/* Updated modules to pass and use the new native addon loader option.
cli/* Updated CLI components and Cargo.toml for addon loader support.

@dsherret dsherret requested a review from nathanwhit April 17, 2025 18:26
Copy link
Member

@nathanwhit nathanwhit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsherret dsherret merged commit 16d3054 into denoland:main Apr 17, 2025
18 checks passed
@dsherret dsherret deleted the feat_basic_support_node_api_deno_compile branch April 17, 2025 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for node native addons / napi / FFI in deno compile
2 participants