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

Remove feature flags from accepted RFCs #872

Merged
merged 8 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[alias]
# Neon defines mutually exclusive feature flags which prevents using `cargo clippy --all-features`
# The following aliases simplify linting the entire workspace
check-napi = "check --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features proc-macros,try-catch-api,napi-experimental,promise-api,task-api"
check-legacy = "check --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,try-catch-api,legacy-runtime"
clippy-legacy = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,try-catch-api,legacy-runtime -- -A clippy::missing_safety_doc"
clippy-napi = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features proc-macros,try-catch-api,napi-experimental,promise-api,task-api -- -A clippy::missing_safety_doc"
check-napi = "check --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features napi-experimental"
check-legacy = "check --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,legacy-runtime"
clippy-legacy = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p tests -p static_tests --features event-handler-api,proc-macros,legacy-runtime -- -A clippy::missing_safety_doc"
clippy-napi = "clippy --all-targets --no-default-features -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --features napi-experimental -- -A clippy::missing_safety_doc"
neon-test = "test -p neon -p neon-runtime -p neon-build -p neon-macros -p electron-tests -p napi-tests --no-default-features --features=napi-experimental"
neon-doc = "rustdoc --no-default-features --features=channel-api,napi-experimental,proc-macros,try-catch-api,promise-api,task-api -- --cfg docsrs"
neon-doc-test = "test --doc --no-default-features --features=channel-api,napi-experimental,proc-macros,try-catch-api,promise-api,task-api"
neon-doc = "rustdoc --no-default-features --features=napi-experimental -- --cfg docsrs"
neon-doc-test = "test --doc --no-default-features --features=napi-experimental"
26 changes: 5 additions & 21 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ default = ["legacy-runtime"]

# Enable static tests. These can be fragile because of variations in Rust compiler
# error message formatting from version to version, so they're disabled by default.
# TODO: https://github.com/neon-bindings/neon/issues/871
enable-static-tests = []

# Enable the EventHandler API of RFC 25.
# DEPRECATED: Will be removed with `legacy-runtime`
event-handler-api = []

# Enable the default panic hook. Useful for debugging neon itself.
# DEPRECATED: Will be removed with `legacy-runtime`
default-panic-hook = []

# Feature flag to enable the legacy V8/NAN runtime. For now, this feature is
Expand All @@ -62,38 +65,19 @@ napi-latest = ["napi-6"]
napi-experimental = ["napi-6", "neon-runtime/napi-experimental"]

# Feature flag to disable external dependencies on docs build
# DEPRECATED: Will be removed with `legacy-runtime`
docs-only = ["neon-runtime/docs-only"]

# Feature flag to enable the try_catch API of RFC 29.
try-catch-api = []

# Feature flag to enable the `EventQueue` API of RFC 33.
# https://github.com/neon-bindings/rfcs/pull/32
channel-api = []

# Deprecated name for `channel-api`
event-queue-api = ["channel-api"]

# Feature flag to include procedural macros
# DEPRECATED: Will be removed with `legacy-runtime` since it is enabled by default in Node-API backend.
proc-macros = ["neon-macros"]

# Enable `JsPromise` and `Deferred`
# https://github.com/neon-bindings/rfcs/pull/35
promise-api = []
# Enable `TaskBuilder`
# https://github.com/neon-bindings/rfcs/pull/35
task-api = []

[package.metadata.docs.rs]
no-default-features = true
rustdoc-args = ["--cfg", "docsrs"]
features = [
"channel-api",
"napi-experimental",
"proc-macros",
"try-catch-api",
"promise-api",
"task-api",
]

