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 <luciofranco14@gmail.com>
This commit is contained in:
Johan Andersson
2020-01-11 23:16:54 +01:00
committed 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 }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable]
env:
@@ -44,7 +44,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable]
env:
+8 -1
View File
@@ -1,4 +1,4 @@
#[cfg(unix)]
#![cfg_attr(not(unix), allow(unused_imports))]
pub mod hello_world {
tonic::include_proto!("helloworld");
@@ -7,10 +7,12 @@ pub mod hello_world {
use hello_world::{greeter_client::GreeterClient, HelloRequest};
use http::Uri;
use std::convert::TryFrom;
#[cfg(unix)]
use tokio::net::UnixStream;
use tonic::transport::Endpoint;
use tower::service_fn;
#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// 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(())
}
#[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 std::{
path::Path,
pin::Pin,
task::{Context, Poll},
};
use tokio::{
io::{AsyncRead, AsyncWrite},
net::UnixListener,
};
use tonic::{
transport::{server::Connected, Server},
Request, Response, Status,
};
use std::path::Path;
#[cfg(unix)]
use tokio::net::UnixListener;
use tonic::{transport::Server, Request, Response, Status};
pub mod hello_world {
tonic::include_proto!("helloworld");
@@ -40,6 +33,7 @@ impl Greeter for MyGreeter {
}
}
#[cfg(unix)]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let path = "/tmp/tonic/helloworld";
@@ -52,41 +46,60 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
Server::builder()
.add_service(GreeterServer::new(greeter))
.serve_with_incoming(uds.incoming().map_ok(UnixStream))
.serve_with_incoming(uds.incoming().map_ok(unix::UnixStream))
.await?;
Ok(())
}
#[derive(Debug)]
struct UnixStream(tokio::net::UnixStream);
#[cfg(unix)]
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 {
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)
#[derive(Debug)]
pub struct UnixStream(pub tokio::net::UnixStream);
impl Connected for UnixStream {}
impl AsyncRead for UnixStream {
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 {
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)
}
#[cfg(not(unix))]
fn main() {
panic!("The `uds` example only works on unix systems!");
}