From 28ee4d14ea887010f8f5cf2ea9b9ea330552e6e1 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 29 Apr 2019 12:57:56 +0200 Subject: [PATCH 1/7] update versions Signed-off-by: Yoshua Wuyts --- Cargo.toml | 8 ++++---- runtime-attributes/Cargo.toml | 4 ++-- runtime-native/Cargo.toml | 4 ++-- runtime-raw/Cargo.toml | 2 +- runtime-tokio/Cargo.toml | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44f36e11..8b80702f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] futures-preview = "0.3.0-alpha.15" -runtime-attributes = { path = "runtime-attributes", version = "0.3.0-alpha.2" } -runtime-raw = { path = "runtime-raw", version = "0.3.0-alpha.1" } -runtime-native = { path = "runtime-native", version = "0.3.0-alpha.1" } +runtime-attributes = { path = "runtime-attributes", version = "0.3.0-alpha.3" } +runtime-raw = { path = "runtime-raw", version = "0.3.0-alpha.2" } +runtime-native = { path = "runtime-native", version = "0.3.0-alpha.2" } [dev-dependencies] failure = "0.1.5" @@ -25,7 +25,7 @@ futures-preview = { version = "0.3.0-alpha.15", features = ["nightly", "async-aw juliex = "0.3.0-alpha.5" mio = "0.6.16" rand = "0.6.5" -runtime-tokio = { path = "runtime-tokio", version = "0.3.0-alpha.1" } +runtime-tokio = { path = "runtime-tokio", version = "0.3.0-alpha.3" } tokio = "0.1.19" [profile.bench] diff --git a/runtime-attributes/Cargo.toml b/runtime-attributes/Cargo.toml index 4f74bd03..4e8228fd 100644 --- a/runtime-attributes/Cargo.toml +++ b/runtime-attributes/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime-attributes" description = "Proc Macro attributes for the Runtime crate." -version = "0.3.0-alpha.2" +version = "0.3.0-alpha.3" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rustasync/runtime" @@ -21,4 +21,4 @@ proc-macro2 = { version = "0.4.29", features = ["nightly"] } quote = "0.6.12" [dev-dependencies] -runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.1" } +runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } diff --git a/runtime-native/Cargo.toml b/runtime-native/Cargo.toml index a57e25dc..858d4089 100644 --- a/runtime-native/Cargo.toml +++ b/runtime-native/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime-native" description = "A cross-platform asynchronous runtime" -version = "0.3.0-alpha.1" +version = "0.3.0-alpha.2" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rustasync/runtime" @@ -17,5 +17,5 @@ async-datagram = "2.2.0" futures-preview = "0.3.0-alpha.15" lazy_static = "1.3.0" romio = "0.3.0-alpha.6" -runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.1" } +runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } juliex = "0.3.0-alpha.5" diff --git a/runtime-raw/Cargo.toml b/runtime-raw/Cargo.toml index cbe437bb..bb918e8d 100644 --- a/runtime-raw/Cargo.toml +++ b/runtime-raw/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime-raw" description = "Traits to implement custom Runtimes." -version = "0.3.0-alpha.1" +version = "0.3.0-alpha.2" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rustasync/runtime" diff --git a/runtime-tokio/Cargo.toml b/runtime-tokio/Cargo.toml index bbf813bd..52662145 100644 --- a/runtime-tokio/Cargo.toml +++ b/runtime-tokio/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime-tokio" description = "A Tokio-based asynchronous runtime" -version = "0.3.0-alpha.2" +version = "0.3.0-alpha.3" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rustasync/runtime" @@ -17,5 +17,5 @@ futures-preview = { version = "0.3.0-alpha.15", features = ["compat", "io-compat futures01 = { package = "futures", version = "0.1" } lazy_static = "1.3.0" mio = "0.6.16" -runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.1" } +runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } tokio = "0.1.19" From e09dda73fc87c5709f012f729874dcc09ce447c1 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 29 Apr 2019 13:02:50 +0200 Subject: [PATCH 2/7] runtime 0.3.0-alpha.3 Signed-off-by: Yoshua Wuyts --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 8b80702f..d3008b43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "runtime" description = "Empowering everyone to build asynchronous software." -version = "0.3.0-alpha.2" +version = "0.3.0-alpha.3" license = "MIT OR Apache-2.0" readme = "README.md" repository = "https://github.com/rustasync/runtime" From 83fea4712a30d889714880d2f484542192a8253a Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 3 May 2019 16:04:09 +0200 Subject: [PATCH 3/7] add wasm32-unknown-unknown support Signed-off-by: Yoshua Wuyts --- runtime-native/Cargo.toml | 9 +++++++- runtime-native/src/lib.rs | 46 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/runtime-native/Cargo.toml b/runtime-native/Cargo.toml index 858d4089..d7d32c8c 100644 --- a/runtime-native/Cargo.toml +++ b/runtime-native/Cargo.toml @@ -16,6 +16,13 @@ edition = "2018" async-datagram = "2.2.0" futures-preview = "0.3.0-alpha.15" lazy_static = "1.3.0" -romio = "0.3.0-alpha.6" runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +romio = "0.3.0-alpha.6" juliex = "0.3.0-alpha.5" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +wasm-bindgen = "0.2.43" +wasm-bindgen-futures = "0.3.20" +futures01 = { package = "futures", version = "0.1" } diff --git a/runtime-native/src/lib.rs b/runtime-native/src/lib.rs index a589676b..0aaca0f9 100644 --- a/runtime-native/src/lib.rs +++ b/runtime-native/src/lib.rs @@ -12,18 +12,29 @@ use futures::prelude::*; use futures::{future::BoxFuture, task::SpawnError}; +#[cfg(not(target_arch = "wasm32"))] use lazy_static::lazy_static; +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::prelude::*; +#[cfg(target_arch = "wasm32")] +use wasm_bindgen_futures::future_to_promise; + use std::io; use std::net::SocketAddr; use std::pin::Pin; +#[cfg(not(target_arch = "wasm32"))] mod tcp; +#[cfg(not(target_arch = "wasm32"))] mod udp; +#[cfg(not(target_arch = "wasm32"))] use tcp::{TcpListener, TcpStream}; +#[cfg(not(target_arch = "wasm32"))] use udp::UdpSocket; +#[cfg(not(target_arch = "wasm32"))] lazy_static! { static ref JULIEX_THREADPOOL: juliex::ThreadPool = { juliex::ThreadPool::with_setup(|| { @@ -36,6 +47,8 @@ lazy_static! { #[derive(Debug)] pub struct Native; +// Unix + Windows +#[cfg(not(target_arch = "wasm32"))] impl runtime_raw::Runtime for Native { fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { JULIEX_THREADPOOL.spawn_boxed(fut.into()); @@ -71,3 +84,36 @@ impl runtime_raw::Runtime for Native { Ok(Box::pin(UdpSocket { romio_socket })) } } + +#[cfg(target_arch = "wasm32")] +impl runtime_raw::Runtime for Native { + fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { + use futures01::future::Future; + let fut = fut.unit_error().compat() + .map(|_| JsValue::undefined()) + .map_err(|_| JsValue::undefined()); + future_to_promise(fut); + Ok(()) + } + + fn connect_tcp_stream( + &self, + _addr: &SocketAddr, + ) -> BoxFuture<'static, io::Result>>> { + panic!("Connecting TCP streams is currently not supported in wasm"); + } + + fn bind_tcp_listener( + &self, + _addr: &SocketAddr, + ) -> io::Result>> { + panic!("Binding TCP listeners is currently not supported in wasm"); + } + + fn bind_udp_socket( + &self, + _addr: &SocketAddr, + ) -> io::Result>> { + panic!("Binding UDP sockets is currently not supported in wasm"); + } +} From 980dee6088e05c4f0a504f7da2c89b9c9a84b886 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 6 May 2019 12:00:43 +0200 Subject: [PATCH 4/7] reorder cfgs Signed-off-by: Yoshua Wuyts --- runtime-native/Cargo.toml | 10 +- runtime-native/src/lib.rs | 106 +-------------------- runtime-native/src/not_wasm32.rs | 61 ++++++++++++ runtime-native/src/{ => not_wasm32}/tcp.rs | 0 runtime-native/src/{ => not_wasm32}/udp.rs | 0 runtime-native/src/wasm32.rs | 48 ++++++++++ 6 files changed, 118 insertions(+), 107 deletions(-) create mode 100644 runtime-native/src/not_wasm32.rs rename runtime-native/src/{ => not_wasm32}/tcp.rs (100%) rename runtime-native/src/{ => not_wasm32}/udp.rs (100%) create mode 100644 runtime-native/src/wasm32.rs diff --git a/runtime-native/Cargo.toml b/runtime-native/Cargo.toml index d7d32c8c..36532c30 100644 --- a/runtime-native/Cargo.toml +++ b/runtime-native/Cargo.toml @@ -13,16 +13,16 @@ categories = ["asynchronous", "network-programming", "filesystem", "concurrency" edition = "2018" [dependencies] -async-datagram = "2.2.0" -futures-preview = "0.3.0-alpha.15" -lazy_static = "1.3.0" +futures-preview = { version = "0.3.0-alpha.15", features = ["compat"] } runtime-raw = { path = "../runtime-raw", version = "0.3.0-alpha.2" } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -romio = "0.3.0-alpha.6" +async-datagram = "2.2.0" juliex = "0.3.0-alpha.5" +lazy_static = "1.3.0" +romio = "0.3.0-alpha.6" [target.'cfg(target_arch = "wasm32")'.dependencies] +futures01 = { package = "futures", version = "0.1" } wasm-bindgen = "0.2.43" wasm-bindgen-futures = "0.3.20" -futures01 = { package = "futures", version = "0.1" } diff --git a/runtime-native/src/lib.rs b/runtime-native/src/lib.rs index 0aaca0f9..5a126085 100644 --- a/runtime-native/src/lib.rs +++ b/runtime-native/src/lib.rs @@ -10,110 +10,12 @@ rust_2018_idioms )] -use futures::prelude::*; -use futures::{future::BoxFuture, task::SpawnError}; -#[cfg(not(target_arch = "wasm32"))] -use lazy_static::lazy_static; - #[cfg(target_arch = "wasm32")] -use wasm_bindgen::prelude::*; +mod wasm32; #[cfg(target_arch = "wasm32")] -use wasm_bindgen_futures::future_to_promise; - -use std::io; -use std::net::SocketAddr; -use std::pin::Pin; - -#[cfg(not(target_arch = "wasm32"))] -mod tcp; -#[cfg(not(target_arch = "wasm32"))] -mod udp; +pub use wasm32::Native; #[cfg(not(target_arch = "wasm32"))] -use tcp::{TcpListener, TcpStream}; -#[cfg(not(target_arch = "wasm32"))] -use udp::UdpSocket; - +mod not_wasm32; #[cfg(not(target_arch = "wasm32"))] -lazy_static! { - static ref JULIEX_THREADPOOL: juliex::ThreadPool = { - juliex::ThreadPool::with_setup(|| { - runtime_raw::set_runtime(&Native); - }) - }; -} - -/// The Native runtime. -#[derive(Debug)] -pub struct Native; - -// Unix + Windows -#[cfg(not(target_arch = "wasm32"))] -impl runtime_raw::Runtime for Native { - fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { - JULIEX_THREADPOOL.spawn_boxed(fut.into()); - Ok(()) - } - - fn connect_tcp_stream( - &self, - addr: &SocketAddr, - ) -> BoxFuture<'static, io::Result>>> { - let romio_connect = romio::TcpStream::connect(addr); - let connect = romio_connect.map(|res| { - res.map(|romio_stream| { - Box::pin(TcpStream { romio_stream }) as Pin> - }) - }); - connect.boxed() - } - - fn bind_tcp_listener( - &self, - addr: &SocketAddr, - ) -> io::Result>> { - let romio_listener = romio::TcpListener::bind(&addr)?; - Ok(Box::pin(TcpListener { romio_listener })) - } - - fn bind_udp_socket( - &self, - addr: &SocketAddr, - ) -> io::Result>> { - let romio_socket = romio::UdpSocket::bind(&addr)?; - Ok(Box::pin(UdpSocket { romio_socket })) - } -} - -#[cfg(target_arch = "wasm32")] -impl runtime_raw::Runtime for Native { - fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { - use futures01::future::Future; - let fut = fut.unit_error().compat() - .map(|_| JsValue::undefined()) - .map_err(|_| JsValue::undefined()); - future_to_promise(fut); - Ok(()) - } - - fn connect_tcp_stream( - &self, - _addr: &SocketAddr, - ) -> BoxFuture<'static, io::Result>>> { - panic!("Connecting TCP streams is currently not supported in wasm"); - } - - fn bind_tcp_listener( - &self, - _addr: &SocketAddr, - ) -> io::Result>> { - panic!("Binding TCP listeners is currently not supported in wasm"); - } - - fn bind_udp_socket( - &self, - _addr: &SocketAddr, - ) -> io::Result>> { - panic!("Binding UDP sockets is currently not supported in wasm"); - } -} +pub use not_wasm32::Native; diff --git a/runtime-native/src/not_wasm32.rs b/runtime-native/src/not_wasm32.rs new file mode 100644 index 00000000..482f4219 --- /dev/null +++ b/runtime-native/src/not_wasm32.rs @@ -0,0 +1,61 @@ +use futures::prelude::*; +use futures::{future::BoxFuture, task::SpawnError}; +use lazy_static::lazy_static; + +use std::io; +use std::net::SocketAddr; +use std::pin::Pin; + +mod tcp; +mod udp; + +use tcp::{TcpListener, TcpStream}; +use udp::UdpSocket; + +lazy_static! { + static ref JULIEX_THREADPOOL: juliex::ThreadPool = { + juliex::ThreadPool::with_setup(|| { + runtime_raw::set_runtime(&Native); + }) + }; +} + +/// The Native runtime. +#[derive(Debug)] +pub struct Native; + +impl runtime_raw::Runtime for Native { + fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { + JULIEX_THREADPOOL.spawn_boxed(fut.into()); + Ok(()) + } + + fn connect_tcp_stream( + &self, + addr: &SocketAddr, + ) -> BoxFuture<'static, io::Result>>> { + let romio_connect = romio::TcpStream::connect(addr); + let connect = romio_connect.map(|res| { + res.map(|romio_stream| { + Box::pin(TcpStream { romio_stream }) as Pin> + }) + }); + connect.boxed() + } + + fn bind_tcp_listener( + &self, + addr: &SocketAddr, + ) -> io::Result>> { + let romio_listener = romio::TcpListener::bind(&addr)?; + Ok(Box::pin(TcpListener { romio_listener })) + } + + fn bind_udp_socket( + &self, + addr: &SocketAddr, + ) -> io::Result>> { + let romio_socket = romio::UdpSocket::bind(&addr)?; + Ok(Box::pin(UdpSocket { romio_socket })) + } +} diff --git a/runtime-native/src/tcp.rs b/runtime-native/src/not_wasm32/tcp.rs similarity index 100% rename from runtime-native/src/tcp.rs rename to runtime-native/src/not_wasm32/tcp.rs diff --git a/runtime-native/src/udp.rs b/runtime-native/src/not_wasm32/udp.rs similarity index 100% rename from runtime-native/src/udp.rs rename to runtime-native/src/not_wasm32/udp.rs diff --git a/runtime-native/src/wasm32.rs b/runtime-native/src/wasm32.rs new file mode 100644 index 00000000..7781051d --- /dev/null +++ b/runtime-native/src/wasm32.rs @@ -0,0 +1,48 @@ +use futures::prelude::*; +use futures::{future::BoxFuture, task::SpawnError}; +// use futures::compat::*; + +use std::io; +use std::net::SocketAddr; +use std::pin::Pin; + +use wasm_bindgen::prelude::*; +use wasm_bindgen_futures::future_to_promise; + +/// The Native runtime. +#[derive(Debug)] +pub struct Native; + +impl runtime_raw::Runtime for Native { + fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { + use futures01::future::Future; + let fut = fut + .unit_error() + .compat() + .map(|_| JsValue::undefined()) + .map_err(|_| JsValue::undefined()); + future_to_promise(fut); + Ok(()) + } + + fn connect_tcp_stream( + &self, + _addr: &SocketAddr, + ) -> BoxFuture<'static, io::Result>>> { + panic!("Connecting TCP streams is currently not supported in wasm"); + } + + fn bind_tcp_listener( + &self, + _addr: &SocketAddr, + ) -> io::Result>> { + panic!("Binding TCP listeners is currently not supported in wasm"); + } + + fn bind_udp_socket( + &self, + _addr: &SocketAddr, + ) -> io::Result>> { + panic!("Binding UDP sockets is currently not supported in wasm"); + } +} From 2869f97281436a25ee8a24a80db3283ae6c324f4 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Tue, 7 May 2019 09:58:14 +0200 Subject: [PATCH 5/7] Update runtime-native/src/wasm32.rs Co-Authored-By: yoshuawuyts --- runtime-native/src/wasm32.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-native/src/wasm32.rs b/runtime-native/src/wasm32.rs index 7781051d..549cf0b6 100644 --- a/runtime-native/src/wasm32.rs +++ b/runtime-native/src/wasm32.rs @@ -21,7 +21,7 @@ impl runtime_raw::Runtime for Native { .compat() .map(|_| JsValue::undefined()) .map_err(|_| JsValue::undefined()); - future_to_promise(fut); + wasm_bindgen_futures::spawn_local(fut); Ok(()) } From d92bad94ba1219432839a2de8214997d4dd27365 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 7 May 2019 10:17:59 +0200 Subject: [PATCH 6/7] wasm-bindgen feature flag Signed-off-by: Yoshua Wuyts --- runtime-native/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime-native/src/lib.rs b/runtime-native/src/lib.rs index 5a126085..f4250298 100644 --- a/runtime-native/src/lib.rs +++ b/runtime-native/src/lib.rs @@ -10,12 +10,12 @@ rust_2018_idioms )] -#[cfg(target_arch = "wasm32")] +#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))] mod wasm32; -#[cfg(target_arch = "wasm32")] +#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))] pub use wasm32::Native; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(feature = "wasm-bindgen", target_arch = "wasm32")))] mod not_wasm32; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(feature = "wasm-bindgen", target_arch = "wasm32")))] pub use not_wasm32::Native; From f0efb383b19594904fef5014c356733b5b89da67 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Wed, 8 May 2019 12:25:14 +0200 Subject: [PATCH 7/7] remove unneeded combinators Signed-off-by: Yoshua Wuyts --- runtime-native/src/wasm32.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/runtime-native/src/wasm32.rs b/runtime-native/src/wasm32.rs index 549cf0b6..907dba95 100644 --- a/runtime-native/src/wasm32.rs +++ b/runtime-native/src/wasm32.rs @@ -16,11 +16,7 @@ pub struct Native; impl runtime_raw::Runtime for Native { fn spawn_boxed(&self, fut: BoxFuture<'static, ()>) -> Result<(), SpawnError> { use futures01::future::Future; - let fut = fut - .unit_error() - .compat() - .map(|_| JsValue::undefined()) - .map_err(|_| JsValue::undefined()); + let fut = fut.unit_error().compat(); wasm_bindgen_futures::spawn_local(fut); Ok(()) }