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.
This commit is contained in:
En-En 2025-09-02 14:42:34 +00:00 committed by Supreeeme
parent c0497c990d
commit 0fd0dd75e9
4 changed files with 38 additions and 10 deletions

View file

@ -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"

View file

@ -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<u8>,
}
#[rustversion::since(1.87)]
pub struct TransferFd(PipeWriter);
#[rustversion::since(1.87)]
impl From<OwnedFd> 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<OwnedFd> for TransferFd {
fn from(value: OwnedFd) -> Self {
Self(UnixStream::from(value))
}
}
impl Write for TransferFd {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
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<ZwpPrimarySelectionOfferV1, Vec<PasteData>> 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<WlDataOffer, Vec<PasteData>> 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:?}"),