Docs.rs rendering assistance

⚓ Rust    📅 2025-10-01    👤 surdeus    👁️ 8      

surdeus

libc relies on cargo-args to build documentation for a bunch of targets including ones not supported by rustup; unfortunately only the items in the crate itself are rendered with hyperlinks and syntax highlighting. For example Dl_info::hash does not highlight or hyperlink the trait Hash, and the descriptions for functions like Hash::hash don't resolve the markdown links (e.g., [Hasher] is displayed). Is it possible to also have syntax highlighting and link resolution for items external to the crate?

I have a crate that uses the below snippet from Cargo.toml:

[package.metadata.docs.rs]
all-features = true
cargo-args = ["-Zbuild-std=std"]
default-target = "x86_64-unknown-openbsd"
targets = [
  "aarch64-apple-darwin",
  "aarch64-unknown-linux-gnu",
  "i686-unknown-linux-gnu",
  "x86_64-unknown-dragonfly",
  "x86_64-unknown-freebsd",
  "x86_64-unknown-linux-gnu",
  "x86_64-unknown-netbsd"
]

But I'd like to also have the typical "niceties" that "normal" doc rendering comes with.

Addendum

In case it's relevant, near the top of lib.rs is the following:

#![cfg_attr(docsrs, feature(doc_cfg))]
#![no_std]
#![cfg(any(
    target_os = "dragonfly",
    target_os = "freebsd",
    target_os = "linux",
    target_os = "netbsd",
    target_os = "openbsd",
    target_vendor = "apple"
))]

I then use something similar to below when dealing with something that isn't relevant for all of the above targets:

#[cfg_attr(docsrs, doc(cfg(target_os = "openbsd")))]
#[cfg(any(doc, target_os = "openbsd"))]

Unlike libc, I use "-Zbuild-std=std" instead of "-Zbuild-std=core" for cargo-args since I do have a std feature; and I want code that is enabled by said feature to be part of the published documentation.

If possible, I'd like to avoid the use of any build script. Do note that when rendered locally via RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --all-features --open, syntax highlighting and link resolution is performed; so it may be hard to test locally.

1 post - 1 participant

Read full topic

🏷️ Rust_feed