From bff2e1298783f9571d4b1c7be8950c5a60a0b17e Mon Sep 17 00:00:00 2001 From: Ottatop Date: Tue, 16 Jul 2024 14:53:52 -0500 Subject: [PATCH] Update dependencies, api/lua: Fix log source --- Cargo.lock | 368 ++++++++++++++++++++++++++++++++++----- Cargo.toml | 8 +- api/lua/pinnacle/log.lua | 46 ++--- api/rust/Cargo.toml | 1 + api/rust/src/lib.rs | 11 +- snowcap | 2 +- src/api.rs | 21 ++- src/api/layout.rs | 41 ++--- src/api/signal.rs | 8 - 9 files changed, 379 insertions(+), 127 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d4da810..ca3140a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,13 +291,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" dependencies = [ "async-trait", - "axum-core", + "axum-core 0.3.4", "bitflags 1.3.2", "bytes", "futures-util", - "http", - "http-body", - "hyper", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", "itoa", "matchit", "memchr", @@ -306,7 +306,34 @@ dependencies = [ "pin-project-lite", "rustversion", "serde", - "sync_wrapper", + "sync_wrapper 0.1.2", + "tower", + "tower-layer", + "tower-service", +] + +[[package]] +name = "axum" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" +dependencies = [ + "async-trait", + "axum-core 0.4.3", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "rustversion", + "serde", + "sync_wrapper 1.0.1", "tower", "tower-layer", "tower-service", @@ -321,14 +348,34 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http", - "http-body", + "http 0.2.12", + "http-body 0.4.6", "mime", "rustversion", "tower-layer", "tower-service", ] +[[package]] +name = "axum-core" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" +dependencies = [ + "async-trait", + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "mime", + "pin-project-lite", + "rustversion", + "sync_wrapper 0.1.2", + "tower-layer", + "tower-service", +] + [[package]] name = "backtrace" version = "0.3.73" @@ -350,6 +397,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "bit-set" version = "0.5.3" @@ -1595,7 +1648,26 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http", + "http 0.2.12", + "indexmap 2.2.6", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "h2" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http 1.1.0", "indexmap 2.2.6", "slab", "tokio", @@ -1679,6 +1751,17 @@ dependencies = [ "itoa", ] +[[package]] +name = "http" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + [[package]] name = "http-body" version = "0.4.6" @@ -1686,7 +1769,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", - "http", + "http 0.2.12", + "pin-project-lite", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http 1.1.0", +] + +[[package]] +name = "http-body-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +dependencies = [ + "bytes", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", "pin-project-lite", ] @@ -1712,9 +1818,9 @@ dependencies = [ "futures-channel", "futures-core", "futures-util", - "h2", - "http", - "http-body", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", "httparse", "httpdate", "itoa", @@ -1726,18 +1832,72 @@ dependencies = [ "want", ] +[[package]] +name = "hyper" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "h2 0.4.5", + "http 1.1.0", + "http-body 1.0.1", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + [[package]] name = "hyper-timeout" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" dependencies = [ - "hyper", + "hyper 0.14.30", "pin-project-lite", "tokio", "tokio-io-timeout", ] +[[package]] +name = "hyper-timeout" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" +dependencies = [ + "hyper 1.4.1", + "hyper-util", + "pin-project-lite", + "tokio", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab92f4f49ee4fb4f997c784b7a2e0fa70050211e0b6a287f898c3c9785ca956" +dependencies = [ + "bytes", + "futures-channel", + "futures-util", + "http 1.1.0", + "http-body 1.0.1", + "hyper 1.4.1", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", +] + [[package]] name = "iana-time-zone" version = "0.1.60" @@ -2271,9 +2431,9 @@ name = "lua-build" version = "0.1.0" dependencies = [ "indexmap 2.2.6", - "prost", - "prost-build", - "prost-types", + "prost 0.12.6", + "prost-build 0.12.6", + "prost-types 0.12.6", "walkdir", ] @@ -3056,7 +3216,7 @@ dependencies = [ "pinnacle", "pinnacle-api", "pinnacle-api-defs", - "prost", + "prost 0.13.1", "serde", "shellexpand", "smithay", @@ -3071,8 +3231,8 @@ dependencies = [ "tokio", "tokio-stream", "toml", - "tonic", - "tonic-reflection", + "tonic 0.12.0", + "tonic-reflection 0.12.0", "tracing", "tracing-appender", "tracing-subscriber", @@ -3089,6 +3249,7 @@ version = "0.0.2" dependencies = [ "bitflags 2.6.0", "futures", + "hyper-util", "indexmap 2.2.6", "num_enum", "pinnacle-api-defs", @@ -3097,7 +3258,7 @@ dependencies = [ "snowcap-api", "tokio", "tokio-stream", - "tonic", + "tonic 0.12.0", "tower", "tracing", "tracing-subscriber", @@ -3109,9 +3270,9 @@ name = "pinnacle-api-defs" version = "0.0.1" dependencies = [ "const_format", - "prost", - "tonic", - "tonic-build", + "prost 0.13.1", + "tonic 0.12.0", + "tonic-build 0.12.0", ] [[package]] @@ -3235,7 +3396,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.12.6", +] + +[[package]] +name = "prost" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13db3d3fde688c61e2446b4d843bc27a7e8af269a69440c0308021dc92333cc" +dependencies = [ + "bytes", + "prost-derive 0.13.1", ] [[package]] @@ -3252,8 +3423,29 @@ dependencies = [ "once_cell", "petgraph", "prettyplease", - "prost", - "prost-types", + "prost 0.12.6", + "prost-types 0.12.6", + "regex", + "syn 2.0.71", + "tempfile", +] + +[[package]] +name = "prost-build" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb182580f71dd070f88d01ce3de9f4da5021db7115d2e1c3605a754153b77c1" +dependencies = [ + "bytes", + "heck", + "itertools", + "log", + "multimap", + "once_cell", + "petgraph", + "prettyplease", + "prost 0.13.1", + "prost-types 0.13.1", "regex", "syn 2.0.71", "tempfile", @@ -3272,13 +3464,35 @@ dependencies = [ "syn 2.0.71", ] +[[package]] +name = "prost-derive" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18bec9b0adc4eba778b33684b7ba3e7137789434769ee3ce3930463ef904cfca" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 2.0.71", +] + [[package]] name = "prost-types" version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ - "prost", + "prost 0.12.6", +] + +[[package]] +name = "prost-types" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee5168b05f49d4b0ca581206eb14a7b22fafd963efe729ac48eb03266e25cc2" +dependencies = [ + "prost 0.13.1", ] [[package]] @@ -3862,15 +4076,15 @@ dependencies = [ "iced_futures", "iced_runtime", "iced_wgpu", - "prost", + "prost 0.12.6", "raw-window-handle", "smithay-client-toolkit 0.19.2", "smithay-clipboard", "snowcap-api-defs", "tokio", "tokio-stream", - "tonic", - "tonic-reflection", + "tonic 0.11.0", + "tonic-reflection 0.11.0", "tracing", "tracing-subscriber", "xdg", @@ -3887,7 +4101,7 @@ dependencies = [ "thiserror", "tokio", "tokio-stream", - "tonic", + "tonic 0.11.0", "tower", "tracing", "xdg", @@ -3898,9 +4112,9 @@ dependencies = [ name = "snowcap-api-defs" version = "0.1.0" dependencies = [ - "prost", - "tonic", - "tonic-build", + "prost 0.12.6", + "tonic 0.11.0", + "tonic-build 0.11.0", "walkdir", ] @@ -4025,6 +4239,12 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "sync_wrapper" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" + [[package]] name = "sys-locale" version = "0.3.1" @@ -4344,17 +4564,47 @@ checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" dependencies = [ "async-stream", "async-trait", - "axum", - "base64", + "axum 0.6.20", + "base64 0.21.7", "bytes", - "h2", - "http", - "http-body", - "hyper", - "hyper-timeout", + "h2 0.3.26", + "http 0.2.12", + "http-body 0.4.6", + "hyper 0.14.30", + "hyper-timeout 0.4.1", "percent-encoding", "pin-project", - "prost", + "prost 0.12.6", + "tokio", + "tokio-stream", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tonic" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f738b6a169a29bca4e39656db89c44a08e09c5b700b896ee9e7459f0652e81dd" +dependencies = [ + "async-stream", + "async-trait", + "axum 0.7.5", + "base64 0.22.1", + "bytes", + "h2 0.4.5", + "http 1.1.0", + "http-body 1.0.1", + "http-body-util", + "hyper 1.4.1", + "hyper-timeout 0.5.1", + "hyper-util", + "percent-encoding", + "pin-project", + "prost 0.13.1", + "socket2", "tokio", "tokio-stream", "tower", @@ -4371,7 +4621,20 @@ checksum = "be4ef6dd70a610078cb4e338a0f79d06bc759ff1b22d2120c2ff02ae264ba9c2" dependencies = [ "prettyplease", "proc-macro2", - "prost-build", + "prost-build 0.12.6", + "quote", + "syn 2.0.71", +] + +[[package]] +name = "tonic-build" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "690943cc223adcdd67bb597a2e573ead1b88e999ba37528fe8e6356bf44b29b6" +dependencies = [ + "prettyplease", + "proc-macro2", + "prost-build 0.13.1", "quote", "syn 2.0.71", ] @@ -4382,11 +4645,24 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "548c227bd5c0fae5925812c4ec6c66ffcfced23ea370cb823f4d18f0fc1cb6a7" dependencies = [ - "prost", - "prost-types", + "prost 0.12.6", + "prost-types 0.12.6", "tokio", "tokio-stream", - "tonic", + "tonic 0.11.0", +] + +[[package]] +name = "tonic-reflection" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e0d3c6688e3b0be22d877b9c6ba86a7c5409e6b505ec8f7c99f026ae09530a" +dependencies = [ + "prost 0.13.1", + "prost-types 0.13.1", + "tokio", + "tokio-stream", + "tonic 0.12.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index ae97585..e12535f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,10 +18,10 @@ repository = "https://github.com/pinnacle-comp/pinnacle/" tokio = { version = "1.38.0", features = ["macros", "rt-multi-thread"]} tokio-stream = { version = "0.1.15", features = ["net"] } # gRPC -prost = "0.12.6" -tonic = "0.11.0" -tonic-reflection = "0.11.0" -tonic-build = "0.11.0" +prost = "0.13.1" +tonic = "0.12.0" +tonic-reflection = "0.12.0" +tonic-build = "0.12.0" # Tracing tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter", "registry"] } diff --git a/api/lua/pinnacle/log.lua b/api/lua/pinnacle/log.lua index 7c35535..63e9146 100644 --- a/api/lua/pinnacle/log.lua +++ b/api/lua/pinnacle/log.lua @@ -12,40 +12,24 @@ local logging = require("logging") ---@field fatal function local log = {} -local console_logger = require("logging.console")({ - logPattern = "%level %message\n", - logPatterns = { - [logging.ERROR] = "%level %message (at %source)\n", - }, -}) +local log_patterns = logging.buildLogPatterns({ + [logging.ERROR] = "%level %message (at %source)", +}, "%level %message") + +local console_logger = logging.new(function(self, level, message) + print( + logging.prepareLogMsg( + log_patterns[level], + logging.date(logging.defaultTimestampPattern()), + level, + message + ) + ) + return true +end, logging.defaultLevel()) setmetatable(log, { __index = console_logger, }) -log.debug = function(_, ...) - console_logger:debug(...) - io.flush() -end - -log.info = function(_, ...) - console_logger:info(...) - io.flush() -end - -log.warn = function(_, ...) - console_logger:warn(...) - io.flush() -end - -log.error = function(_, ...) - console_logger:error(...) - io.flush() -end - -log.fatal = function(_, ...) - console_logger:fatal(...) - io.flush() -end - return log diff --git a/api/rust/Cargo.toml b/api/rust/Cargo.toml index f9cc25d..404dfc1 100644 --- a/api/rust/Cargo.toml +++ b/api/rust/Cargo.toml @@ -16,6 +16,7 @@ tokio = { workspace = true, features = ["net"] } tokio-stream = { workspace = true } tonic = { workspace = true } tower = { version = "0.4.13", features = ["util"] } +hyper-util = { version = "0.1.6", features = ["tokio"] } futures = "0.3.30" num_enum = "0.7.2" xkbcommon = { workspace = true } diff --git a/api/rust/src/lib.rs b/api/rust/src/lib.rs index 18685d9..6e303c5 100644 --- a/api/rust/src/lib.rs +++ b/api/rust/src/lib.rs @@ -85,6 +85,7 @@ //! You can peruse the documentation for things to configure. use futures::{Future, StreamExt}; +use hyper_util::rt::TokioIo; use input::Input; use layout::Layout; use output::Output; @@ -263,11 +264,11 @@ impl ApiModules { pub async fn connect() -> Result<(), Box> { // port doesn't matter, we use a unix socket let channel = Endpoint::try_from("http://[::]:50051")? - .connect_with_connector(service_fn(|_: Uri| { - tokio::net::UnixStream::connect( - std::env::var("PINNACLE_GRPC_SOCKET") - .expect("PINNACLE_GRPC_SOCKET was not set; is Pinnacle running?"), - ) + .connect_with_connector(service_fn(|_: Uri| async { + let path = std::env::var("PINNACLE_GRPC_SOCKET") + .expect("PINNACLE_GRPC_SOCKET was not set; is Pinnacle running?"); + + Ok::<_, std::io::Error>(TokioIo::new(tokio::net::UnixStream::connect(path).await?)) })) .await .unwrap(); diff --git a/snowcap b/snowcap index 7baca8e..3dc2659 160000 --- a/snowcap +++ b/snowcap @@ -1 +1 @@ -Subproject commit 7baca8e4299780723f21ea696b19f8998207dc1f +Subproject commit 3dc265976aa1e715db483e1c69d1c84ce897e4a0 diff --git a/src/api.rs b/src/api.rs index 701d216..3c32e74 100644 --- a/src/api.rs +++ b/src/api.rs @@ -144,7 +144,7 @@ fn run_bidirectional_streaming( with_out_stream_and_in_stream_join_handle: F2, ) -> Result>, Status> where - F1: Fn(&mut State, Result) + Clone + Send + 'static, + F1: Fn(&mut State, I) + Clone + Send + 'static, F2: FnOnce(&mut State, UnboundedSender>, JoinHandle<()>) + Send + 'static, I: Send + 'static, O: Send + 'static, @@ -155,15 +155,24 @@ where let with_in_stream = async move { while let Some(request) = in_stream.next().await { - let on_client_request = on_client_request.clone(); - // TODO: handle error - let _ = fn_sender_clone.send(Box::new(move |state: &mut State| { - on_client_request(state, request); - })); + match request { + Ok(request) => { + let on_client_request = on_client_request.clone(); + // TODO: handle error + let _ = fn_sender_clone.send(Box::new(move |state: &mut State| { + on_client_request(state, request); + })); + } + Err(err) => { + debug!("bidirectional stream error: {err}"); + break; + } + } } }; let join_handle = tokio::spawn(with_in_stream); + // let join_handle = tokio::spawn(async {}); let with_out_stream_and_in_stream_join_handle = Box::new(|state: &mut State| { with_out_stream_and_in_stream_join_handle(state, sender, join_handle); diff --git a/src/api/layout.rs b/src/api/layout.rs index df7ad80..f6b6ca5 100644 --- a/src/api/layout.rs +++ b/src/api/layout.rs @@ -32,34 +32,23 @@ impl layout_service_server::LayoutService for LayoutService { run_bidirectional_streaming( self.sender.clone(), in_stream, - |state, request| match request { - Ok(request) => { - if let Some(body) = request.body { - match body { - layout_request::Body::Geometries(geos) => { - if let Err(err) = state.apply_layout(geos) { - debug!("{err}") - } - } - layout_request::Body::Layout(ExplicitLayout { output_name }) => { - if let Some(output) = output_name - .map(OutputName) - .and_then(|name| name.output(&state.pinnacle)) - .or_else(|| state.pinnacle.focused_output().cloned()) - { - state.pinnacle.request_layout(&output); - } + |state, request| { + if let Some(body) = request.body { + match body { + layout_request::Body::Geometries(geos) => { + if let Err(err) = state.apply_layout(geos) { + debug!("{err}") + } + } + layout_request::Body::Layout(ExplicitLayout { output_name }) => { + if let Some(output) = output_name + .map(OutputName) + .and_then(|name| name.output(&state.pinnacle)) + .or_else(|| state.pinnacle.focused_output().cloned()) + { + state.pinnacle.request_layout(&output); } } - } - } - Err(err) => { - // Ignore broken pipes here, they have a code of `Unknown` - // - // Silences errors when reloading the config, unfortunately also ignores other - // `Unknown` errors - if err.code() != tonic::Code::Unknown { - tracing::error!("{err}") } } }, diff --git a/src/api/signal.rs b/src/api/signal.rs index 123293b..25a15dc 100644 --- a/src/api/signal.rs +++ b/src/api/signal.rs @@ -157,14 +157,6 @@ where sender, in_stream, move |state, request| { - let request = match request { - Ok(request) => request, - Err(status) => { - debug!("Error in output_connect signal in stream: {status}"); - return; - } - }; - debug!("Got {request:?} from client stream"); let signal = signal_data_selector(state);