Skip to content

Commit

Permalink
Run CI checks & tests on Windows and Mac (#206)
Browse files Browse the repository at this point in the history
* Run CI checks & tests on Windows and Mac

* Fix uds windows compile

Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
  • Loading branch information
repi and LucioFranco committed Jan 11, 2020
1 parent 6673f91 commit 3be8bc1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable]

env:
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
rust: [stable]

env:
Expand Down
9 changes: 8 additions & 1 deletion examples/src/uds/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(unix)]
#![cfg_attr(not(unix), allow(unused_imports))]

pub mod hello_world {
tonic::include_proto!("helloworld");
Expand All @@ -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
Expand All @@ -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!");
}
95 changes: 54 additions & 41 deletions examples/src/uds/server.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -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";
Expand All @@ -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);

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)
#[cfg(unix)]
mod unix {
use std::{
pin::Pin,
task::{Context, Poll},
};

use tokio::io::{AsyncRead, AsyncWrite};
use tonic::transport::server::Connected;

#[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)
}
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<std::io::Result<()>> {
Pin::new(&mut self.0).poll_flush(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)
}
}
}

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!");
}

0 comments on commit 3be8bc1

Please sign in to comment.