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

Use #[cfg(doc)] instead of docs.rs-specific cfg flag #287

Merged
merged 4 commits into from
Aug 18, 2021
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
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@ jobs:
with:
command: build

- name: "Run cargo doc"
uses: actions-rs/cargo@v1
with:
command: doc

Comment on lines +68 to +72
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should do 3 runs of cargo doc here:

  1. cargo doc
    • default flags, on nightly
  2. RUSTDOCFLAGS="--cfg docsrs" cargo doc
    • flags docs.rs will use, on nightly
  3. cargo +stable doc --no-default-features --features=external_asm,instructions
    • make sure we can build the docs with the stable compiler

Copy link
Contributor

Choose a reason for hiding this comment

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

I decided to just have (1) and (3), now that we don't have the docsrs stuff.

- name: "Run cargo doc for stable"
uses: actions-rs/cargo@v1
with:
command: doc
args: --no-default-features --features external_asm,instructions
if: runner.os != 'Windows'

- name: "Run cargo build for stable without instructions"
uses: actions-rs/cargo@v1
with:
Expand Down
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,11 @@ cc = { version = "1.0.37", optional = true }
default = [ "nightly", "instructions" ]
instructions = []
external_asm = [ "cc" ]
nightly = [ "inline_asm", "const_fn", "abi_x86_interrupt" ]
nightly = [ "inline_asm", "const_fn", "abi_x86_interrupt", "doc_cfg" ]
inline_asm = []
abi_x86_interrupt = []
const_fn = []

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "docsrs"]
doc_cfg = []

[package.metadata.release]
no-dev-version = true
Expand Down
5 changes: 4 additions & 1 deletion src/instructions/interrupts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ pub fn int3() {
/// immediate. This macro will be replaced by a generic function when support for
/// const generics is implemented in Rust.
#[cfg(feature = "inline_asm")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(feature = "nightly", feature = "inline_asm")))
)]
#[macro_export]
macro_rules! software_interrupt {
($x:expr) => {{
Expand Down
5 changes: 4 additions & 1 deletion src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ pub fn bochs_breakpoint() {
/// Gets the current instruction pointer. Note that this is only approximate as it requires a few
/// instructions to execute.
#[cfg(feature = "inline_asm")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "nightly", feature = "inline_asm"))))]
#[cfg_attr(
feature = "doc_cfg",
doc(cfg(any(feature = "nightly", feature = "inline_asm")))
)]
#[inline(always)]
pub fn read_rip() -> crate::VirtAddr {
let rip: u64;
Expand Down
2 changes: 1 addition & 1 deletion src/instructions/segmentation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Provides functions to read and write segment registers.

#[cfg(docsrs)]
#[cfg(doc)]
use crate::{
registers::control::Cr4Flags,
structures::gdt::{Descriptor, GlobalDescriptorTable},
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#![cfg_attr(feature = "const_fn", feature(const_fn_trait_bound))] // PageSize marker trait
#![cfg_attr(feature = "inline_asm", feature(asm))]
#![cfg_attr(feature = "abi_x86_interrupt", feature(abi_x86_interrupt))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![cfg_attr(feature = "doc_cfg", feature(doc_cfg))]
#![warn(missing_docs)]
#![deny(missing_debug_implementations)]

Expand Down
2 changes: 1 addition & 1 deletion src/registers/control.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Functions to read and write control registers.

pub use super::model_specific::{Efer, EferFlags};
#[cfg(docsrs)]
#[cfg(doc)]
use crate::{registers::rflags::RFlags, structures::paging::PageTableFlags};

use bitflags::bitflags;
Expand Down
2 changes: 1 addition & 1 deletion src/registers/model_specific.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Functions to read and write model specific registers.

#[cfg(docsrs)]
#[cfg(doc)]
use crate::{
instructions::segmentation::{Segment64, FS, GS},
registers::control::Cr4Flags,
Expand Down