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

Dev windows support part2 #243

Closed
Closed
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
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,9 @@ jobs:

- target: x86_64-pc-windows-msvc
os: windows-latest
no_run: 1
- target: x86_64-pc-windows-gnu
os: windows-latest
no_run: 1
- target: i686-pc-windows-msvc
os: windows-latest
no_run: 1
- target: i686-pc-windows-gnu
os: windows-latest
no_run: 1
2 changes: 2 additions & 0 deletions examples/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! Run the example and `nc 127.0.0.1 50002` in another shell.
//! All your input will be echoed out.

#[cfg(unix)]
use monoio::{
io::{AsyncReadRent, AsyncWriteRentExt},
net::{TcpListener, TcpStream},
Expand All @@ -28,6 +29,7 @@ async fn main() {
}
}

#[cfg(unix)]
async fn echo(mut stream: TcpStream) -> std::io::Result<()> {
let mut buf: Vec<u8> = Vec::with_capacity(8 * 1024);
let mut res;
Expand Down
3 changes: 2 additions & 1 deletion examples/echo_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! Run the example and `nc 127.0.0.1 50002` in another shell.
//! All your input will be echoed out.

#[cfg(unix)]
use monoio::{
io::{
poll_io::{AsyncReadExt, AsyncWriteExt},
Expand Down Expand Up @@ -30,6 +30,7 @@ async fn main() {
}
}

#[cfg(unix)]
async fn echo(stream: TcpStream) -> std::io::Result<()> {
// Convert completion-based io to poll-based io(which impl tokio::io)
let mut stream = stream.into_poll_io()?;
Expand Down
3 changes: 3 additions & 0 deletions examples/h2_server.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Example for using h2 directly.
//! Example code is modified from https://github.com/hyperium/h2/blob/master/examples/server.rs.

#[cfg(unix)]
use monoio::{
io::IntoPollIo,
net::{TcpListener, TcpStream},
};

#[cfg(unix)]
async fn serve(io: TcpStream) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let io = io.into_poll_io()?;
let mut connection = h2::server::handshake(io).await?;
Expand All @@ -24,6 +26,7 @@ async fn serve(io: TcpStream) -> Result<(), Box<dyn std::error::Error + Send + S
Ok(())
}

#[cfg(unix)]
async fn handle_request(
mut request: http::Request<h2::RecvStream>,
mut respond: h2::server::SendResponse<bytes::Bytes>,
Expand Down
21 changes: 12 additions & 9 deletions examples/hyper_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
//!
//! It will try to fetch http://httpbin.org/ip and print the
//! response.

use std::io::Write;

use bytes::Bytes;
use http_body_util::{BodyExt, Empty};
use hyper::Request;
use monoio::{io::IntoPollIo, net::TcpStream};
use monoio_compat::hyper::MonoioIo;

#[cfg(unix)]
use {
bytes::Bytes,
http_body_util::{BodyExt, Empty},
hyper::Request,
monoio::{io::IntoPollIo, net::TcpStream},
monoio_compat::hyper::MonoioIo,
std::io::Write,
};

#[cfg(unix)]
type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;

#[cfg(unix)]
async fn fetch_url(url: hyper::Uri) -> Result<()> {
let host = url.host().expect("uri has no host");
let port = url.port_u16().unwrap_or(80);
Expand Down
22 changes: 11 additions & 11 deletions examples/hyper_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@
//!
//! After running this example, you can open http://localhost:23300
//! and http://localhost:23300/monoio in your browser or curl it.
#[cfg(unix)]
use {
bytes::Bytes,
futures::Future,
http_body_util::Full,
hyper::{server::conn::http1, service::service_fn, Method, Request, Response, StatusCode},
monoio::{io::IntoPollIo, net::TcpListener},
};

use std::net::SocketAddr;

use bytes::Bytes;
use futures::Future;
use hyper::{server::conn::http1, service::service_fn};
use monoio::{io::IntoPollIo, net::TcpListener};

#[cfg(unix)]
pub(crate) async fn serve_http<S, F, E, A>(addr: A, service: S) -> std::io::Result<()>
where
S: Copy + Fn(Request<hyper::body::Incoming>) -> F + 'static,
F: Future<Output = Result<Response<Full<Bytes>>, E>> + 'static,
E: std::error::Error + 'static + Send + Sync,
A: Into<SocketAddr>,
A: Into<std::net::SocketAddr>,
{
let listener = TcpListener::bind(addr.into())?;
loop {
Expand All @@ -35,9 +37,7 @@ where
}
}

use http_body_util::Full;
use hyper::{Method, Request, Response, StatusCode};

#[cfg(unix)]
async fn hyper_handler(
req: Request<hyper::body::Incoming>,
) -> Result<Response<Full<Bytes>>, std::convert::Infallible> {
Expand Down
1 change: 1 addition & 0 deletions examples/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ async fn main() {
println!("monoio::join two tasks");
}

#[cfg(unix)]
async fn ready_now() -> u8 {
7
}
3 changes: 2 additions & 1 deletion examples/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! An example TCP proxy.

#[cfg(unix)]
use monoio::{
io::{AsyncReadRent, AsyncWriteRent, AsyncWriteRentExt, Splitable},
net::{TcpListener, TcpStream},
Expand Down Expand Up @@ -35,6 +35,7 @@ async fn main() {
}
}

#[cfg(unix)]
async fn copy_one_direction<FROM: AsyncReadRent, TO: AsyncWriteRent>(
mut from: FROM,
to: &mut TO,
Expand Down
13 changes: 8 additions & 5 deletions examples/timer_select.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! An example to illustrate selecting by macro or manually.

use std::{future::Future, pin::pin};

use monoio::{io::Canceller, net::TcpListener, time::Duration};
use pin_project_lite::pin_project;
#[cfg(unix)]
use {
monoio::{io::Canceller, net::TcpListener, time::Duration},
pin_project_lite::pin_project,
std::{future::Future, pin::pin},
};

#[monoio::main(enable_timer = true)]
async fn main() {
Expand Down Expand Up @@ -65,6 +66,7 @@ async fn main() {
}
}

#[cfg(unix)]
pin_project! {
struct DualSelect<F> {
#[pin]
Expand All @@ -74,6 +76,7 @@ pin_project! {
}
}

#[cfg(unix)]
impl<F> Future for DualSelect<F>
where
F: Future<Output = ()>,
Expand Down
2 changes: 1 addition & 1 deletion examples/uds.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A example to show how to use UnixStream.

use local_sync::oneshot::channel;
#[cfg(unix)]
use monoio::{
io::{AsyncReadRent, AsyncWriteRentExt},
net::{UnixListener, UnixStream},
Expand Down
7 changes: 5 additions & 2 deletions monoio-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,19 @@ fn parse_knobs(mut input: syn::ItemFn, is_test: bool, config: FinalConfig) -> To
} else {
quote! {}
};
// todo
// disable some tests in windows, after the features are completed, it is necessary to rollback
// the code here
let cfg_attr = if is_test {
match config.driver {
DriverType::Legacy => quote! {
#[cfg(feature = "legacy")]
#[cfg(all(feature = "legacy", not(windows)))]
},
DriverType::Uring => quote! {
#[cfg(all(target_os = "linux", feature = "iouring"))]
},
DriverType::Fusion => quote! {
#[cfg(any(feature = "legacy", feature = "iouring"))]
#[cfg(all(any(feature = "legacy", feature = "iouring"), not(windows, feature = "sync")))]
},
}
} else {
Expand Down
23 changes: 21 additions & 2 deletions monoio-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod entry;
mod select;

use proc_macro::TokenStream;

#[cfg(unix)]
#[proc_macro_attribute]
pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {
Expand All @@ -19,8 +20,26 @@ pub fn main(args: TokenStream, item: TokenStream) -> TokenStream {

#[cfg(windows)]
#[proc_macro_attribute]
pub fn main(_args: TokenStream, _item: TokenStream) -> TokenStream {
unimplemented!()
pub fn main(_args: TokenStream, func: TokenStream) -> TokenStream {
use quote::quote;
use syn::parse_macro_input;

let func = parse_macro_input!(func as syn::ItemFn);
let func_vis = &func.vis; // like pub

let func_decl = func.sig;
let func_name = &func_decl.ident; // function name
let func_generics = &func_decl.generics;
let func_inputs = &func_decl.inputs;
let _func_output = &func_decl.output;

let caller = quote! {
// rebuild the function
#func_vis fn #func_name #func_generics(#func_inputs) {
println!("macros unimplemented in windows!");
}
};
caller.into()
}

#[proc_macro_attribute]
Expand Down
7 changes: 4 additions & 3 deletions monoio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ once_cell = { version = "1.19.0", optional = true }

# windows dependencies(will be added when windows support finished)
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.48.0", features = [
windows-sys = { version = "0.52.0", features = [
"Win32_Foundation",
"Win32_Networking_WinSock",
"Win32_System_IO",
"Win32_Storage_FileSystem",
"Win32_Security"
] }
polling = { version = "2.8.0", optional = true }

# unix dependencies
[target.'cfg(unix)'.dependencies]
Expand Down Expand Up @@ -78,13 +79,13 @@ utils = ["nix"]
# enable debug if you want to know what runtime does
debug = ["tracing"]
# enable legacy driver support(will make monoio available for older kernel and macOS)
legacy = ["mio"]
legacy = ["mio", "polling", "once_cell"]
# iouring support
iouring = ["io-uring"]
# tokio-compatible(only have effect when legacy is enabled and iouring is not)
tokio-compat = ["tokio"]
# (experimental)enable poll-io to convert structs to structs that impl tokio's poll io
poll-io = ["tokio", "mio"]
poll-io = ["tokio", "mio", "polling"]
# signal enables setting ctrl_c handler
signal = ["ctrlc", "sync"]
signal-termination = ["signal", "ctrlc/termination"]
Expand Down
2 changes: 1 addition & 1 deletion monoio/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ where
}
}

#[cfg(test)]
#[cfg(all(test, not(windows)))]
mod tests {
use super::DefaultThreadPool;

Expand Down
6 changes: 5 additions & 1 deletion monoio/src/buf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ mod raw_buf;
pub use raw_buf::{RawBuf, RawBufVectored};

mod vec_wrapper;
pub(crate) use vec_wrapper::{read_vec_meta, write_vec_meta};
#[allow(unused_imports)]
pub(crate) use vec_wrapper::{read_vec_meta, write_vec_meta, IoVecMeta};

mod msg;
pub use msg::{MsgBuf, MsgBufMut, MsgMeta};

pub(crate) fn deref(buf: &impl IoBuf) -> &[u8] {
// Safety: the `IoBuf` trait is marked as unsafe and is expected to be
Expand Down
Loading
Loading