Merge pull request #164 from rust-windowing/rustix
Use `rustix`/`libc` instead of `nix`
This commit is contained in:
commit
a405e0341d
4 changed files with 19 additions and 36 deletions
|
|
@ -18,10 +18,10 @@ harness = false
|
|||
|
||||
[features]
|
||||
default = ["kms", "x11", "x11-dlopen", "wayland", "wayland-dlopen"]
|
||||
kms = ["bytemuck", "drm", "nix"]
|
||||
wayland = ["wayland-backend", "wayland-client", "memmap2", "nix", "fastrand"]
|
||||
kms = ["bytemuck", "drm", "libc", "rustix"]
|
||||
wayland = ["wayland-backend", "wayland-client", "memmap2", "rustix", "fastrand"]
|
||||
wayland-dlopen = ["wayland-sys/dlopen"]
|
||||
x11 = ["as-raw-xcb-connection", "bytemuck", "nix", "tiny-xlib", "x11rb"]
|
||||
x11 = ["as-raw-xcb-connection", "bytemuck", "libc", "rustix", "tiny-xlib", "x11rb"]
|
||||
x11-dlopen = ["tiny-xlib/dlopen", "x11rb/dl-libxcb"]
|
||||
|
||||
[dependencies]
|
||||
|
|
@ -33,7 +33,8 @@ as-raw-xcb-connection = { version = "1.0.0", optional = true }
|
|||
bytemuck = { version = "1.12.3", optional = true }
|
||||
drm = { version = "0.10.0", default-features = false, optional = true }
|
||||
memmap2 = { version = "0.9.0", optional = true }
|
||||
nix = { version = "0.27.0", features = ["fs", "mman"], optional = true }
|
||||
libc = { version = "0.2.149", optional = true }
|
||||
rustix = { version = "0.38.19", features = ["fs", "mm", "shm"], optional = true }
|
||||
tiny-xlib = { version = "0.2.1", optional = true }
|
||||
wayland-backend = { version = "0.3.0", features = ["client_system"], optional = true }
|
||||
wayland-client = { version = "0.31.0", optional = true }
|
||||
|
|
|
|||
|
|
@ -332,10 +332,8 @@ impl BufferImpl<'_> {
|
|||
// this is going to fail. Low hanging fruit PR: add a flag that's set to false if this
|
||||
// returns `ENOSYS` and check that before allocating the above and running this.
|
||||
match self.display.dirty_framebuffer(self.front_fb, &rectangles) {
|
||||
Ok(())
|
||||
| Err(drm::SystemError::Unknown {
|
||||
errno: nix::errno::Errno::ENOSYS,
|
||||
}) => {}
|
||||
Ok(()) => {}
|
||||
Err(drm::SystemError::Unknown { errno }) if errno as i32 == libc::ENOSYS => {}
|
||||
Err(e) => {
|
||||
return Err(SoftBufferError::PlatformError(
|
||||
Some("failed to dirty framebuffer".into()),
|
||||
|
|
|
|||
|
|
@ -18,35 +18,19 @@ use super::State;
|
|||
|
||||
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
|
||||
fn create_memfile() -> File {
|
||||
use nix::{
|
||||
fcntl::{fcntl, FcntlArg, SealFlag},
|
||||
sys::memfd::{memfd_create, MemFdCreateFlag},
|
||||
};
|
||||
use rustix::fs::{MemfdFlags, SealFlags};
|
||||
|
||||
let name = unsafe { CStr::from_bytes_with_nul_unchecked("softbuffer\0".as_bytes()) };
|
||||
let fd = memfd_create(
|
||||
name,
|
||||
MemFdCreateFlag::MFD_CLOEXEC | MemFdCreateFlag::MFD_ALLOW_SEALING,
|
||||
)
|
||||
.expect("Failed to create memfd to store buffer.");
|
||||
let _ = fcntl(
|
||||
fd.as_raw_fd(),
|
||||
FcntlArg::F_ADD_SEALS(SealFlag::F_SEAL_SHRINK | SealFlag::F_SEAL_SEAL),
|
||||
)
|
||||
.expect("Failed to seal memfd.");
|
||||
let fd = rustix::fs::memfd_create(name, MemfdFlags::CLOEXEC | MemfdFlags::ALLOW_SEALING)
|
||||
.expect("Failed to create memfd to store buffer.");
|
||||
rustix::fs::fcntl_add_seals(&fd, SealFlags::SHRINK | SealFlags::SEAL)
|
||||
.expect("Failed to seal memfd.");
|
||||
File::from(fd)
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
|
||||
fn create_memfile() -> File {
|
||||
use nix::{
|
||||
errno::Errno,
|
||||
fcntl::OFlag,
|
||||
sys::{
|
||||
mman::{shm_open, shm_unlink},
|
||||
stat::Mode,
|
||||
},
|
||||
};
|
||||
use rustix::{fs::Mode, io::Errno, shm::ShmOFlags};
|
||||
use std::iter;
|
||||
|
||||
// Use a cached RNG to avoid hammering the thread local.
|
||||
|
|
@ -59,14 +43,14 @@ fn create_memfile() -> File {
|
|||
|
||||
let name = unsafe { CStr::from_bytes_with_nul_unchecked(name.as_bytes()) };
|
||||
// `CLOEXEC` is implied with `shm_open`
|
||||
let fd = shm_open(
|
||||
let fd = rustix::shm::shm_open(
|
||||
name,
|
||||
OFlag::O_RDWR | OFlag::O_CREAT | OFlag::O_EXCL,
|
||||
Mode::S_IRWXU,
|
||||
ShmOFlags::RDWR | ShmOFlags::CREATE | ShmOFlags::EXCL,
|
||||
Mode::RWXU,
|
||||
);
|
||||
if !matches!(fd, Err(Errno::EEXIST)) {
|
||||
if !matches!(fd, Err(Errno::EXIST)) {
|
||||
let fd = fd.expect("Failed to create POSIX shm to store buffer.");
|
||||
let _ = shm_unlink(name);
|
||||
let _ = rustix::shm::shm_unlink(name);
|
||||
return File::from(fd);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
use crate::error::SwResultExt;
|
||||
use crate::{Rect, SoftBufferError};
|
||||
use nix::libc::{shmat, shmctl, shmdt, shmget, IPC_PRIVATE, IPC_RMID};
|
||||
use libc::{shmat, shmctl, shmdt, shmget, IPC_PRIVATE, IPC_RMID};
|
||||
use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle, XlibDisplayHandle, XlibWindowHandle};
|
||||
use std::ptr::{null_mut, NonNull};
|
||||
use std::{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue