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 all 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"
3 changes: 2 additions & 1 deletion .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Use npm v8
run: npm install -g npm@8
# https://github.com/npm/cli/issues/4552
run: npm -g i npm@~8.3
- name: install build-essential
run: sudo apt-get install -y build-essential
- name: npm install workspace
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- name: Use npm v8
run: npm install -g npm@8
# https://github.com/npm/cli/issues/4552
run: npm -g i npm@~8.3
- name: npm install workspace
run: npm install
- name: run tests
Expand Down
31 changes: 11 additions & 20 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 @@ -61,39 +64,27 @@ napi-6 = ["napi-5", "neon-runtime/napi-6"]
napi-latest = ["napi-6"]
napi-experimental = ["napi-6", "neon-runtime/napi-experimental"]

# Feature flag to disable external dependencies on docs build
docs-only = ["neon-runtime/docs-only"]

# Feature flag to enable the try_catch API of RFC 29.
# DEPRECATED: These perform no action and will be removed in 1.0
try-catch-api = []

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

# Deprecated name for `channel-api`
event-queue-api = ["channel-api"]
# 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 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
63 changes: 38 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,10 @@ pub trait Context<'a>: ContextInternal<'a> {
result
}

#[cfg(feature = "try-catch-api")]
#[cfg_attr(docsrs, doc(cfg(feature = "try-catch-api")))]
#[cfg_attr(
feature = "try-catch-api",
deprecated = "`try-catch-api` feature has no impact and may be removed"
)]
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 +601,23 @@ 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")]
#[deprecated(since = "0.9.0", note = "Please use the channel() method instead")]
#[doc(hidden)]
fn queue(&mut self) -> Channel {
self.channel()
}

#[cfg(feature = "napi-4")]
#[cfg_attr(
feature = "channel-api",
deprecated = "`channel-api` feature has no impact and may be removed"
)]
#[cfg_attr(
all(not(feature = "channel-api"), feature = "event-queue-api"),
deprecated = "`event-queue-api` feature has no impact and may be removed"
)]
#[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 +632,16 @@ 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")]
#[cfg_attr(
feature = "promise-api",
deprecated = "`promise-api` feature has no impact and may be removed"
)]
/// 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 +657,17 @@ 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")]
#[cfg_attr(
feature = "task-api",
deprecated = "`task-api` feature has no impact and may be removed"
)]
/// 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 +950,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
12 changes: 10 additions & 2 deletions src/event/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ 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(
feature = "channel-api",
deprecated = "`channel-api` feature has no impact and may be removed"
)]
#[cfg_attr(
all(not(feature = "channel-api"), feature = "event-queue-api"),
deprecated = "`event-queue-api` feature has no impact and may be removed"
)]
#[cfg_attr(docsrs, doc(cfg(feature = "napi-4")))]
pub struct Channel {
state: Arc<ChannelState>,
has_ref: bool,
Expand Down Expand Up @@ -262,7 +270,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
12 changes: 6 additions & 6 deletions src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,24 +123,24 @@
//! [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"))]
#[cfg(feature = "napi-4")]
#[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"))]
#[cfg(feature = "napi-4")]
#[deprecated(since = "0.9.0", note = "Please use the SendError type instead")]
#[doc(hidden)]
pub type EventQueueError = self::channel::SendError;
Expand Down
23 changes: 7 additions & 16 deletions src/event/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ 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};

#[cfg_attr(
feature = "task-api",
deprecated = "`task-api` feature has no impact and may be removed"
)]
/// 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 +25,6 @@ use crate::types::{Deferred, JsPromise};
///
/// Ok(promise)
/// }
/// # }
/// ```
pub struct TaskBuilder<'cx, C, E> {
cx: &'cx mut C,
Expand Down Expand Up @@ -61,8 +56,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 +113,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 +132,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
Loading