Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace nix with rustix #815

Merged
merged 8 commits into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@1.56.0
- uses: dtolnay/rust-toolchain@1.63.0
notgull marked this conversation as resolved.
Show resolved Hide resolved

# build
- name: cargo check x11rb-protocol with all features
run: cargo build --package x11rb-protocol --verbose --lib --all-features
- name: cargo check x11rb with all features
run: cargo build --package x11rb --verbose --lib --all-features
- name: Pin last log release supporting our msrv of Rust 1.56
run: cargo update --package log --precise 0.4.18
- name: cargo check x11rb-async with all features
run: cargo build --package x11rb-async --verbose --lib --all-features

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![GitHub Actions Status](https://github.com/psychon/x11rb/workflows/CI/badge.svg)](https://github.com/psychon/x11rb/actions)
[![Crate](https://img.shields.io/crates/v/x11rb.svg)](https://crates.io/crates/x11rb)
[![API](https://docs.rs/x11rb/badge.svg)](https://docs.rs/x11rb)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)
![Minimum rustc version](https://img.shields.io/badge/rustc-1.63+-lightgray.svg)
[![License](https://img.shields.io/crates/l/x11rb.svg)](https://github.com/psychon/x11rb#license)

Feel free to open issues for any problems or questions you might have.
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.56.0"
msrv = "1.63.0"
4 changes: 3 additions & 1 deletion generator/src/generator/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,13 +1511,15 @@ impl<'ns, 'c> NamespaceGenerator<'ns, 'c> {
}
}
xcbdefs::FieldDef::Fd(_) | xcbdefs::FieldDef::FdList(_) => {
// RawFdContainer cannot be cloned, compared, hashed or made default
// OwnedFd cannot be cloned, compared, hashed or made default
derives.clone = false;
derives.copy = false;
derives.partial_ord = false;
derives.ord = false;
notgull marked this conversation as resolved.
Show resolved Hide resolved
derives.hash = false;
derives.default_ = false;
derives.eq = false;
derives.partial_eq = false;
}
xcbdefs::FieldDef::Expr(_) => {}
xcbdefs::FieldDef::VirtualLen(_) => {}
Expand Down
8 changes: 5 additions & 3 deletions x11rb-async/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
repository = "https://github.com/psychon/x11rb"
readme = "../README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11", "async"]

Expand All @@ -24,9 +24,10 @@ tracing = { version = "0.1", default-features = false }
x11rb = { version = "0.12.0", path = "../x11rb", default-features = false }
x11rb-protocol = { version = "0.12.0", path = "../x11rb-protocol" }

[target.'cfg(unix)'.dev-dependencies.nix]
version = "0.26"
[target.'cfg(unix)'.dev-dependencies.rustix]
version = "0.38"
default-features = false
features = ["pipe"]

[features]
# Enable this feature to enable all the X11 extensions
Expand Down Expand Up @@ -98,6 +99,7 @@ all-features = true

[dev-dependencies]
async-executor = "1.5.0"
libc = "0.2.147"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[[example]]
Expand Down
2 changes: 1 addition & 1 deletion x11rb-async/examples/shared_memory_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::os::unix::io::AsRawFd;
use std::ptr::null_mut;

use async_executor::LocalExecutor;
use nix::libc::{mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use libc::{mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};

use x11rb_async::connection::Connection;
use x11rb_async::errors::{ConnectionError, ReplyError, ReplyOrIdError};
Expand Down
150 changes: 66 additions & 84 deletions x11rb-async/src/rust_connection/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::connection::Connection;
use crate::Cookie;
use std::collections::hash_map::{Entry, HashMap};
use std::future::Future;
use x11rb::errors::{ConnectionError, ReplyError};
use x11rb_protocol::protocol::xproto::QueryExtensionReply;
use x11rb_protocol::x11_utils::{ExtInfoProvider, ExtensionInformation};
Expand Down Expand Up @@ -31,99 +30,82 @@ impl Extensions {
}

/// Prefetch information for a given extension, if this was not yet done.
// n.b. notgull: Apparently the resolver for 1.56 is too weak to figure out the lifetimes
// here on its own. Manually specifying them like this seems to solve the issue.
pub(super) fn prefetch<'f, 't, 'c, C: Connection>(
&'t mut self,
conn: &'c C,
pub(super) async fn prefetch<C: Connection>(
&mut self,
conn: &C,
name: &'static str,
) -> impl Future<Output = Result<(), ConnectionError>> + 'f
where
'c: 'f,
't: 'f,
{
async move {
// Check if there is already a cache entry.
if let Entry::Vacant(entry) = self.0.entry(name) {
tracing::debug!("Prefetching information about '{}' extension", name);

// Send a QueryExtension request.
let cookie =
crate::protocol::xproto::query_extension(conn, name.as_bytes()).await?;

// Add the extension to the cache.
entry.insert(ExtensionState::Loading(cookie.sequence_number()));

std::mem::forget(cookie);
}
) -> Result<(), ConnectionError> {
// Check if there is already a cache entry.
if let Entry::Vacant(entry) = self.0.entry(name) {
tracing::debug!("Prefetching information about '{}' extension", name);

// Send a QueryExtension request.
let cookie = crate::protocol::xproto::query_extension(conn, name.as_bytes()).await?;

Ok(())
// Add the extension to the cache.
entry.insert(ExtensionState::Loading(cookie.sequence_number()));

std::mem::forget(cookie);
}

Ok(())
}

/// Get information about an X11 extension.
// n.b. notgull: Apparently the resolver for 1.56 is too weak to figure out the lifetimes
// here on its own. Manually specifying them like this seems to solve the issue.
pub(super) fn information<'f, 't, 'c, C: Connection>(
&'t mut self,
conn: &'c C,
pub(super) async fn information<C: Connection>(
&mut self,
conn: &C,
name: &'static str,
) -> impl Future<Output = Result<Option<ExtensionInformation>, ConnectionError>> + 'f
where
'c: 'f,
't: 'f,
{
async move {
// Prefetch the implementation in case this was not yet done
self.prefetch(conn, name).await?;

// Get the entry from the cache
let mut entry = match self.0.entry(name) {
Entry::Occupied(o) => o,
_ => unreachable!("We just prefetched this."),
};

// Complete the request if we need to.
match entry.get() {
ExtensionState::Loaded(info) => Ok(*info),

ExtensionState::Loading(cookie) => {
tracing::debug!("Waiting for QueryInfo reply for '{}' extension", name);

// Load the extension information.
let cookie = Cookie::<'_, _, QueryExtensionReply>::new(conn, *cookie);

// Get the reply.
let reply = cookie.reply().await.map_err(|e| {
tracing::warn!(
"Got error {:?} for QueryInfo reply for '{}' extension",
e,
name
);
match e {
ReplyError::ConnectionError(e) => e,
ReplyError::X11Error(_) => ConnectionError::UnknownError,
}
})?;

let ext_info = if reply.present {
let info = ExtensionInformation {
major_opcode: reply.major_opcode,
first_event: reply.first_event,
first_error: reply.first_error,
};
tracing::debug!("Extension '{}' is present: {:?}", name, info);
Some(info)
} else {
tracing::debug!("Extension '{}' is not present", name);
None
) -> Result<Option<ExtensionInformation>, ConnectionError> {
// Prefetch the implementation in case this was not yet done
self.prefetch(conn, name).await?;

// Get the entry from the cache
let mut entry = match self.0.entry(name) {
Entry::Occupied(o) => o,
_ => unreachable!("We just prefetched this."),
};

// Complete the request if we need to.
match entry.get() {
ExtensionState::Loaded(info) => Ok(*info),

ExtensionState::Loading(cookie) => {
tracing::debug!("Waiting for QueryInfo reply for '{}' extension", name);

// Load the extension information.
let cookie = Cookie::<'_, _, QueryExtensionReply>::new(conn, *cookie);

// Get the reply.
let reply = cookie.reply().await.map_err(|e| {
tracing::warn!(
"Got error {:?} for QueryInfo reply for '{}' extension",
e,
name
);
match e {
ReplyError::ConnectionError(e) => e,
ReplyError::X11Error(_) => ConnectionError::UnknownError,
}
})?;

let ext_info = if reply.present {
let info = ExtensionInformation {
major_opcode: reply.major_opcode,
first_event: reply.first_event,
first_error: reply.first_error,
};
tracing::debug!("Extension '{}' is present: {:?}", name, info);
Some(info)
} else {
tracing::debug!("Extension '{}' is not present", name);
None
};

// Update the cache.
*entry.get_mut() = ExtensionState::Loaded(ext_info);
// Update the cache.
*entry.get_mut() = ExtensionState::Loaded(ext_info);

Ok(ext_info)
}
Ok(ext_info)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions x11rb-async/tests/connection_regression_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ fn retry_for_left_over_fds() {
// Right now that error is WriteZero. That is still better than no error at all.

let fds = {
let (fd0, fd1) = nix::unistd::pipe().unwrap();
vec![RawFdContainer::new(fd0), RawFdContainer::new(fd1)]
let (fd0, fd1) = rustix::pipe::pipe().unwrap();
vec![fd0, fd1]
};

// Send a large request. This should be larger than the write buffer size, which is 16384 bytes.
Expand Down
10 changes: 5 additions & 5 deletions x11rb-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors = [
repository = "https://github.com/psychon/x11rb"
readme = "../README.md"
edition = "2021"
rust-version = "1.56"
rust-version = "1.63"
license = "MIT OR Apache-2.0"
keywords = ["xcb", "X11"]

Expand All @@ -20,15 +20,15 @@ serde = { version = "1", features = ["derive"], optional = true }
[dev-dependencies]
criterion = "0.4"

[target.'cfg(unix)'.dependencies.nix]
version = "0.26"
[target.'cfg(unix)'.dependencies.rustix]
version = "0.38"
default-features = false
features = ["fs"]
features = ["std"]
psychon marked this conversation as resolved.
Show resolved Hide resolved
optional = true

[features]
default = ["std"]
std = ["nix"]
std = ["rustix"]

# Enable utility functions in `x11rb::resource_manager` for querying the
# resource databases.
Expand Down
14 changes: 7 additions & 7 deletions x11rb-protocol/src/protocol/dri3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl crate::x11_utils::ReplyFDsRequest for OpenRequest {
type Reply = OpenReply;
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct OpenReply {
pub nfd: u8,
pub sequence: u16,
Expand Down Expand Up @@ -308,7 +308,7 @@ impl Serialize for OpenReply {

/// Opcode for the PixmapFromBuffer request
pub const PIXMAP_FROM_BUFFER_REQUEST: u8 = 2;
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct PixmapFromBufferRequest {
pub pixmap: xproto::Pixmap,
pub drawable: xproto::Drawable,
Expand Down Expand Up @@ -460,7 +460,7 @@ impl crate::x11_utils::ReplyFDsRequest for BufferFromPixmapRequest {
type Reply = BufferFromPixmapReply;
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct BufferFromPixmapReply {
pub nfd: u8,
pub sequence: u16,
Expand Down Expand Up @@ -566,7 +566,7 @@ impl Serialize for BufferFromPixmapReply {

/// Opcode for the FenceFromFD request
pub const FENCE_FROM_FD_REQUEST: u8 = 4;
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct FenceFromFDRequest {
pub drawable: xproto::Drawable,
pub fence: u32,
Expand Down Expand Up @@ -699,7 +699,7 @@ impl crate::x11_utils::ReplyFDsRequest for FDFromFenceRequest {
type Reply = FDFromFenceReply;
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct FDFromFenceReply {
pub nfd: u8,
pub sequence: u16,
Expand Down Expand Up @@ -930,7 +930,7 @@ impl GetSupportedModifiersReply {

/// Opcode for the PixmapFromBuffers request
pub const PIXMAP_FROM_BUFFERS_REQUEST: u8 = 7;
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct PixmapFromBuffersRequest {
pub pixmap: xproto::Pixmap,
pub window: xproto::Window,
Expand Down Expand Up @@ -1157,7 +1157,7 @@ impl crate::x11_utils::ReplyFDsRequest for BuffersFromPixmapRequest {
type Reply = BuffersFromPixmapReply;
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct BuffersFromPixmapReply {
pub sequence: u16,
pub length: u32,
Expand Down
2 changes: 1 addition & 1 deletion x11rb-protocol/src/protocol/randr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6896,7 +6896,7 @@ impl<'input> crate::x11_utils::ReplyFDsRequest for CreateLeaseRequest<'input> {
type Reply = CreateLeaseReply;
}

#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct CreateLeaseReply {
pub nfd: u8,
pub sequence: u16,
Expand Down
4 changes: 2 additions & 2 deletions x11rb-protocol/src/protocol/shm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ pub const ATTACH_FD_REQUEST: u8 = 6;
/// * `shmseg` - A shared memory segment ID created with xcb_generate_id().
/// * `shm_fd` - The file descriptor the server should mmap().
/// * `read_only` - True if the segment shall be mapped read only by the X11 server, otherwise false.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct AttachFdRequest {
pub shmseg: Seg,
pub shm_fd: RawFdContainer,
Expand Down Expand Up @@ -1149,7 +1149,7 @@ impl crate::x11_utils::ReplyFDsRequest for CreateSegmentRequest {
/// # Fields
///
/// * `nfd` - The number of file descriptors sent by the server. Will always be 1.
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug)]
pub struct CreateSegmentReply {
pub nfd: u8,
pub sequence: u16,
Expand Down
Loading