From addaf8aad68b424a13e50767865103ca2875071f Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Thu, 1 Aug 2024 22:43:39 +0200 Subject: [PATCH 1/6] docs: add root level documentation for all libraries --- .github/workflows/doc.yml | 49 +++++++++++++++++++ crates/libs/bindgen/readme.md | 2 +- crates/libs/bindgen/src/lib.rs | 4 +- crates/libs/core/readme.md | 83 +------------------------------- crates/libs/core/src/lib.rs | 4 +- crates/libs/cppwinrt/src/lib.rs | 4 +- crates/libs/implement/src/lib.rs | 8 +-- crates/libs/interface/src/lib.rs | 8 +-- crates/libs/metadata/src/lib.rs | 4 +- crates/libs/registry/src/lib.rs | 4 +- crates/libs/result/src/lib.rs | 4 +- crates/libs/strings/src/lib.rs | 4 +- crates/libs/sys/readme.md | 57 ++-------------------- crates/libs/sys/src/lib.rs | 21 ++++++-- crates/libs/targets/readme.md | 5 +- crates/libs/targets/src/lib.rs | 4 +- crates/libs/version/readme.md | 8 +-- crates/libs/version/src/lib.rs | 4 +- crates/libs/windows/readme.md | 36 -------------- crates/libs/windows/src/lib.rs | 27 +++++++++-- 20 files changed, 123 insertions(+), 217 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 3a630abaef..7b89390de1 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -20,6 +20,13 @@ jobs: uses: actions/checkout@v4 - name: Check run: cargo doc --no-deps -p windows + - name: Doctests + run: > + cargo test --doc -p windows + -F Data_Xml_Dom + -F Win32_Security + -F Win32_System_Threading + -F Win32_UI_WindowsAndMessaging windows-sys: name: windows-sys @@ -29,3 +36,45 @@ jobs: uses: actions/checkout@v4 - name: Check run: cargo doc --no-deps -p windows-sys + - name: Doctests + run: > + cargo test --doc -p windows-sys + -F Win32_Security + -F Win32_System_Threading + -F Win32_UI_WindowsAndMessaging + + other-crates: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Check + run: > + cargo doc --no-deps + -p windows-bindgen + -p windows-core + -p cppwinrt + -p windows-implement + -p windows-interface + -p windows-metadata + -p windows-registry + -p windows-result + -p windows-strings + -p windows-targets + -p windows-version + + - name: Doctests + run: > + cargo test --doc + -p windows-bindgen + -p windows-core + -p cppwinrt + -p windows-implement + -p windows-interface + -p windows-metadata + -p windows-registry + -p windows-result + -p windows-strings + -p windows-targets + -p windows-version diff --git a/crates/libs/bindgen/readme.md b/crates/libs/bindgen/readme.md index 5647260723..671a4c1531 100644 --- a/crates/libs/bindgen/readme.md +++ b/crates/libs/bindgen/readme.md @@ -18,7 +18,7 @@ version = "0.58" Generates Rust bindings in a build script or test as needed: -```rust,no_run +```rust,ignore #[test] fn bindgen() { let args = [ diff --git a/crates/libs/bindgen/src/lib.rs b/crates/libs/bindgen/src/lib.rs index e9db3a17b9..406da7a6c5 100644 --- a/crates/libs/bindgen/src/lib.rs +++ b/crates/libs/bindgen/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] mod args; mod error; diff --git a/crates/libs/core/readme.md b/crates/libs/core/readme.md index 060034beba..0b7035b0d3 100644 --- a/crates/libs/core/readme.md +++ b/crates/libs/core/readme.md @@ -1,86 +1,7 @@ -## Rust for Windows +## windows-core -The [windows](https://crates.io/crates/windows) and [windows-sys](https://crates.io/crates/windows-sys) crates let you call any Windows API past, present, and future using code generated on the fly directly from the [metadata describing the API](https://github.com/microsoft/windows-rs/tree/master/crates/libs/bindgen/default) and right into your Rust package where you can call them as if they were just another Rust module. The Rust language projection follows in the tradition established by [C++/WinRT](https://github.com/microsoft/cppwinrt) of building language projections for Windows using standard languages and compilers, providing a natural and idiomatic way for Rust developers to call Windows APIs. +Core primitives for the [windows](https://crates.io/crates/windows) crate. * [Getting started](https://kennykerr.ca/rust-getting-started/) * [Samples](https://github.com/microsoft/windows-rs/tree/0.58.0/crates/samples) * [Releases](https://github.com/microsoft/windows-rs/releases) - -Start by adding the following to your Cargo.toml file: - -```toml -[dependencies.windows] -version = "0.58" -features = [ - "Data_Xml_Dom", - "Win32_Security", - "Win32_System_Threading", - "Win32_UI_WindowsAndMessaging", -] -``` - -Make use of any Windows APIs as needed: - -```rust,no_run -use windows::{ - core::*, Data::Xml::Dom::*, Win32::Foundation::*, Win32::System::Threading::*, - Win32::UI::WindowsAndMessaging::*, -}; - -fn main() -> Result<()> { - let doc = XmlDocument::new()?; - doc.LoadXml(h!("hello world"))?; - - let root = doc.DocumentElement()?; - assert!(root.NodeName()? == "html"); - assert!(root.InnerText()? == "hello world"); - - unsafe { - let event = CreateEventW(None, true, false, None)?; - SetEvent(event)?; - WaitForSingleObject(event, 0); - CloseHandle(event)?; - - MessageBoxA(None, s!("Ansi"), s!("Caption"), MB_OK); - MessageBoxW(None, w!("Wide"), w!("Caption"), MB_OK); - } - - Ok(()) -} -``` - -## windows-sys - -The `windows-sys` crate is a zero-overhead fallback for the most demanding situations and primarily where the absolute best compile time is essential. It only includes function declarations (externs), structs, and constants. No convenience helpers, traits, or wrappers are provided. - -Start by adding the following to your Cargo.toml file: - -```toml -[dependencies.windows-sys] -version = "0.59" -features = [ - "Win32_Security", - "Win32_System_Threading", - "Win32_UI_WindowsAndMessaging", -] -``` - -Make use of any Windows APIs as needed: - -```rust,no_run -use windows_sys::{ - core::*, Win32::Foundation::*, Win32::System::Threading::*, Win32::UI::WindowsAndMessaging::*, -}; - -fn main() { - unsafe { - let event = CreateEventW(std::ptr::null(), 1, 0, std::ptr::null()); - SetEvent(event); - WaitForSingleObject(event, 0); - CloseHandle(event); - - MessageBoxA(0 as _, s!("Ansi"), s!("Caption"), MB_OK); - MessageBoxW(0 as _, w!("Wide"), w!("Caption"), MB_OK); - } -} -``` diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index d8a2b77f87..a43cb08633 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![doc(html_no_source)] #![allow(non_snake_case)] diff --git a/crates/libs/cppwinrt/src/lib.rs b/crates/libs/cppwinrt/src/lib.rs index 655ccc2ca3..444e050407 100644 --- a/crates/libs/cppwinrt/src/lib.rs +++ b/crates/libs/cppwinrt/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![cfg(windows)] diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index 024263085b..3ad13505b1 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -1,6 +1,8 @@ -/*! -Learn more about Rust for Windows here: -*/ +//! Implement COM interfaces for Rust types. +//! +//! Take a look at [macro@implement] for an example. +//! +//! Learn more about Rust for Windows here: use quote::{quote, ToTokens}; diff --git a/crates/libs/interface/src/lib.rs b/crates/libs/interface/src/lib.rs index 2e6307f200..c44f8eab27 100644 --- a/crates/libs/interface/src/lib.rs +++ b/crates/libs/interface/src/lib.rs @@ -1,6 +1,8 @@ -/*! -Learn more about Rust for Windows here: -*/ +//! Define COM interfaces to call or implement. +//! +//! Take a look at [macro@interface] for an example. +//! +//! Learn more about Rust for Windows here: use quote::quote; use syn::spanned::Spanned; diff --git a/crates/libs/metadata/src/lib.rs b/crates/libs/metadata/src/lib.rs index c7ef6c1f16..4aa1275faa 100644 --- a/crates/libs/metadata/src/lib.rs +++ b/crates/libs/metadata/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![doc(hidden)] diff --git a/crates/libs/registry/src/lib.rs b/crates/libs/registry/src/lib.rs index 44ba2f4982..3ff734d3c0 100644 --- a/crates/libs/registry/src/lib.rs +++ b/crates/libs/registry/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![cfg(windows)] #![no_std] diff --git a/crates/libs/result/src/lib.rs b/crates/libs/result/src/lib.rs index c636a52c53..ba0ba6406e 100644 --- a/crates/libs/result/src/lib.rs +++ b/crates/libs/result/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![cfg_attr( windows_debugger_visualizer, diff --git a/crates/libs/strings/src/lib.rs b/crates/libs/strings/src/lib.rs index 19f84039ad..d01eb25e76 100644 --- a/crates/libs/strings/src/lib.rs +++ b/crates/libs/strings/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![cfg(windows)] #![allow(non_snake_case)] diff --git a/crates/libs/sys/readme.md b/crates/libs/sys/readme.md index 7a1e893961..06076876ac 100644 --- a/crates/libs/sys/readme.md +++ b/crates/libs/sys/readme.md @@ -1,59 +1,12 @@ -## Rust for Windows - -The [windows](https://crates.io/crates/windows) and [windows-sys](https://crates.io/crates/windows-sys) crates let you call any Windows API past, present, and future using code generated on the fly directly from the [metadata describing the API](https://github.com/microsoft/windows-rs/tree/master/crates/libs/bindgen/default) and right into your Rust package where you can call them as if they were just another Rust module. The Rust language projection follows in the tradition established by [C++/WinRT](https://github.com/microsoft/cppwinrt) of building language projections for Windows using standard languages and compilers, providing a natural and idiomatic way for Rust developers to call Windows APIs. - -* [Getting started](https://kennykerr.ca/rust-getting-started/) -* [Samples](https://github.com/microsoft/windows-rs/tree/0.59.0/crates/samples) -* [Releases](https://github.com/microsoft/windows-rs/releases) -* [Feature search](https://microsoft.github.io/windows-rs/features/#/0.59.0) - -Start by adding the following to your Cargo.toml file: - -```toml -[dependencies.windows] -version = "0.58" -features = [ - "Data_Xml_Dom", - "Win32_Security", - "Win32_System_Threading", - "Win32_UI_WindowsAndMessaging", -] -``` - -Make use of any Windows APIs as needed: - -```rust,no_run -use windows::{ - core::*, Data::Xml::Dom::*, Win32::Foundation::*, Win32::System::Threading::*, - Win32::UI::WindowsAndMessaging::*, -}; - -fn main() -> Result<()> { - let doc = XmlDocument::new()?; - doc.LoadXml(h!("hello world"))?; - - let root = doc.DocumentElement()?; - assert!(root.NodeName()? == "html"); - assert!(root.InnerText()? == "hello world"); - - unsafe { - let event = CreateEventW(None, true, false, None)?; - SetEvent(event)?; - WaitForSingleObject(event, 0); - CloseHandle(event)?; - - MessageBoxA(None, s!("Ansi"), s!("Caption"), MB_OK); - MessageBoxW(None, w!("Wide"), w!("Caption"), MB_OK); - } - - Ok(()) -} -``` - ## windows-sys The `windows-sys` crate is a zero-overhead fallback for the most demanding situations and primarily where the absolute best compile time is essential. It only includes function declarations (externs), structs, and constants. No convenience helpers, traits, or wrappers are provided. +- [Getting started](https://kennykerr.ca/rust-getting-started/) +- [Samples](https://github.com/microsoft/windows-rs/tree/0.59.0/crates/samples) +- [Releases](https://github.com/microsoft/windows-rs/releases) +- [Feature search](https://microsoft.github.io/windows-rs/features/#/0.59.0) + Start by adding the following to your Cargo.toml file: ```toml diff --git a/crates/libs/sys/src/lib.rs b/crates/libs/sys/src/lib.rs index 396dd24e1b..79d562063b 100644 --- a/crates/libs/sys/src/lib.rs +++ b/crates/libs/sys/src/lib.rs @@ -1,8 +1,21 @@ -/*! -Learn more about Rust for Windows here: +#![cfg_attr( + all( + feature = "Win32_Security", + feature = "Win32_System_Threading", + feature = "Win32_UI_WindowsAndMessaging", + ), + doc = include_str!("../README.md") +)] -[Feature search](https://microsoft.github.io/windows-rs/features/#/0.59.0) -*/ +// fallback if not all features are enabled +#![cfg_attr( + not(all( + feature = "Win32_Security", + feature = "Win32_System_Threading", + feature = "Win32_UI_WindowsAndMessaging", + )), + doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)", +)] #![no_std] #![doc(html_no_source)] diff --git a/crates/libs/targets/readme.md b/crates/libs/targets/readme.md index b7cb6979d7..58840c40f2 100644 --- a/crates/libs/targets/readme.md +++ b/crates/libs/targets/readme.md @@ -1,10 +1,11 @@ ## Import libs for Windows -The [windows-targets](https://crates.io/crates/windows-targets) crate includes import libs, supports semantic versioning, and optional support for raw-dylib. +The [windows-targets](https://crates.io/crates/windows-targets) crate includes import libs, supports semantic versioning, and optional support for raw-dylib. * [Getting started](https://kennykerr.ca/rust-getting-started/) * [Samples](https://github.com/microsoft/windows-rs/tree/0.58.0/crates/samples) * [Releases](https://github.com/microsoft/windows-rs/releases) +* [Understanding the `windows-targets` crate](https://kennykerr.ca/rust-getting-started/understanding-windows-targets.html) Start by adding the following to your Cargo.toml file: @@ -15,7 +16,7 @@ version = "0.52" Use the `link` macro to define the external functions you wish to call: -```rust,no_run +```rust windows_targets::link!("kernel32.dll" "system" fn SetLastError(code: u32)); windows_targets::link!("kernel32.dll" "system" fn GetLastError() -> u32); diff --git a/crates/libs/targets/src/lib.rs b/crates/libs/targets/src/lib.rs index e4751989f1..f9ee390eea 100644 --- a/crates/libs/targets/src/lib.rs +++ b/crates/libs/targets/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![no_std] diff --git a/crates/libs/version/readme.md b/crates/libs/version/readme.md index 2d50f897de..b274782a08 100644 --- a/crates/libs/version/readme.md +++ b/crates/libs/version/readme.md @@ -2,9 +2,9 @@ The [windows-version](https://crates.io/crates/windows-version) crate provides reliable operating system version information without the need for application manifest files. -* [Getting started](https://kennykerr.ca/rust-getting-started/) -* [Samples](https://github.com/microsoft/windows-rs/tree/0.58.0/crates/samples) -* [Releases](https://github.com/microsoft/windows-rs/releases) +- [Getting started](https://kennykerr.ca/rust-getting-started/) +- [Samples](https://github.com/microsoft/windows-rs/tree/0.58.0/crates/samples) +- [Releases](https://github.com/microsoft/windows-rs/releases) Start by adding the following to your Cargo.toml file: @@ -15,7 +15,7 @@ version = "0.1" Make use of Windows version information as needed: -```rust,no_run +```rust use windows_version::*; fn main() { diff --git a/crates/libs/version/src/lib.rs b/crates/libs/version/src/lib.rs index 3209fc1d72..ddaaffbd41 100644 --- a/crates/libs/version/src/lib.rs +++ b/crates/libs/version/src/lib.rs @@ -1,6 +1,4 @@ -/*! -Learn more about Rust for Windows here: -*/ +#![doc = include_str!("../README.md")] #![cfg(windows)] #![cfg_attr(not(test), no_std)] diff --git a/crates/libs/windows/readme.md b/crates/libs/windows/readme.md index c61e93cbc9..3086da6113 100644 --- a/crates/libs/windows/readme.md +++ b/crates/libs/windows/readme.md @@ -49,39 +49,3 @@ fn main() -> Result<()> { Ok(()) } ``` - -## windows-sys - -The `windows-sys` crate is a zero-overhead fallback for the most demanding situations and primarily where the absolute best compile time is essential. It only includes function declarations (externs), structs, and constants. No convenience helpers, traits, or wrappers are provided. - -Start by adding the following to your Cargo.toml file: - -```toml -[dependencies.windows-sys] -version = "0.59" -features = [ - "Win32_Security", - "Win32_System_Threading", - "Win32_UI_WindowsAndMessaging", -] -``` - -Make use of any Windows APIs as needed: - -```rust,no_run -use windows_sys::{ - core::*, Win32::Foundation::*, Win32::System::Threading::*, Win32::UI::WindowsAndMessaging::*, -}; - -fn main() { - unsafe { - let event = CreateEventW(std::ptr::null(), 1, 0, std::ptr::null()); - SetEvent(event); - WaitForSingleObject(event, 0); - CloseHandle(event); - - MessageBoxA(0 as _, s!("Ansi"), s!("Caption"), MB_OK); - MessageBoxW(0 as _, w!("Wide"), w!("Caption"), MB_OK); - } -} -``` diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 01e207a06d..993523cf8a 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -1,10 +1,29 @@ #![cfg_attr(docsrs, doc = "This is a stub. The latest API documentation is here: ")] #![cfg_attr(docsrs, doc = "")] -/*! -Learn more about Rust for Windows here: -[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0) -*/ +#![cfg_attr( + all( + feature = "Data_Xml_Dom", + feature = "Win32_Security", + feature = "Win32_System_Threading", + feature = "Win32_UI_WindowsAndMessaging", + ), + doc = include_str!("../README.md"), +)] + +// fallback if not all features are enabled +#![cfg_attr( + all( + not(all( + feature = "Data_Xml_Dom", + feature = "Win32_Security", + feature = "Win32_System_Threading", + feature = "Win32_UI_WindowsAndMessaging", + )), + not(docsrs), + ), + doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)", +)] #![cfg(windows)] #![doc(html_no_source)] From e7af1343fe2f068235a76c5a926bcff22b1c90ff Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 14 Aug 2024 19:19:44 +0200 Subject: [PATCH 2/6] fix: yaml multilines --- .github/workflows/doc.yml | 60 +++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 7b89390de1..9cdc51916f 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -4,7 +4,7 @@ on: pull_request: push: paths-ignore: - - '.github/ISSUE_TEMPLATE/**' + - ".github/ISSUE_TEMPLATE/**" branches: - master @@ -23,10 +23,10 @@ jobs: - name: Doctests run: > cargo test --doc -p windows - -F Data_Xml_Dom - -F Win32_Security - -F Win32_System_Threading - -F Win32_UI_WindowsAndMessaging + -F Data_Xml_Dom + -F Win32_Security + -F Win32_System_Threading + -F Win32_UI_WindowsAndMessaging windows-sys: name: windows-sys @@ -39,9 +39,9 @@ jobs: - name: Doctests run: > cargo test --doc -p windows-sys - -F Win32_Security - -F Win32_System_Threading - -F Win32_UI_WindowsAndMessaging + -F Win32_Security + -F Win32_System_Threading + -F Win32_UI_WindowsAndMessaging other-crates: runs-on: windows-latest @@ -52,29 +52,29 @@ jobs: - name: Check run: > cargo doc --no-deps - -p windows-bindgen - -p windows-core - -p cppwinrt - -p windows-implement - -p windows-interface - -p windows-metadata - -p windows-registry - -p windows-result - -p windows-strings - -p windows-targets - -p windows-version + -p windows-bindgen + -p windows-core + -p cppwinrt + -p windows-implement + -p windows-interface + -p windows-metadata + -p windows-registry + -p windows-result + -p windows-strings + -p windows-targets + -p windows-version - name: Doctests run: > cargo test --doc - -p windows-bindgen - -p windows-core - -p cppwinrt - -p windows-implement - -p windows-interface - -p windows-metadata - -p windows-registry - -p windows-result - -p windows-strings - -p windows-targets - -p windows-version + -p windows-bindgen + -p windows-core + -p cppwinrt + -p windows-implement + -p windows-interface + -p windows-metadata + -p windows-registry + -p windows-result + -p windows-strings + -p windows-targets + -p windows-version From 8e5694523388b8c548db965c9a7fe16d54f38bfd Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 14 Aug 2024 19:28:39 +0200 Subject: [PATCH 3/6] fix: remove needless fn main from doctests --- crates/libs/cppwinrt/readme.md | 10 ++++------ crates/libs/targets/readme.md | 8 +++----- crates/libs/version/readme.md | 14 ++++++-------- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/crates/libs/cppwinrt/readme.md b/crates/libs/cppwinrt/readme.md index 2182d9ad8b..c05bcdcdba 100644 --- a/crates/libs/cppwinrt/readme.md +++ b/crates/libs/cppwinrt/readme.md @@ -16,12 +16,10 @@ version = "0.1" Use `cppwinrt` function as needed: ```rust -fn main() { - match cppwinrt::cppwinrt(["-help"]) { - Ok(output) => println!("{output}"), - Err(error) => println!("{error}"), - }; -} +match cppwinrt::cppwinrt(["-help"]) { + Ok(output) => println!("{output}"), + Err(error) => println!("{error}"), +}; ``` Source: diff --git a/crates/libs/targets/readme.md b/crates/libs/targets/readme.md index 58840c40f2..7ac5c64cf8 100644 --- a/crates/libs/targets/readme.md +++ b/crates/libs/targets/readme.md @@ -20,10 +20,8 @@ Use the `link` macro to define the external functions you wish to call: windows_targets::link!("kernel32.dll" "system" fn SetLastError(code: u32)); windows_targets::link!("kernel32.dll" "system" fn GetLastError() -> u32); -fn main() { - unsafe { - SetLastError(1234); - assert_eq!(GetLastError(), 1234); - } +unsafe { + SetLastError(1234); + assert_eq!(GetLastError(), 1234); } ``` diff --git a/crates/libs/version/readme.md b/crates/libs/version/readme.md index b274782a08..344fae4675 100644 --- a/crates/libs/version/readme.md +++ b/crates/libs/version/readme.md @@ -18,15 +18,13 @@ Make use of Windows version information as needed: ```rust use windows_version::*; -fn main() { - println!("Current version: {:?}", OsVersion::current()); +println!("Current version: {:?}", OsVersion::current()); - if is_server() { - println!("Running on a Windows Server release."); - } +if is_server() { + println!("Running on a Windows Server release."); +} - if OsVersion::current() >= OsVersion::new(10, 0, 0, 12345) { - println!("Can use a feature available on this version or later.") - } +if OsVersion::current() >= OsVersion::new(10, 0, 0, 12345) { + println!("Can use a feature available on this version or later.") } ``` From 100a7ed86487a73d335d40754c5f41da902c8e86 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 14 Aug 2024 19:29:28 +0200 Subject: [PATCH 4/6] fix: fmt --- crates/libs/core/src/lib.rs | 1 - crates/libs/cppwinrt/src/lib.rs | 1 - crates/libs/implement/src/lib.rs | 4 ++-- crates/libs/interface/src/lib.rs | 4 ++-- crates/libs/metadata/src/lib.rs | 1 - crates/libs/registry/src/lib.rs | 1 - crates/libs/result/src/lib.rs | 1 - crates/libs/strings/src/lib.rs | 1 - crates/libs/sys/src/lib.rs | 11 +---------- crates/libs/targets/src/lib.rs | 1 - crates/libs/version/src/lib.rs | 1 - crates/libs/windows/src/lib.rs | 16 +--------------- 12 files changed, 6 insertions(+), 37 deletions(-) diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index a43cb08633..272a762dd7 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![doc(html_no_source)] #![allow(non_snake_case)] #![cfg_attr( diff --git a/crates/libs/cppwinrt/src/lib.rs b/crates/libs/cppwinrt/src/lib.rs index 444e050407..b45b54e73e 100644 --- a/crates/libs/cppwinrt/src/lib.rs +++ b/crates/libs/cppwinrt/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![cfg(windows)] const VERSION: &str = "2.0.240405.15"; diff --git a/crates/libs/implement/src/lib.rs b/crates/libs/implement/src/lib.rs index 3ad13505b1..55847b8ecf 100644 --- a/crates/libs/implement/src/lib.rs +++ b/crates/libs/implement/src/lib.rs @@ -1,7 +1,7 @@ //! Implement COM interfaces for Rust types. -//! +//! //! Take a look at [macro@implement] for an example. -//! +//! //! Learn more about Rust for Windows here: use quote::{quote, ToTokens}; diff --git a/crates/libs/interface/src/lib.rs b/crates/libs/interface/src/lib.rs index c44f8eab27..c2341b6c85 100644 --- a/crates/libs/interface/src/lib.rs +++ b/crates/libs/interface/src/lib.rs @@ -1,7 +1,7 @@ //! Define COM interfaces to call or implement. -//! +//! //! Take a look at [macro@interface] for an example. -//! +//! //! Learn more about Rust for Windows here: use quote::quote; diff --git a/crates/libs/metadata/src/lib.rs b/crates/libs/metadata/src/lib.rs index 4aa1275faa..608b472963 100644 --- a/crates/libs/metadata/src/lib.rs +++ b/crates/libs/metadata/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![doc(hidden)] use std::cmp::Ordering; diff --git a/crates/libs/registry/src/lib.rs b/crates/libs/registry/src/lib.rs index 3ff734d3c0..a6cddb8f77 100644 --- a/crates/libs/registry/src/lib.rs +++ b/crates/libs/registry/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![cfg(windows)] #![no_std] diff --git a/crates/libs/result/src/lib.rs b/crates/libs/result/src/lib.rs index ba0ba6406e..ea42de4129 100644 --- a/crates/libs/result/src/lib.rs +++ b/crates/libs/result/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![cfg_attr( windows_debugger_visualizer, debugger_visualizer(natvis_file = "../.natvis") diff --git a/crates/libs/strings/src/lib.rs b/crates/libs/strings/src/lib.rs index d01eb25e76..e7442f0007 100644 --- a/crates/libs/strings/src/lib.rs +++ b/crates/libs/strings/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![cfg(windows)] #![allow(non_snake_case)] #![cfg_attr( diff --git a/crates/libs/sys/src/lib.rs b/crates/libs/sys/src/lib.rs index 79d562063b..d528b0684d 100644 --- a/crates/libs/sys/src/lib.rs +++ b/crates/libs/sys/src/lib.rs @@ -6,17 +6,8 @@ ), doc = include_str!("../README.md") )] - // fallback if not all features are enabled -#![cfg_attr( - not(all( - feature = "Win32_Security", - feature = "Win32_System_Threading", - feature = "Win32_UI_WindowsAndMessaging", - )), - doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)", -)] - +#![cfg_attr(not(all(feature = "Win32_Security", feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging",)), doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)")] #![no_std] #![doc(html_no_source)] #![allow(non_snake_case, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)] diff --git a/crates/libs/targets/src/lib.rs b/crates/libs/targets/src/lib.rs index f9ee390eea..19b0d6f226 100644 --- a/crates/libs/targets/src/lib.rs +++ b/crates/libs/targets/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![no_std] /// Defines an external function to import. diff --git a/crates/libs/version/src/lib.rs b/crates/libs/version/src/lib.rs index ddaaffbd41..232f051191 100644 --- a/crates/libs/version/src/lib.rs +++ b/crates/libs/version/src/lib.rs @@ -1,5 +1,4 @@ #![doc = include_str!("../README.md")] - #![cfg(windows)] #![cfg_attr(not(test), no_std)] diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index 993523cf8a..aa93b54180 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(docsrs, doc = "This is a stub. The latest API documentation is here: ")] #![cfg_attr(docsrs, doc = "")] - #![cfg_attr( all( feature = "Data_Xml_Dom", @@ -10,21 +9,8 @@ ), doc = include_str!("../README.md"), )] - // fallback if not all features are enabled -#![cfg_attr( - all( - not(all( - feature = "Data_Xml_Dom", - feature = "Win32_Security", - feature = "Win32_System_Threading", - feature = "Win32_UI_WindowsAndMessaging", - )), - not(docsrs), - ), - doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)", -)] - +#![cfg_attr(all(not(all(feature = "Data_Xml_Dom", feature = "Win32_Security", feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging",)), not(docsrs),), doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)")] #![cfg(windows)] #![doc(html_no_source)] #![allow(non_snake_case, clashing_extern_declarations, non_upper_case_globals, non_camel_case_types, missing_docs, clippy::all)] From 31a4f3a55aa0bfd6bba5b57624795928e687b969 Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 14 Aug 2024 19:32:32 +0200 Subject: [PATCH 5/6] fix: casing --- crates/libs/bindgen/src/lib.rs | 2 +- crates/libs/core/src/lib.rs | 2 +- crates/libs/cppwinrt/src/lib.rs | 2 +- crates/libs/metadata/src/lib.rs | 2 +- crates/libs/registry/src/lib.rs | 2 +- crates/libs/result/src/lib.rs | 2 +- crates/libs/strings/src/lib.rs | 2 +- crates/libs/sys/src/lib.rs | 2 +- crates/libs/targets/src/lib.rs | 2 +- crates/libs/version/src/lib.rs | 2 +- crates/libs/windows/src/lib.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/libs/bindgen/src/lib.rs b/crates/libs/bindgen/src/lib.rs index 406da7a6c5..4ecdc572d9 100644 --- a/crates/libs/bindgen/src/lib.rs +++ b/crates/libs/bindgen/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] mod args; mod error; diff --git a/crates/libs/core/src/lib.rs b/crates/libs/core/src/lib.rs index 272a762dd7..962e2eb6af 100644 --- a/crates/libs/core/src/lib.rs +++ b/crates/libs/core/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![doc(html_no_source)] #![allow(non_snake_case)] #![cfg_attr( diff --git a/crates/libs/cppwinrt/src/lib.rs b/crates/libs/cppwinrt/src/lib.rs index b45b54e73e..e82643e2da 100644 --- a/crates/libs/cppwinrt/src/lib.rs +++ b/crates/libs/cppwinrt/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![cfg(windows)] const VERSION: &str = "2.0.240405.15"; diff --git a/crates/libs/metadata/src/lib.rs b/crates/libs/metadata/src/lib.rs index 608b472963..01ddd4728d 100644 --- a/crates/libs/metadata/src/lib.rs +++ b/crates/libs/metadata/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![doc(hidden)] use std::cmp::Ordering; diff --git a/crates/libs/registry/src/lib.rs b/crates/libs/registry/src/lib.rs index a6cddb8f77..cf35f9d628 100644 --- a/crates/libs/registry/src/lib.rs +++ b/crates/libs/registry/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![cfg(windows)] #![no_std] diff --git a/crates/libs/result/src/lib.rs b/crates/libs/result/src/lib.rs index ea42de4129..fcea7ce7b5 100644 --- a/crates/libs/result/src/lib.rs +++ b/crates/libs/result/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![cfg_attr( windows_debugger_visualizer, debugger_visualizer(natvis_file = "../.natvis") diff --git a/crates/libs/strings/src/lib.rs b/crates/libs/strings/src/lib.rs index e7442f0007..12dc81321e 100644 --- a/crates/libs/strings/src/lib.rs +++ b/crates/libs/strings/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![cfg(windows)] #![allow(non_snake_case)] #![cfg_attr( diff --git a/crates/libs/sys/src/lib.rs b/crates/libs/sys/src/lib.rs index d528b0684d..43fa45204e 100644 --- a/crates/libs/sys/src/lib.rs +++ b/crates/libs/sys/src/lib.rs @@ -4,7 +4,7 @@ feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging", ), - doc = include_str!("../README.md") + doc = include_str!("../readme.md") )] // fallback if not all features are enabled #![cfg_attr(not(all(feature = "Win32_Security", feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging",)), doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)")] diff --git a/crates/libs/targets/src/lib.rs b/crates/libs/targets/src/lib.rs index 19b0d6f226..39ae950e6c 100644 --- a/crates/libs/targets/src/lib.rs +++ b/crates/libs/targets/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![no_std] /// Defines an external function to import. diff --git a/crates/libs/version/src/lib.rs b/crates/libs/version/src/lib.rs index 232f051191..5b197c9a44 100644 --- a/crates/libs/version/src/lib.rs +++ b/crates/libs/version/src/lib.rs @@ -1,4 +1,4 @@ -#![doc = include_str!("../README.md")] +#![doc = include_str!("../readme.md")] #![cfg(windows)] #![cfg_attr(not(test), no_std)] diff --git a/crates/libs/windows/src/lib.rs b/crates/libs/windows/src/lib.rs index aa93b54180..7127344120 100644 --- a/crates/libs/windows/src/lib.rs +++ b/crates/libs/windows/src/lib.rs @@ -7,7 +7,7 @@ feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging", ), - doc = include_str!("../README.md"), + doc = include_str!("../readme.md"), )] // fallback if not all features are enabled #![cfg_attr(all(not(all(feature = "Data_Xml_Dom", feature = "Win32_Security", feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging",)), not(docsrs),), doc = "Learn more about Rust for Windows here: \n\n[Feature search](https://microsoft.github.io/windows-rs/features/#/0.58.0)")] From 999805969ba070f46a5eb3639d639484144ee79b Mon Sep 17 00:00:00 2001 From: Nerixyz Date: Wed, 14 Aug 2024 19:33:28 +0200 Subject: [PATCH 6/6] fix: revert prettier auto-format --- .github/workflows/doc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 9cdc51916f..8cc66bdaf8 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -4,7 +4,7 @@ on: pull_request: push: paths-ignore: - - ".github/ISSUE_TEMPLATE/**" + - '.github/ISSUE_TEMPLATE/**' branches: - master