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

docs: add root level documentation for all libraries #3202

Merged
merged 6 commits into from
Aug 15, 2024
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
49 changes: 49 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion crates/libs/bindgen/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 1 addition & 3 deletions crates/libs/bindgen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/
#![doc = include_str!("../readme.md")]

mod args;
mod error;
Expand Down
83 changes: 2 additions & 81 deletions crates/libs/core/readme.md
Original file line number Diff line number Diff line change
@@ -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!("<html>hello world</html>"))?;
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);
}
}
```
5 changes: 1 addition & 4 deletions crates/libs/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![doc(html_no_source)]
#![allow(non_snake_case)]
#![cfg_attr(
Expand Down
10 changes: 4 additions & 6 deletions crates/libs/cppwinrt/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions crates/libs/cppwinrt/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![cfg(windows)]

const VERSION: &str = "2.0.240405.15";
Expand Down
8 changes: 5 additions & 3 deletions crates/libs/implement/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/
//! Implement COM interfaces for Rust types.
//!
//! Take a look at [macro@implement] for an example.
//!
//! Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>

use quote::{quote, ToTokens};

Expand Down
8 changes: 5 additions & 3 deletions crates/libs/interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/
//! Define COM interfaces to call or implement.
//!
//! Take a look at [macro@interface] for an example.
//!
//! Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>

use quote::quote;
use syn::spanned::Spanned;
Expand Down
5 changes: 1 addition & 4 deletions crates/libs/metadata/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![doc(hidden)]

use std::cmp::Ordering;
Expand Down
5 changes: 1 addition & 4 deletions crates/libs/registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![cfg(windows)]
#![no_std]

Expand Down
5 changes: 1 addition & 4 deletions crates/libs/result/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![cfg_attr(
windows_debugger_visualizer,
debugger_visualizer(natvis_file = "../.natvis")
Expand Down
5 changes: 1 addition & 4 deletions crates/libs/strings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![cfg(windows)]
#![allow(non_snake_case)]
#![cfg_attr(
Expand Down
57 changes: 5 additions & 52 deletions crates/libs/sys/readme.md
Original file line number Diff line number Diff line change
@@ -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!("<html>hello world</html>"))?;

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
Expand Down
16 changes: 10 additions & 6 deletions crates/libs/sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>

[Feature search](https://microsoft.github.io/windows-rs/features/#/0.59.0)
*/

#![cfg_attr(
all(
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(not(all(feature = "Win32_Security", feature = "Win32_System_Threading", feature = "Win32_UI_WindowsAndMessaging",)), doc = "Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>\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)]
Expand Down
13 changes: 6 additions & 7 deletions crates/libs/targets/readme.md
Original file line number Diff line number Diff line change
@@ -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:

Expand All @@ -15,14 +16,12 @@ 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);

fn main() {
unsafe {
SetLastError(1234);
assert_eq!(GetLastError(), 1234);
}
unsafe {
SetLastError(1234);
assert_eq!(GetLastError(), 1234);
}
```
5 changes: 1 addition & 4 deletions crates/libs/targets/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
/*!
Learn more about Rust for Windows here: <https://github.com/microsoft/windows-rs>
*/

#![doc = include_str!("../readme.md")]
#![no_std]

/// Defines an external function to import.
Expand Down
Loading