Skip to content

Commit

Permalink
Merge pull request #96 from compio-rs/doc/refurnish
Browse files Browse the repository at this point in the history
Add `doc(cfg())` support
  • Loading branch information
Berrysoft authored Oct 17, 2023
2 parents 8e57133 + b8ea870 commit eac5bfb
Show file tree
Hide file tree
Showing 24 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions compio-buf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg docsrs"]

[dependencies]
bumpalo = { version = "3", optional = true }
Expand Down
1 change: 1 addition & 0 deletions compio-buf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! crate defines [`IoBuf`] and [`IoBufMut`] traits which are implemented by
//! buffer types that respect the safety contract.

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "allocator_api", feature(allocator_api))]
#![cfg_attr(feature = "read_buf", feature(read_buf))]
#![cfg_attr(feature = "try_trait_v2", feature(try_trait_v2, try_trait_v2_residual))]
Expand Down
3 changes: 2 additions & 1 deletion compio-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg docsrs"]
default-target = "x86_64-pc-windows-msvc"
targets = [
"x86_64-pc-windows-msvc",
Expand All @@ -36,7 +37,7 @@ slab = "0.4"
socket2 = { version = "0.5", features = ["all"] }

# Windows specific dependencies
[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(windows)'.dependencies]
compio-buf = { workspace = true, features = ["arrayvec"] }
# may be excluded from linking if the unstable equivalent is used
aligned-array = "1"
Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/iour/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[doc(no_inline)]
#[cfg_attr(all(doc, docsrs), doc(cfg(all())))]
pub use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::{collections::VecDeque, io, pin::Pin, task::Poll, time::Duration};

Expand Down
6 changes: 4 additions & 2 deletions compio-driver/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! The platform-specified driver.
//! Some types differ by compilation target.

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "once_cell_try", feature(once_cell_try))]
#![warn(missing_docs)]

Expand All @@ -18,10 +19,11 @@ use slab::Slab;

pub mod op;
#[cfg(unix)]
#[cfg_attr(docsrs, doc(cfg(all())))]
mod unix;

cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
if #[cfg(windows)] {
#[path = "iocp/mod.rs"]
mod sys;
} else if #[cfg(all(target_os = "linux", feature = "io-uring"))] {
Expand All @@ -35,7 +37,7 @@ cfg_if::cfg_if! {

pub use sys::*;

#[cfg(target_os = "windows")]
#[cfg(windows)]
#[macro_export]
#[doc(hidden)]
macro_rules! syscall {
Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use compio_buf::{BufResult, IntoInner, IoBuf, IoBufMut, SetBufInit};
use socket2::SockAddr;

#[cfg(target_os = "windows")]
#[cfg(windows)]
pub use crate::sys::op::ConnectNamedPipe;
pub use crate::sys::op::{
Accept, Recv, RecvFrom, RecvFromVectored, RecvVectored, Send, SendTo, SendToVectored,
Expand Down
2 changes: 1 addition & 1 deletion compio-driver/src/poll/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[doc(no_inline)]
#[cfg_attr(all(doc, docsrs), doc(cfg(all())))]
pub use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::{
collections::{HashMap, HashSet, VecDeque},
Expand Down
5 changes: 3 additions & 2 deletions compio-fs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg docsrs"]

[dependencies]
# Workspace dependencies
Expand All @@ -20,7 +21,7 @@ compio-driver = { workspace = true }
compio-runtime = { workspace = true, optional = true }

# Windows specific dependencies
[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(windows)'.dependencies]
widestring = "1"
windows-sys = { version = "0.48", features = [
"Win32_Foundation",
Expand All @@ -31,7 +32,7 @@ windows-sys = { version = "0.48", features = [
] }

# Windows specific dev dependencies
[target.'cfg(target_os = "windows")'.dev-dependencies]
[target.'cfg(windows)'.dev-dependencies]
windows-sys = { version = "0.48", features = ["Win32_Security_Authorization"] }

# Unix specific dependencies
Expand Down
4 changes: 2 additions & 2 deletions compio-fs/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct File {
attacher: Attacher,
}

#[cfg(target_os = "windows")]
#[cfg(windows)]
fn file_with_options(
path: impl AsRef<Path>,
mut options: std::fs::OpenOptions,
Expand All @@ -38,7 +38,7 @@ fn file_with_options(
options.open(path)
}

#[cfg(not(target_os = "windows"))]
#[cfg(not(windows))]
fn file_with_options(
path: impl AsRef<Path>,
mut options: std::fs::OpenOptions,
Expand Down
3 changes: 2 additions & 1 deletion compio-fs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Filesystem manipulation operations.

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "allocator_api", feature(allocator_api))]
#![warn(missing_docs)]

Expand All @@ -9,5 +10,5 @@ pub use file::*;
mod open_options;
pub use open_options::*;

#[cfg(target_os = "windows")]
#[cfg(windows)]
pub mod named_pipe;
1 change: 1 addition & 0 deletions compio-net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repository = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg docsrs"]

[dependencies]
# Workspace dependencies
Expand Down
1 change: 1 addition & 0 deletions compio-net/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! Currently, TCP/UDP/Unix socket are implemented.

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![warn(missing_docs)]

mod socket;
Expand Down
4 changes: 2 additions & 2 deletions compio-net/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Socket {
self.attach()?;
let op = Connect::new(self.as_raw_fd(), addr.clone());
let BufResult(res, _op) = submit(op).await;
#[cfg(target_os = "windows")]
#[cfg(windows)]
{
res?;
_op.update_context()?;
Expand Down Expand Up @@ -113,7 +113,7 @@ impl Socket {
Ok((accept_sock, addr))
}

#[cfg(all(feature = "runtime", target_os = "windows"))]
#[cfg(all(feature = "runtime", windows))]
pub async fn accept(&self) -> io::Result<(Self, SockAddr)> {
self.attach()?;
let local_addr = self.local_addr()?;
Expand Down
2 changes: 1 addition & 1 deletion compio-net/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl TcpStream {
use std::net::{Ipv4Addr, Ipv6Addr, SocketAddrV4, SocketAddrV6};

super::each_addr_async(addr, |addr| async move {
let socket = if cfg!(target_os = "windows") {
let socket = if cfg!(windows) {
let bind_addr = if addr.is_ipv4() {
SockAddr::from(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0))
} else if addr.is_ipv6() {
Expand Down
3 changes: 2 additions & 1 deletion compio-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository = { workspace = true }
[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-pc-windows-msvc"
rustdoc-args = ["--cfg docsrs"]
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
Expand All @@ -39,7 +40,7 @@ slab = { version = "0.4", optional = true }
smallvec = "1"

# Windows specific dependencies
[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.48", features = ["Win32_System_IO"] }

# Unix specific dependencies
Expand Down
2 changes: 1 addition & 1 deletion compio-runtime/src/attacher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Attacher {
/// * io-uring/polling: it will try to attach in the current thread if
/// needed.
pub fn try_clone(&self, source: &impl AsRawFd) -> io::Result<Self> {
if cfg!(target_os = "windows") {
if cfg!(windows) {
Ok(self.clone())
} else {
let new_self = Self::new();
Expand Down
2 changes: 1 addition & 1 deletion compio-runtime/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! Only for waking up the driver.

cfg_if::cfg_if! {
if #[cfg(target_os = "windows")] {
if #[cfg(windows)] {
mod iocp;
pub use iocp::*;
} else if #[cfg(any(
Expand Down
1 change: 1 addition & 0 deletions compio-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! ```

#![cfg_attr(feature = "once_cell_try", feature(once_cell_try))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![warn(missing_docs)]

mod attacher;
Expand Down
3 changes: 2 additions & 1 deletion compio-signal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ repository = { workspace = true }

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg docsrs"]

[dependencies]
# Workspace dependencies
compio-runtime = { workspace = true, features = ["event"] }

# Windows specific dependencies
[target.'cfg(target_os = "windows")'.dependencies]
[target.'cfg(windows)'.dependencies]
compio-driver = { workspace = true }
once_cell = "1"
slab = "0.4"
Expand Down
5 changes: 3 additions & 2 deletions compio-signal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
//! })
//! ```

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![cfg_attr(feature = "lazy_cell", feature(lazy_cell))]
#![warn(missing_docs)]

#[cfg(target_os = "windows")]
#[cfg(windows)]
pub mod windows;

#[cfg(unix)]
pub mod unix;

/// Completes when a "ctrl-c" notification is sent to the process.
pub async fn ctrl_c() -> std::io::Result<()> {
#[cfg(target_os = "windows")]
#[cfg(windows)]
{
windows::ctrl_c().await
}
Expand Down
1 change: 1 addition & 0 deletions compio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository = { workspace = true }
[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-pc-windows-msvc"
rustdoc-args = ["--cfg docsrs"]
targets = [
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
Expand Down
4 changes: 2 additions & 2 deletions compio/benches/named_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn basic(c: &mut Criterion) {
.build()
.unwrap();
b.to_async(&runtime).iter(|| async {
#[cfg(target_os = "windows")]
#[cfg(windows)]
{
use tokio::{
io::{AsyncReadExt, AsyncWriteExt},
Expand All @@ -52,7 +52,7 @@ fn basic(c: &mut Criterion) {

group.bench_function("compio", |b| {
b.to_async(CompioRuntime).iter(|| async {
#[cfg(target_os = "windows")]
#[cfg(windows)]
{
use compio::{
buf::BufResult,
Expand Down
2 changes: 1 addition & 1 deletion compio/examples/named_pipe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[compio::main(crate = "compio")]
async fn main() {
#[cfg(target_os = "windows")]
#[cfg(windows)]
{
use compio::{
buf::BufResult,
Expand Down
1 change: 1 addition & 0 deletions compio/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
//! # })
//! ```

#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![warn(missing_docs)]

#[doc(no_inline)]
Expand Down

0 comments on commit eac5bfb

Please sign in to comment.