Run CI checks & tests on Windows and Mac (#206)

* Run CI checks & tests on Windows and Mac

* Fix uds windows compile

Co-authored-by: Lucio Franco <[email protected]>
This commit is contained in:
Johan Andersson
2020-01-11 14:16:54 -08:00
committed by Lucio Franco
co-authored by Lucio Franco
parent 6673f91f1f
commit 3be8bc1668
3 changed files with 63 additions and 43 deletions
+2 -2
View File
@@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable] rust: [stable]
env: env:
@@ -44,7 +44,7 @@ jobs:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable] rust: [stable]
env: env:
+8 -1
View File
@@ -1,4 +1,4 @@
#[cfg(unix)] #![cfg_attr(not(unix), allow(unused_imports))]
pub mod hello_world { pub mod hello_world {
tonic::include_proto!("helloworld"); tonic::include_proto!("helloworld");
@@ -7,10 +7,12 @@ pub mod hello_world {
use hello_world::{greeter_client::GreeterClient, HelloRequest}; use hello_world::{greeter_client::GreeterClient, HelloRequest};
use http::Uri; use http::Uri;
use std::convert::TryFrom; use std::convert::TryFrom;
#[cfg(unix)]
use tokio::net::UnixStream; use tokio::net::UnixStream;
use tonic::transport::Endpoint; use tonic::transport::Endpoint;
use tower::service_fn; use tower::service_fn;
#[cfg(unix)]
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
// We will ignore this uri because uds do not use it // We will ignore this uri because uds do not use it
@@ -37,3 +39,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Ok(()) Ok(())
} }
#[cfg(not(unix))]
fn main() {
panic!("The `uds` example only works on unix systems!");
}
+53 -40
View File
@@ -1,17 +1,10 @@
#![cfg_attr(not(unix), allow(unused_imports))]
use futures::stream::TryStreamExt; use futures::stream::TryStreamExt;
use std::{ use std::path::Path;
path::Path, #[cfg(unix)]
pin::Pin, use tokio::net::UnixListener;
task::{Context, Poll}, use tonic::{transport::Server, Request, Response, Status};
};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::UnixListener,
};
use tonic::{
transport::{server::Connected, Server},
Request, Response, Status,
};
pub mod hello_world { pub mod hello_world {
tonic::include_proto!("helloworld"); tonic::include_proto!("helloworld");
@@ -40,6 +33,7 @@ impl Greeter for MyGreeter {
} }
} }
#[cfg(unix)]
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = "/tmp/tonic/helloworld"; let path = "/tmp/tonic/helloworld";
@@ -52,41 +46,60 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::builder() Server::builder()
.add_service(GreeterServer::new(greeter)) .add_service(GreeterServer::new(greeter))
.serve_with_incoming(uds.incoming().map_ok(UnixStream)) .serve_with_incoming(uds.incoming().map_ok(unix::UnixStream))
.await?; .await?;
Ok(()) Ok(())
} }
#[derive(Debug)] #[cfg(unix)]
struct UnixStream(tokio::net::UnixStream); mod unix {
use std::{
pin::Pin,
task::{Context, Poll},
};
impl Connected for UnixStream {} use tokio::io::{AsyncRead, AsyncWrite};
use tonic::transport::server::Connected;
impl AsyncRead for UnixStream { #[derive(Debug)]
fn poll_read( pub struct UnixStream(pub tokio::net::UnixStream);
mut self: Pin<&mut Self>,
cx: &mut Context<'_>, impl Connected for UnixStream {}
buf: &mut [u8],
) -> Poll<std::io::Result<usize>> { impl AsyncRead for UnixStream {
Pin::new(&mut self.0).poll_read(cx, buf) fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<std::io::Result<usize>> {
Pin::new(&mut self.0).poll_read(cx, buf)
}
}
impl AsyncWrite for UnixStream {
fn poll_write(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
Pin::new(&mut self.0).poll_write(cx, buf)
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_flush(cx)
}
fn poll_shutdown(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}
} }
} }
impl AsyncWrite for UnixStream { #[cfg(not(unix))]
fn poll_write( fn main() {
mut self: Pin<&mut Self>, panic!("The `uds` example only works on unix systems!");
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<std::io::Result<usize>> {
Pin::new(&mut self.0).poll_write(cx, buf)
}
fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_flush(cx)
}
fn poll_shutdown(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_shutdown(cx)
}
} }