Skip to content
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

feat(runtime): add a Cargo feature flag to enable the ffi API #26493

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions runtime/00_ffi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

// mock FFI interface in case the `ffi` Cargo feature is not enabled
5 changes: 4 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ repository.workspace = true
description = "Provides the deno runtime library"

[features]
default = ["ffi"]
# "fake" feature that allows to generate docs on docs.rs
docsrs = []
# A feature that allows excluding `./js/99_main.js` from the exported extension.
Expand All @@ -29,6 +30,8 @@ hmr = ["include_js_files_for_snapshotting", "transpile"]
only_snapshotted_js_sources = ["include_js_files_for_snapshotting"]
snapshot = ["transpile"]
transpile = ["deno_ast"]
# enable the FFI API
ffi = ["deno_ffi"]

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
Expand All @@ -53,7 +56,7 @@ deno_cron.workspace = true
deno_crypto.workspace = true
deno_error.workspace = true
deno_fetch.workspace = true
deno_ffi.workspace = true
deno_ffi = { workspace = true, optional = true }
deno_fs = { workspace = true, features = ["sync_fs"] }
deno_http.workspace = true
deno_io.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions runtime/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub use deno_core;
pub use deno_cron;
pub use deno_crypto;
pub use deno_fetch;
#[cfg(feature = "ffi")]
pub use deno_ffi;
pub use deno_fs;
pub use deno_http;
Expand Down Expand Up @@ -75,6 +76,7 @@ pub static UNSTABLE_GRANULAR_FLAGS: &[UnstableGranularFlag] = &[
show_in_help: true,
id: 2,
},
#[cfg(feature = "ffi")]
UnstableGranularFlag {
name: deno_ffi::UNSTABLE_FEATURE_NAME,
help_text: "Enable unstable FFI APIs",
Expand Down
3 changes: 3 additions & 0 deletions runtime/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
use deno_core::extension;
use deno_core::Extension;

#[cfg(not(feature = "ffi"))]
extension!(deno_ffi, esm = ["00_ffi.js"]);

extension!(runtime,
deps = [
deno_webidl,
Expand Down
4 changes: 4 additions & 0 deletions runtime/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl deno_fetch::FetchPermissions for Permissions {
}
}

#[cfg(feature = "ffi")]
impl deno_ffi::FfiPermissions for Permissions {
fn check_partial_no_path(&mut self) -> Result<(), PermissionCheckError> {
unreachable!("snapshotting!")
Expand Down Expand Up @@ -293,7 +294,10 @@ pub fn create_runtime_snapshot(
deno_broadcast_channel::deno_broadcast_channel::init_ops_and_esm(
deno_broadcast_channel::InMemoryBroadcastChannel::default(),
),
#[cfg(feature = "ffi")]
deno_ffi::deno_ffi::init_ops_and_esm::<Permissions>(),
#[cfg(not(feature = "ffi"))]
crate::shared::deno_ffi::init_ops_and_esm(),
deno_net::deno_net::init_ops_and_esm::<Permissions>(None, None),
deno_tls::deno_tls::init_ops_and_esm(),
deno_kv::deno_kv::init_ops_and_esm(
Expand Down
3 changes: 3 additions & 0 deletions runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,10 @@ impl WebWorker {
deno_broadcast_channel::deno_broadcast_channel::init_ops_and_esm(
services.broadcast_channel,
),
#[cfg(feature = "ffi")]
deno_ffi::deno_ffi::init_ops_and_esm::<PermissionsContainer>(),
#[cfg(not(feature = "ffi"))]
crate::shared::deno_ffi::init_ops_and_esm(),
deno_net::deno_net::init_ops_and_esm::<PermissionsContainer>(
services.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
Expand Down
3 changes: 3 additions & 0 deletions runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ impl MainWorker {
deno_broadcast_channel::deno_broadcast_channel::init_ops_and_esm(
services.broadcast_channel.clone(),
),
#[cfg(feature = "ffi")]
deno_ffi::deno_ffi::init_ops_and_esm::<PermissionsContainer>(),
#[cfg(not(feature = "ffi"))]
crate::shared::deno_ffi::init_ops_and_esm(),
deno_net::deno_net::init_ops_and_esm::<PermissionsContainer>(
services.root_cert_store_provider.clone(),
options.unsafely_ignore_certificate_errors.clone(),
Expand Down
2 changes: 1 addition & 1 deletion tests/node_compat/runner/suite
Submodule suite updated 3 files
+1 −1 README.md
+0 −3 node_version.ts
+2 −3 vendor.ts
Loading