Skip to content

Commit

Permalink
Generate doc cfg attributes for more beautiful docs
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 12, 2020
1 parent cea2f7c commit c63d1fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/codegen/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub fn uses(w: &mut dyn Write, env: &Env, imports: &Imports) -> Result<()> {
"#[cfg(any({},feature = \"dox\"))]",
scope.constraints.join(", ")
)?;
writeln!(
w,
"#[cfg_attr(feature = \"dox\", doc(cfg({})))]",
scope.constraints.join(", ")
)?;
}

version_condition(w, env, scope.version, false, 0)?;
Expand Down Expand Up @@ -517,7 +522,8 @@ pub fn version_condition_string(
Some(v) if v > env.config.min_cfg_version => {
let comment = if commented { "//" } else { "" };
Some(format!(
"{}{}#[cfg(any({}, feature = \"dox\"))]",
"{0}{1}#[cfg(any({2}, feature = \"dox\"))]\n\
{0}{1}#[cfg_attr(feature = \"dox\", doc(cfg({2})))]",
tabs(indent),
comment,
v.to_cfg()
Expand All @@ -536,7 +542,8 @@ pub fn not_version_condition(
if let Some(v) = version {
let comment = if commented { "//" } else { "" };
let s = format!(
"{}{}#[cfg(any(not({}), feature = \"dox\"))]",
"{0}{1}#[cfg(any(not({2}), feature = \"dox\"))]\n\
{0}{1}#[cfg_attr(feature = \"dox\", doc(cfg(not({2}))))]",
tabs(indent),
comment,
v.to_cfg()
Expand Down Expand Up @@ -587,7 +594,8 @@ pub fn cfg_condition_string(
Some(v) => {
let comment = if commented { "//" } else { "" };
Some(format!(
"{}{}#[cfg(any({}, feature = \"dox\"))]",
"{0}{1}#[cfg(any({2}, feature = \"dox\"))]\n\
{0}{1}#[cfg_attr(feature = \"dox\", doc(cfg({2})))]",
tabs(indent),
comment,
v
Expand Down
5 changes: 5 additions & 0 deletions src/codegen/sys/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ fn generate_object_funcs(
// since we work with gir-files from Linux, some function names need to be adjusted
if is_windows_utf8 {
writeln!(w, " {}#[cfg(any(windows, feature = \"dox\"))]", comment)?;
writeln!(
w,
" {}#[cfg_attr(feature = \"dox\", doc(cfg(windows)))]",
comment
)?;
writeln!(w, " {}pub fn {}_utf8{};", comment, name, sig)?;
version_condition(w, env, version, commented, 1)?;
}
Expand Down
1 change: 1 addition & 0 deletions src/codegen/sys/statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub fn begin(w: &mut dyn Write) -> Result<()> {
"",
"#![allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]",
"#![allow(clippy::approx_constant, clippy::type_complexity, clippy::unreadable_literal)]",
"#![cfg_attr(feature = \"dox\", feature(doc_cfg))]",
"",
"extern crate libc;",
];
Expand Down

0 comments on commit c63d1fa

Please sign in to comment.