Skip to content

Commit 59f57c4

Browse files
committed
add docgen tools binary
This commit adds a `docgen` binary to the tools crate. This tool can generate a .json file describing the API based on parsing the `cbindgen` generated `rustls.h` header file using a tree-sitter C grammar. The produced JSON can in turn be used to generate markdown web documentation, or any other format required. Along with generating docs this tool applies some basic policy. In particular it requires that **all** public API items be documented or it will produce an error instead of the JSON data. We can extend this in the future to require (for example) describing arguments and return values in doc comments. The generated JSON has the following structure: ```json { "structs": [ .. ], "functions": : [ .. ], "callbacks": [ .. ], "enums": [ .. ], "externs": [ .. ], "aliases": [ .. ] } ``` Where each key is a general category of item: * Structure definitions * API function prototypes * Callback typedefs * Enum typedefs * Extern typedefs * Simple type alias typdefs Within each category items are described like: ```json { "anchor": "rustls-accepted", "comment": "A parsed ClientHello produced by a ...", "feature": null, "name": "rustls_accepted", "text": "```c\nstruct rustls_accepted\n```" }, ``` The anchor field is useful for creating anchor links that identify the item. The name is the actual name of the item. The comment is the C block comment content (with the block comment syntax removed, but other whitespace left as-is). If the item is surrounded by an ifdef guard for a crate feature, then the required feature name is used as the feature field. Lastly the text field holds the actual text that defines the item in rustls.h (without comment) as a C formatted markdown code block. Backtick references in comments that match anchor names (after replacing `_` with `-` and stripping an optional `()` suffix) are automatically hyperlinked.
1 parent 0e59eb5 commit 59f57c4

File tree

5 files changed

+891
-4
lines changed

5 files changed

+891
-4
lines changed

Cargo.lock

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ regex = "1.9.6"
2222
toml = { version = "0.6.0", default-features = false, features = ["parse"] }
2323
hickory-resolver = { version = "=0.25.0-alpha.4", features = ["dns-over-https-rustls", "webpki-roots"] }
2424
tokio = { version = "1.42.0", features = ["io-util", "macros", "net", "rt"] }
25+
serde = { version = "1", features = ["derive"] }
26+
serde_json = "1"
27+
tree-sitter = "0.23" # TODO(@cpu): handle breaking API changes for 0.24
28+
tree-sitter-c = "0.23"
29+
tree-sitter-md = "0.3"

tools/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ publish = false
88
rustls = { workspace = true }
99
hickory-resolver = { workspace = true }
1010
tokio = { workspace = true }
11-
12-
[[bin]]
13-
name = "ech_fetch"
14-
path = "src/ech_fetch.rs"
11+
serde = { workspace = true }
12+
serde_json = { workspace = true }
13+
tree-sitter = { workspace = true }
14+
tree-sitter-c = { workspace = true }
15+
tree-sitter-md = { workspace = true, features = ["parser"] }

0 commit comments

Comments
 (0)