[workspace]
Expand Down
36 changes: 11 additions & 25 deletions src/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ use crate::borrow::internal::Ledger;
#[cfg(feature = "legacy-runtime")]
use crate::borrow::{Borrow, BorrowMut, Ref, RefMut};
use crate::context::internal::Env;
#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[cfg(feature = "napi-4")]
use crate::event::Channel;
#[cfg(all(feature = "napi-1", feature = "task-api"))]
#[cfg(feature = "napi-1")]
use crate::event::TaskBuilder;
use crate::handle::{Handle, Managed};
#[cfg(all(feature = "napi-6", feature = "channel-api"))]
#[cfg(feature = "napi-6")]
use crate::lifecycle::InstanceData;
#[cfg(feature = "legacy-runtime")]
use crate::object::class::Class;
Expand All @@ -171,7 +171,7 @@ pub use crate::types::buffer::lock::Lock;
#[cfg(feature = "napi-5")]
use crate::types::date::{DateError, JsDate};
use crate::types::error::JsError;
#[cfg(all(feature = "napi-1", feature = "promise-api"))]
#[cfg(feature = "napi-1")]
use crate::types::{Deferred, JsPromise};
use crate::types::{
JsArray, JsArrayBuffer, JsBoolean, JsBuffer, JsFunction, JsNull, JsNumber, JsObject, JsString,
Expand Down Expand Up @@ -441,8 +441,6 @@ pub trait Context<'a>: ContextInternal<'a> {
result
}

#[cfg(feature = "try-catch-api")]
#[cfg_attr(docsrs, doc(cfg(feature = "try-catch-api")))]
fn try_catch<T, F>(&mut self, f: F) -> Result<T, Handle<'a, JsValue>>
where
F: FnOnce(&mut Self) -> NeonResult<T>,
Expand Down Expand Up @@ -599,8 +597,8 @@ pub trait Context<'a>: ContextInternal<'a> {
JsBox::new(self, v)
}

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "napi-4", feature = "channel-api"))))]
#[cfg(feature = "napi-4")]
#[cfg_attr(docsrs, doc(cfg(feature = "napi-4")))]
/// Returns an unbounded channel for scheduling events to be executed on the JavaScript thread.
///
/// When using N-API >= 6,the channel returned by this method is backed by a shared queue.
Expand All @@ -615,20 +613,12 @@ pub trait Context<'a>: ContextInternal<'a> {
channel
}

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[deprecated(since = "0.9.0", note = "Please use the channel() method instead")]
#[doc(hidden)]
fn queue(&mut self) -> Channel {
self.channel()
}

#[cfg(all(feature = "napi-1", feature = "promise-api"))]
#[cfg_attr(docsrs, doc(cfg(feature = "promise-api")))]
#[cfg(feature = "napi-1")]
/// Creates a [`Deferred`] and [`JsPromise`] pair. The [`Deferred`] handle can be
/// used to resolve or reject the [`JsPromise`].
///
/// ```
/// # #[cfg(all(feature = "napi-1", feature = "promise-api"))] {
/// # #[cfg(feature = "napi-1")] {
/// # use neon::prelude::*;
/// fn resolve_promise(mut cx: FunctionContext) -> JsResult<JsPromise> {
/// let (deferred, promise) = cx.promise();
Expand All @@ -644,14 +634,13 @@ pub trait Context<'a>: ContextInternal<'a> {
JsPromise::new(self)
}

#[cfg(all(feature = "napi-1", feature = "task-api"))]
#[cfg_attr(docsrs, doc(cfg(feature = "task-api")))]
#[cfg(feature = "napi-1")]
/// Creates a [`TaskBuilder`] which can be used to schedule the `execute`
/// callback to asynchronously execute on the
/// [Node worker pool](https://nodejs.org/en/docs/guides/dont-block-the-event-loop/).
///
/// ```
/// # #[cfg(all(feature = "napi-1", feature = "promise-api", feature = "task-api"))] {
/// # #[cfg(feature = "napi-1")] {
/// # use neon::prelude::*;
/// fn greet(mut cx: FunctionContext) -> JsResult<JsPromise> {
/// let name = cx.argument::<JsString>(0)?.value(&mut cx);
Expand Down Expand Up @@ -934,10 +923,7 @@ impl<'a> TaskContext<'a> {
Scope::with(env, |scope| f(TaskContext { scope }))
}

