Skip to content

Improve documentation examples and streamline architecture support#53

Merged
phip1611 merged 6 commits intorust-osdev:mainfrom
phip1611:restructure
Mar 24, 2026
Merged

Improve documentation examples and streamline architecture support#53
phip1611 merged 6 commits intorust-osdev:mainfrom
phip1611:restructure

Conversation

@phip1611
Copy link
Member

@phip1611 phip1611 commented Mar 23, 2026

  • Split backend into mmio.rs (always) and pio.rs (x86-only) to localize cfg usage at module boundaries
  • Switched to #[cfg(any(x86..., doc))] so rustdoc includes all items across architectures
  • Enabled doc_cfg on docs.rs for proper platform-specific annotations
  • No functional changes; purely improves structure, maintainability, and documentation

//! - [`MmioBackend`]

mod mmio;
#[cfg(any(target_arch = "x86", target_arch = "x86_64", doc))]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hints for reviewers: it's working

image

@phip1611 phip1611 force-pushed the restructure branch 6 times, most recently from 5294752 to dcea221 Compare March 24, 2026 07:09
This helps to reduce #[cfg()] duplication.
- cfg badges per item
- needs nightly
- comes with auto-detection of cfg items, so there is no need
  for `#[doc(cfg(...))]` per item

To verify, run:

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --open --no-deps
@phip1611 phip1611 force-pushed the restructure branch 2 times, most recently from aa5bb4d to 09fbd20 Compare March 24, 2026 07:15
- dedicated example for x86 port IO and MMIO
- also builds on non-x86 systems

To test doc cross-build, you may use

RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --open --no-deps --document-private-items --target aarch64-unknown-linux-gnu -Zbuild-std
@phip1611
Copy link
Member Author

Yikes this was more painful than anticipated but I've learned something about cross-architecture rustdoc builds :D

Copy link
Member

@mkroening mkroening left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting into modules definitely makes sense. 👍

The second commit does not seem to do what it says. 🤔

  • Switched to #[cfg(any(x86..., doc))] so rustdoc includes all items across architectures

Why is this useful? I have never seen a crate do this. Instead, you can switch the platform on docs.rs.

@phip1611
Copy link
Member Author

phip1611 commented Mar 24, 2026

The second commit does not seem to do what it says. 🤔

Do you refer to an old commit? 🤔 I'm not sure which one you are talking about.

Instead, you can switch the platform on docs.rs.

I did not know this 😁 interesting

Why is this useful? I have never seen a crate do this.

TL;DR: I have a feeling that a documentation should include everything (with markers for feature gates).

This is I think my first library crate with platform specific API, I think. I have no idea what the standard is. To me, it feels natural that the documentation includes everything if one reads them. e.g., if one build the documentation on their macbook and opens it, the documentation should tell the developer how they can do stuff on a x86 PC, for example.

I think this is quite useful and the necessary changes to the codebase are fairly small.

What do you think? Do you see any risk?

@mkroening
Copy link
Member

The second commit does not seem to do what it says. 🤔

Do you refer to an old commit? 🤔 I'm not sure which one you are talking about.

I mean this one: 1f47a91

To me, it feels natural that the documentation includes everything if one reads them. e.g., if one build the documentation on their macbook and opens it, the documentation should tell the developer how they can do stuff on a x86 PC, for example.

I think this is quite useful and the necessary changes to the codebase are fairly small.

What do you think? Do you see any risk?

I think the default is to enable all features for building docs, but not all target-dependent options such as OS or architecture. If a aarch64-apple-darwin user like me is interested in x86 docs, I would use cargo doc --target x86_64-unknown-none. I would personally be confused by cargo doc --target aarch64-apple-darwin containing x86-only items.

Take, for example, libc. They enable a plethora of targets for building in docs.rs. I would be confused if I was interested in what API is available on macOS but also saw every other OS when searching or reading, even if it had the yellow boxes.

If you prefer it like that, it should be fine; I was just confused at first. :D

@phip1611
Copy link
Member Author

Thanks for the heads-up - I simply didn't know 😁

I think I'm in favor of keeping it the current way.

  1. It is not that much overhead
  2. Without it, linking to [`Uart16550::new_port()`] in the docs is a pain with #[cfg_attr(..., doc = "...")]

@phip1611 phip1611 added this pull request to the merge queue Mar 24, 2026
Merged via the queue into rust-osdev:main with commit d1eb768 Mar 24, 2026
16 checks passed
@phip1611 phip1611 deleted the restructure branch March 24, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants