From 0fd0dd75e918cf848220c7e5bed1718570162200 Mon Sep 17 00:00:00 2001 From: En-En <39373446+En-En-Code@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:42:34 +0000 Subject: [PATCH] tests: only use PipeWriter if rust-version >= 1.87 By using conditional compilation, we now support running the test suite with Rust versions 1.83 to 1.86 again. This allows us to lower the `rust-version` specified in the root Cargo.toml (because it was controlling the toolchain used in CI) to 1.83, resolving #230. This solution keeps tests operational on our MSRV while also lowering it. It would have been unsatisfying to have an MSRV which could not compile the tests. `rustversion` was selected as the dependency to control the conditional compilation since it was already a build dependency needed by `vergen-gitcl`, so no new dependencies were added. --- Cargo.lock | 5 +++-- Cargo.toml | 4 ++-- testwl/Cargo.toml | 1 + testwl/src/lib.rs | 38 ++++++++++++++++++++++++++++++++------ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ce2a92..e7ffed3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -530,9 +530,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "sd-notify" @@ -635,6 +635,7 @@ name = "testwl" version = "0.1.0" dependencies = [ "rustix", + "rustversion", "wayland-protocols", "wayland-server", "wl_drm", diff --git a/Cargo.toml b/Cargo.toml index c76f160..a19f556 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["macros", "testwl"] +members = ["macros", "testwl", "wl_drm"] [workspace.dependencies] wayland-client = "0.31.2" @@ -12,7 +12,7 @@ rustix = "0.38.31" all = "deny" [workspace.package] -rust-version = "1.87.0" +rust-version = "1.83.0" [package] name = "xwayland-satellite" diff --git a/testwl/Cargo.toml b/testwl/Cargo.toml index 20a5489..6167c22 100644 --- a/testwl/Cargo.toml +++ b/testwl/Cargo.toml @@ -11,3 +11,4 @@ wayland-protocols = { workspace = true, features = ["server", "staging", "unstab wayland-server.workspace = true wl_drm = { path = "../wl_drm" } rustix = { workspace = true, features = ["pipe"] } +rustversion = "1.0.22" diff --git a/testwl/src/lib.rs b/testwl/src/lib.rs index 8ac45c5..6dd52de 100644 --- a/testwl/src/lib.rs +++ b/testwl/src/lib.rs @@ -1,6 +1,7 @@ use std::collections::{hash_map, HashMap, HashSet}; -use std::io::Read; -use std::io::{PipeWriter, Write}; +#[rustversion::since(1.87)] +use std::io::PipeWriter; +use std::io::{Read, Write}; use std::os::fd::{AsFd, BorrowedFd, OwnedFd}; use std::os::unix::net::UnixStream; use std::sync::{Arc, Mutex, OnceLock}; @@ -908,6 +909,33 @@ pub struct PasteData { pub data: Vec, } +#[rustversion::since(1.87)] +pub struct TransferFd(PipeWriter); +#[rustversion::since(1.87)] +impl From for TransferFd { + fn from(value: OwnedFd) -> Self { + Self(PipeWriter::from(value)) + } +} + +#[rustversion::before(1.87)] +pub struct TransferFd(UnixStream); +#[rustversion::before(1.87)] +impl From for TransferFd { + fn from(value: OwnedFd) -> Self { + Self(UnixStream::from(value)) + } +} + +impl Write for TransferFd { + fn write(&mut self, buf: &[u8]) -> std::io::Result { + self.0.write(buf) + } + fn flush(&mut self) -> std::io::Result<()> { + self.0.flush() + } +} + simple_global_dispatch!(WlShm); simple_global_dispatch!(WlCompositor); simple_global_dispatch!(XdgWmBase); @@ -1134,8 +1162,7 @@ impl Dispatch> for State { .position(|data| data.mime_type == mime_type) .unwrap_or_else(|| panic!("Invalid mime type: {mime_type}")); - let mut stream = PipeWriter::from(fd); - stream.write_all(&data[pos].data).unwrap(); + TransferFd::from(fd).write_all(&data[pos].data).unwrap(); } Request::Destroy => {} other => todo!("{other:?}"), @@ -1219,8 +1246,7 @@ impl Dispatch> for State { .position(|data| data.mime_type == mime_type) .unwrap_or_else(|| panic!("Invalid mime type: {mime_type}")); - let mut stream = PipeWriter::from(fd); - stream.write_all(&data[pos].data).unwrap(); + TransferFd::from(fd).write_all(&data[pos].data).unwrap(); } wl_data_offer::Request::Destroy => {} other => todo!("unhandled request: {other:?}"),