Skip to content

Commit

Permalink
Allow to skip runtime feature for clippy run
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Oct 17, 2024
1 parent dedb7de commit e9fa7b8
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 9 deletions.
4 changes: 4 additions & 0 deletions ntex-rt/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## [0.4.20] - 2024-10-17

* Allow to skip runtime feature for clippy run

## [0.4.19] - 2024-10-11

* Force runtime feature selection
Expand Down
2 changes: 1 addition & 1 deletion ntex-rt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ntex-rt"
version = "0.4.19"
version = "0.4.20"
authors = ["ntex contributors <team@ntex.rs>"]
description = "ntex runtime"
keywords = ["network", "framework", "async", "futures"]
Expand Down
25 changes: 17 additions & 8 deletions ntex-rt/build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
use std::{collections::HashSet, env};

fn main() {
let mut clippy = false;
let mut features = HashSet::<&'static str>::default();

for (key, _val) in env::vars() {
for (key, val) in env::vars() {
let _ = match key.as_ref() {
"CARGO_FEATURE_COMPIO" => features.insert("compio"),
"CARGO_FEATURE_TOKIO" => features.insert("tokio"),
"CARGO_FEATURE_GLOMMIO" => features.insert("glommio"),
"CARGO_FEATURE_ASYNC_STD" => features.insert("async-std"),
"CARGO_CFG_FEATURE" => {
if val.contains("cargo-clippy") {
clippy = true;
}
false
}
_ => false,
};
}

if features.is_empty() {
panic!("Runtime must be selected '--feature=ntex/$runtime', available options are \"compio\", \"tokio\", \"async-std\", \"glommio\"");
} else if features.len() > 1 {
panic!(
"Only one runtime feature could be selected, current selection {:?}",
features
);
if !clippy {
if features.is_empty() {
panic!("Runtime must be selected '--feature=ntex/$runtime', available options are \"compio\", \"tokio\", \"async-std\", \"glommio\"");
} else if features.len() > 1 {
panic!(
"Only one runtime feature could be selected, current selection {:?}",
features
);
}
}
}
73 changes: 73 additions & 0 deletions ntex-rt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,76 @@ pub use self::glommio::*;

#[cfg(feature = "compio")]
pub use self::compio::*;

#[allow(dead_code)]
#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "compio"),
not(feature = "glommio")
))]
mod no_rt {
use std::task::{Context, Poll};
use std::{fmt, future::Future, marker::PhantomData, pin::Pin};

/// Runs the provided future, blocking the current thread until the future
/// completes.
pub fn block_on<F: Future<Output = ()>>(_: F) {
panic!("async runtime is not configured");
}

pub fn spawn<F>(_: F) -> JoinHandle<F::Output>
where
F: Future + 'static,
{
unimplemented!()
}

pub fn spawn_blocking<F, T>(_: F) -> JoinHandle<T>
where
F: FnOnce() -> T + Send + Sync + 'static,
T: Send + 'static,
{
unimplemented!()
}

/// Blocking operation completion future. It resolves with results
/// of blocking function execution.
#[allow(clippy::type_complexity)]
pub struct JoinHandle<T> {
t: PhantomData<T>,
}

impl<T> JoinHandle<T> {
pub fn is_finished(&self) -> bool {
true
}
}

impl<T> Future for JoinHandle<T> {
type Output = Result<T, JoinError>;

fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Self::Output> {
todo!()
}
}

#[derive(Debug, Copy, Clone)]
pub struct JoinError;

impl fmt::Display for JoinError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "JoinError")
}
}

impl std::error::Error for JoinError {}
}

#[cfg(all(
not(feature = "tokio"),
not(feature = "async-std"),
not(feature = "compio"),
not(feature = "glommio")
))]
pub use self::no_rt::*;

0 comments on commit e9fa7b8

Please sign in to comment.