#[cfg(any(
all(feature = "napi-1", feature = "task-api"),
all(feature = "napi-4", feature = "channel-api"),
))]
#[cfg(feature = "napi-1")]
pub(crate) fn with_context<T, F: for<'b> FnOnce(TaskContext<'b>) -> T>(env: Env, f: F) -> T {
Scope::with(env, |scope| f(TaskContext { scope }))
}
Expand Down
4 changes: 2 additions & 2 deletions src/event/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Callback = Box<dyn FnOnce(Env) + Send + 'static>;
/// Ok(cx.undefined())
/// }
/// ```
#[cfg_attr(docsrs, doc(cfg(all(feature = "napi-4", feature = "task-api"))))]
#[cfg_attr(docsrs, doc(cfg(feature = "napi-4")))]
pub struct Channel {
state: Arc<ChannelState>,
has_ref: bool,
Expand Down Expand Up @@ -262,7 +262,7 @@ impl std::error::Error for JoinError {}
//
// NOTE: These docs will need to be updated to include `QueueFull` if bounded queues are
// implemented.
#[cfg_attr(docsrs, doc(cfg(all(feature = "napi-4", feature = "task-api"))))]
#[cfg_attr(docsrs, doc(cfg(feature = "napi-4")))]
pub struct SendError;

impl std::fmt::Display for SendError {
Expand Down
18 changes: 4 additions & 14 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,18 @@
//! [psd-crate]: https://crates.io/crates/psd
//! [psd-file]: https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[cfg(feature = "napi-4")]
mod channel;

#[cfg(all(feature = "napi-1", feature = "task-api"))]
#[cfg(feature = "napi-1")]
mod task;

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[cfg(feature = "napi-4")]
pub use self::channel::{Channel, JoinError, JoinHandle, SendError};

#[cfg(all(feature = "napi-1", feature = "task-api"))]
#[cfg(feature = "napi-1")]
pub use self::task::TaskBuilder;

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[deprecated(since = "0.9.0", note = "Please use the Channel type instead")]
#[doc(hidden)]
pub type EventQueue = self::channel::Channel;

#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[deprecated(since = "0.9.0", note = "Please use the SendError type instead")]
#[doc(hidden)]
pub type EventQueueError = self::channel::SendError;

#[cfg(all(not(feature = "napi-1"), feature = "event-handler-api"))]
mod event_handler;

Expand Down
19 changes: 3 additions & 16 deletions src/event/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,13 @@ use std::thread;
use neon_runtime::{async_work, raw};

use crate::context::{internal::Env, Context, TaskContext};
#[cfg(feature = "promise-api")]
use crate::handle::Handle;
#[cfg(feature = "promise-api")]
use crate::result::JsResult;
use crate::result::NeonResult;
#[cfg(feature = "promise-api")]
use crate::types::Value;
#[cfg(feature = "promise-api")]
use crate::types::{Deferred, JsPromise};

#[cfg_attr(docsrs, doc(cfg(feature = "task-api")))]
use crate::result::{JsResult, NeonResult};
use crate::types::{Deferred, JsPromise, Value};

/// Node asynchronous task builder
///
/// ```
/// # #[cfg(feature = "promise-api")] {
/// # use neon::prelude::*;
/// fn greet(mut cx: FunctionContext) -> JsResult<JsPromise> {
/// let name = cx.argument::<JsString>(0)?.value(&mut cx);
Expand All @@ -29,7 +21,6 @@ use crate::types::{Deferred, JsPromise};
///
/// Ok(promise)
/// }
/// # }
/// ```
pub struct TaskBuilder<'cx, C, E> {
cx: &'cx mut C,
Expand Down Expand Up @@ -61,8 +52,6 @@ where
schedule(env, execute, complete);
}

#[cfg_attr(docsrs, doc(cfg(feature = "promise-api")))]
#[cfg(feature = "promise-api")]
/// Schedules a task to execute on the Node worker pool and returns a
/// promise that is resolved with the value from the `complete` callback.
///
Expand Down Expand Up @@ -120,7 +109,6 @@ where
});
}

#[cfg(feature = "promise-api")]
// Schedule a task to execute on the Node worker pool and settle a `Promise` with the result
fn schedule_promise<I, O, D, V>(env: Env, input: I, complete: D, deferred: Deferred)
where
Expand All @@ -140,7 +128,6 @@ where
}
}

#[cfg(feature = "promise-api")]
fn complete_promise<O, D, V>(
env: raw::Env,
output: thread::Result<O>,
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@
#[cfg(feature = "legacy-runtime")]
pub mod borrow;
pub mod context;
#[cfg(any(
feature = "event-handler-api",
all(feature = "napi-1", feature = "task-api"),
all(feature = "napi-4", feature = "channel-api")
))]
#[cfg(any(feature = "event-handler-api", feature = "napi-1"))]
pub mod event;
pub mod handle;
pub mod meta;
Expand Down
8 changes: 0 additions & 8 deletions src/lifecycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ use neon_runtime::raw::Env;
use neon_runtime::tsfn::ThreadsafeFunction;

