From 3f0058d5fa2b1177d5f83954bbac0f392d38f621 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 14:23:45 -0500 Subject: [PATCH 1/9] chore: Update `tonic` and `prost` dependencies to latest --- Cargo.toml | 10 +++++----- crates/client/Cargo.toml | 1 + crates/client/src/lib.rs | 33 +++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8733101e5..c77450115 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,9 +35,9 @@ nix = "0.29" oci-spec = "0.6" os_pipe = "1.1" prctl = "1.0.0" -prost = "0.12" -prost-build = "0.12" -prost-types = "0.12" +prost = "0.13" +prost-build = "0.13" +prost-types = "0.13" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" simple_logger = { version = "5.0", default-features = false } @@ -45,7 +45,7 @@ tempfile = "3.6" thiserror = "1.0" time = { version = "0.3.29", features = ["serde", "std", "formatting"] } tokio = "1.26" -tonic = "0.11" -tonic-build = "0.11" +tonic = "0.12" +tonic-build = "0.12" tower = "0.4" uuid = { version = "1.0", features = ["v4"] } diff --git a/crates/client/Cargo.toml b/crates/client/Cargo.toml index 9616e08d7..d89af8bf5 100644 --- a/crates/client/Cargo.toml +++ b/crates/client/Cargo.toml @@ -23,6 +23,7 @@ name = "version" path = "examples/version.rs" [dependencies] +hyper-util = "0.1.6" # https://github.com/hyperium/hyper/issues/3110 prost.workspace = true prost-types.workspace = true tokio = { workspace = true, optional = true } diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 74dd798da..590d42dbb 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -86,23 +86,28 @@ pub async fn connect( let path = path.as_ref().to_path_buf(); - // Taken from https://github.com/hyperium/tonic/blob/eeb3268f71ae5d1107c937392389db63d8f721fb/examples/src/uds/client.rs#L19 + // Taken from https://github.com/hyperium/tonic/blob/71fca362d7ffbb230547f23b3f2fb75c414063a8/examples/src/uds/client.rs#L21-L28 // There will ignore this uri because uds do not use it // and make connection with UnixStream::connect. - let channel = Endpoint::try_from("http://[::]") - .unwrap() + let channel = Endpoint::try_from("http://[::]")? .connect_with_connector(tower::service_fn(move |_| { - #[cfg(unix)] - { - tokio::net::UnixStream::connect(path.clone()) - } - - #[cfg(windows)] - { - let client = tokio::net::windows::named_pipe::ClientOptions::new() - .open(path.clone()) - .map_err(|e| std::io::Error::from(e)); - async move { client } + let path = path.clone(); + + async move { + #[cfg(unix)] + { + Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new( + tokio::net::UnixStream::connect(path).await?, + )) + } + + #[cfg(windows)] + { + let client = tokio::net::windows::named_pipe::ClientOptions::new() + .open(path) + .map_err(|e| std::io::Error::from(e)); + client.await + } } })) .await?; From 257de235314a8f9766b440e948d484b95d9e96cf Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 14:36:10 -0500 Subject: [PATCH 2/9] fix: Windows client is not awaitable --- crates/client/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 590d42dbb..4b6d46f5a 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -103,10 +103,9 @@ pub async fn connect( #[cfg(windows)] { - let client = tokio::net::windows::named_pipe::ClientOptions::new() + tokio::net::windows::named_pipe::ClientOptions::new() .open(path) - .map_err(|e| std::io::Error::from(e)); - client.await + .map_err(|e| std::io::Error::from(e)) } } })) From c766cdb3c0cfcf4f9fc2c55b1485eedd60b880f4 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 16:17:57 -0500 Subject: [PATCH 3/9] chore: Revert change to windows target --- crates/client/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 4b6d46f5a..7d8b28668 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -103,9 +103,10 @@ pub async fn connect( #[cfg(windows)] { - tokio::net::windows::named_pipe::ClientOptions::new() - .open(path) - .map_err(|e| std::io::Error::from(e)) + let client = tokio::net::windows::named_pipe::ClientOptions::new() + .open(path.clone()) + .map_err(|e| std::io::Error::from(e)); + async move { client } } } })) From b592c76c20b1862a63f953aecc5c5f43b2efecfb Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 21:07:37 -0500 Subject: [PATCH 4/9] Update lib.rs Co-authored-by: James Sturtevant Signed-off-by: Bryant Biggs --- crates/client/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 7d8b28668..7b6d2976c 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -103,10 +103,11 @@ pub async fn connect( #[cfg(windows)] { - let client = tokio::net::windows::named_pipe::ClientOptions::new() - .open(path.clone()) - .map_err(|e| std::io::Error::from(e)); - async move { client } + let client = tokio::net::windows::named_pipe::ClientOptions::new() + .open(&path) + .map_err(|e| std::io::Error::from(e))?; + + Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new(client)) } } })) From 6ef21cc46e646b89a5188a85aa3b239c6d1a3720 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 2 Aug 2024 21:20:30 -0500 Subject: [PATCH 5/9] chore: Run `cargo fmt` --- crates/client/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index 7b6d2976c..89f3a80e3 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -103,11 +103,11 @@ pub async fn connect( #[cfg(windows)] { - let client = tokio::net::windows::named_pipe::ClientOptions::new() - .open(&path) - .map_err(|e| std::io::Error::from(e))?; - - Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new(client)) + let client = tokio::net::windows::named_pipe::ClientOptions::new() + .open(&path) + .map_err(|e| std::io::Error::from(e))?; + + Ok::<_, std::io::Error>(hyper_util::rt::TokioIo::new(client)) } } })) From 07715a425525fd672640db0c3d89463e2ab2d1ec Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Wed, 11 Sep 2024 18:12:13 -0500 Subject: [PATCH 6/9] fix: Correct lint warnings, bump toolchain version due to `cargo::key=value` build directive which is reserved for future use --- crates/runc/src/utils.rs | 1 + crates/shim/src/args.rs | 2 +- crates/shim/src/lib.rs | 2 -- rust-toolchain.toml | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/runc/src/utils.rs b/crates/runc/src/utils.rs index 750a116ae..15596fe09 100644 --- a/crates/runc/src/utils.rs +++ b/crates/runc/src/utils.rs @@ -98,6 +98,7 @@ pub async fn write_value_to_temp_file(value: &T) -> Result>(args: &[S]) -> Result { }) .map_err(|e| Error::InvalidArgument(e.to_string()))?; - if let Some(action) = args.get(0) { + if let Some(action) = args.first() { flags.action = action.into(); } diff --git a/crates/shim/src/lib.rs b/crates/shim/src/lib.rs index 5f447bd76..d428fd82f 100644 --- a/crates/shim/src/lib.rs +++ b/crates/shim/src/lib.rs @@ -94,14 +94,12 @@ macro_rules! cfg_async { } cfg_not_async! { - pub use crate::synchronous::*; pub use crate::synchronous::publisher; pub use protos::shim::shim_ttrpc::Task; pub use protos::ttrpc::TtrpcContext; } cfg_async! { - pub use crate::asynchronous::*; pub use crate::asynchronous::publisher; pub use protos::shim_async::Task; pub use protos::ttrpc::r#async::TtrpcContext; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 23dbc5c8e..db3e0d02f 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.74" +channel = "1.77" components = ["rustfmt", "clippy", "llvm-tools"] From 0e5c8cbbc451880d7962f8282c1fb310a2d54677 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Wed, 11 Sep 2024 20:21:22 -0500 Subject: [PATCH 7/9] fix: Switch `write` to `write_all` to consume --- crates/shim/src/sys/windows/named_pipe_logger.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/shim/src/sys/windows/named_pipe_logger.rs b/crates/shim/src/sys/windows/named_pipe_logger.rs index 1121c5f1c..018309843 100644 --- a/crates/shim/src/sys/windows/named_pipe_logger.rs +++ b/crates/shim/src/sys/windows/named_pipe_logger.rs @@ -100,7 +100,7 @@ impl log::Log for NamedPipeLogger { .current_connection .lock() .unwrap() - .write(message.as_bytes()) + .write_all(message.as_bytes()) { Ok(_) => {} Err(ref e) if e.kind() == io::ErrorKind::Interrupted => { From 7c45ccae1a72afa7072179cd3efaf8c828449545 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 4 Oct 2024 09:41:23 -0500 Subject: [PATCH 8/9] fix: Replace `tonic` deprecated methods to fix clippy warnings --- crates/client/build.rs | 2 +- crates/snapshots/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/client/build.rs b/crates/client/build.rs index 941bee0d9..2c52cb206 100644 --- a/crates/client/build.rs +++ b/crates/client/build.rs @@ -70,7 +70,7 @@ fn main() { tonic_build::configure() .build_server(false) - .compile_with_config(config, PROTO_FILES, &["vendor/"]) + .compile_protos_with_config(config, PROTO_FILES, &["vendor/"]) .expect("Failed to generate GRPC bindings"); for module in FIXUP_MODULES { diff --git a/crates/snapshots/build.rs b/crates/snapshots/build.rs index c6785fa77..862f2206d 100644 --- a/crates/snapshots/build.rs +++ b/crates/snapshots/build.rs @@ -26,7 +26,7 @@ const FIXUP_MODULES: &[&str] = &["containerd.services.snapshots.v1"]; fn main() { tonic_build::configure() .build_server(true) - .compile(PROTO_FILES, &["vendor/"]) + .compile_protos(PROTO_FILES, &["vendor/"]) .expect("Failed to generate GRPC bindings"); for module in FIXUP_MODULES { From af86309813b5ba0e64f7edefa390fcac1d7c0981 Mon Sep 17 00:00:00 2001 From: Bryant Biggs Date: Fri, 4 Oct 2024 14:52:16 +0000 Subject: [PATCH 9/9] fix: All unused re-export to pass clippy --- crates/shim/src/sys/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/shim/src/sys/mod.rs b/crates/shim/src/sys/mod.rs index 3f98c21ec..6972b7677 100644 --- a/crates/shim/src/sys/mod.rs +++ b/crates/shim/src/sys/mod.rs @@ -17,4 +17,5 @@ #[cfg(windows)] pub(crate) mod windows; #[cfg(windows)] +#[allow(unused_imports)] pub use crate::sys::windows::NamedPipeLogger;