use crate::context::Context;
#[cfg(feature = "channel-api")]
use crate::event::Channel;
use crate::handle::root::NapiRef;
#[cfg(feature = "promise-api")]
use crate::types::promise::NodeApiDeferred;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -53,13 +51,11 @@ pub(crate) struct InstanceData {
drop_queue: Arc<ThreadsafeFunction<DropData>>,

/// Shared `Channel` that is cloned to be returned by the `cx.channel()` method
#[cfg(all(feature = "channel-api"))]
shared_channel: Channel,
}

/// Wrapper for raw Node-API values to be dropped on the main thread
pub(crate) enum DropData {
#[cfg(feature = "promise-api")]
Deferred(NodeApiDeferred),
Ref(NapiRef),
}
Expand All @@ -70,7 +66,6 @@ impl DropData {
if let Some(env) = env {
unsafe {
match data {
#[cfg(feature = "promise-api")]
DropData::Deferred(data) => data.leaked(env),
DropData::Ref(data) => data.unref(env),
}
Expand Down Expand Up @@ -101,7 +96,6 @@ impl InstanceData {
queue
};

#[cfg(all(feature = "channel-api"))]
let shared_channel = {
let mut channel = Channel::new(cx);
channel.unref(cx);
Expand All @@ -111,7 +105,6 @@ impl InstanceData {
let data = InstanceData {
id: InstanceId::next(),
drop_queue: Arc::new(drop_queue),
#[cfg(all(feature = "channel-api"))]
shared_channel,
};

Expand All @@ -125,7 +118,6 @@ impl InstanceData {

/// Clones the shared channel and references it since new channels should start
/// referenced, but the shared channel is unreferenced.
#[cfg(all(feature = "channel-api"))]
pub(crate) fn channel<'a, C: Context<'a>>(cx: &mut C) -> Channel {
let mut channel = InstanceData::get(cx).shared_channel.clone();
channel.reference(cx);
Expand Down
8 changes: 2 additions & 6 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ pub use crate::declare_types;
#[cfg(all(not(feature = "napi-1"), feature = "event-handler-api"))]
#[doc(no_inline)]
pub use crate::event::EventHandler;
#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[cfg(feature = "napi-4")]
#[doc(no_inline)]
pub use crate::event::{Channel, SendError};
#[cfg(all(feature = "napi-4", feature = "channel-api"))]
#[doc(no_inline)]
#[allow(deprecated)]
pub use crate::event::{EventQueue, EventQueueError};
#[doc(no_inline)]
pub use crate::handle::Handle;
#[cfg(feature = "legacy-runtime")]
Expand All @@ -37,7 +33,7 @@ pub use crate::task::Task;
#[cfg(feature = "legacy-runtime")]
#[doc(no_inline)]
pub use crate::types::BinaryData;
#[cfg(all(feature = "napi-1", feature = "promise-api"))]
#[cfg(feature = "napi-1")]
#[doc(no_inline)]
pub use crate::types::JsPromise;
#[cfg(feature = "napi-1")]
Expand Down
4 changes: 2 additions & 2 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub mod buffer;
pub(crate) mod date;
pub(crate) mod error;
pub mod function;
#[cfg(all(feature = "napi-1", feature = "promise-api"))]
#[cfg(feature = "napi-1")]
pub(crate) mod promise;

pub(crate) mod private;
Expand Down Expand Up @@ -122,7 +122,7 @@ pub use self::buffer::types::{JsArrayBuffer, JsBuffer, JsTypedArray};
#[cfg(feature = "napi-5")]
pub use self::date::{DateError, DateErrorKind, JsDate};
pub use self::error::JsError;
#[cfg(all(feature = "napi-1", feature = "promise-api"))]
#[cfg(feature = "napi-1")]
pub use self::promise::{Deferred, JsPromise};

pub(crate) fn build<'a, T: Managed, F: FnOnce(&mut raw::Local) -> bool>(
Expand Down
Loading