Skip to content

Commit d2e4261

Browse files
[API View] Pin nightly for rustdoc JSON output (Azure#2356)
* Pin nightly-2025-01-12 * NIGHTLY_TOOLCHAIN_FOR_APIVIEW variable in rust.yml * revert rust.yml * Use rust-toolchain.toml * Remove NIGHTLY_TOOLCHAIN_FOR_APIVIEW variable * Update eng/pipelines/templates/variables/rust.yml * error message to run from the root --------- Co-authored-by: Heath Stewart <[email protected]>
1 parent 45fb8dd commit d2e4261

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

eng/tools/generate_api_report/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ license = "MIT"
66
repository = "https://github.com/azure/azure-sdk-for-rust"
77
rust-version = "1.80"
88

9+
[build-dependencies]
10+
serde = { version = "1.0", features = ["derive"] }
11+
toml = "0.8.20"
12+
913
[dependencies]
1014
rustdoc-types = "0.33.0"
1115
serde_json = "1.0"

eng/tools/generate_api_report/README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,38 @@ It uses the following command `cargo +nightly rustdoc -Z unstable-options --outp
77

88
## Version Compatibility
99

10-
When updating the `rustdoc-types` in Cargo.toml, ensure that the `rust-api-parser` in the tools repository is also updated along with this project.
10+
The project depends on specific version relationships between several components:
1111

12-
1. Check the `FORMAT_VERSION` value in the new version.
13-
2. Verify that it is compatible with your rustdoc JSON output version (generated by `cargo +nightly rustdoc ...`).
14-
3. If they do not match, you may need to use a different version of `rustdoc-types`.
12+
1. **rustdoc FORMAT_VERSION**: The rustdoc JSON output has a specific `FORMAT_VERSION` (currently 37). Different nightly versions of Rust may produce different format versions.
1513

16-
Current `FORMAT_VERSION`: 37 (as of rustdoc-types 0.33.0)
14+
2. **rustdoc-types crate**: The version of this dependency in Cargo.toml (currently 0.33.0) must be compatible with the JSON format version produced by the selected nightly toolchain.
15+
16+
3. **rust-api-parser**: This project in the azure-sdk-for-tools repository consumes the JSON files produced by this project and depends on the **rustdoc-types crate**. When updating the above components, ensure that the rust-api-parser tool is also updated to maintain compatibility.
17+
18+
### Version Update Process
19+
20+
When updating the nightly toolchain or the rustdoc-types crate, follow these steps:
21+
22+
- First check the `FORMAT_VERSION` in a sample JSON output from the new nightly
23+
- Update the rustdoc-types crate version to match
24+
- Update `rust-toolchain.toml` with the desired nightly toolchain version and run `rustup install`.
25+
- Update the rust-api-parser project in the azure-sdk-for-tools repository to ensure compatibility with the new JSON format
26+
- Test the complete workflow to ensure all tools in the chain remain compatible
1727

1828
## Usage
1929

2030
To run the tool, navigate to the root of the `azure-sdk-for-rust` repository and use the following command:
2131

2232
```sh
23-
cargo run --manifest-path eng/tools/generate_api_report/Cargo.toml -- --package package_name
33+
cargo run --manifest-path eng/tools/generate_api_report/Cargo.toml -- --package package_name
2434
```
2535

2636
Generates `package_name.rust.json` in the `sdk/service_folder/package_name/review` directory.
2737

2838
For example, to generate the report for a package named `azure_core`, run:
2939

3040
```bash
31-
cargo run --manifest-path eng/tools/generate_api_report/Cargo.toml -- --package azure_core
41+
cargo run --manifest-path eng/tools/generate_api_report/Cargo.toml -- --package azure_core
3242
```
3343

3444
## Functionality
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
use serde::Deserialize;
5+
use std::{fs, path::Path};
6+
7+
fn main() {
8+
let toolchain_file = Path::new(env!("CARGO_MANIFEST_DIR")).join("rust-toolchain.toml");
9+
let toolchain_content =
10+
fs::read_to_string(toolchain_file).expect("read rust-toolchain.toml from crate root");
11+
let manifest: Manifest =
12+
toml::from_str(&toolchain_content).expect("deserialize rust-toolchain.toml");
13+
println!(
14+
"cargo::rustc-env=TOOLCHAIN_CHANNEL={}",
15+
manifest.toolchain.channel
16+
);
17+
println!("cargo::rerun-if-changed=rust-toolchain.toml");
18+
}
19+
20+
#[derive(Debug, Deserialize)]
21+
struct Manifest {
22+
toolchain: Toolchain,
23+
}
24+
25+
#[derive(Debug, Deserialize)]
26+
struct Toolchain {
27+
channel: String,
28+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[toolchain]
2+
channel = "nightly-2025-01-12"
3+
components = [
4+
"cargo",
5+
"rust-docs",
6+
"rust-std",
7+
]

eng/tools/generate_api_report/src/main.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
14
use rustdoc_types::Crate;
25
use std::env;
36
use std::error::Error;
7+
use std::ffi::OsStr;
48
use std::fs::File;
59
use std::io::prelude::*;
610
use std::path::Path;
711
use std::process::Command;
812

913
fn main() -> Result<(), Box<dyn Error>> {
14+
// Verify we're running from the repository root
15+
if !Path::new("eng/tools/generate_api_report").exists() {
16+
return Err(
17+
"This tool must be run from the root of the azure-sdk-for-rust repository. Use: cargo run --manifest-path eng/tools/generate_api_report/Cargo.toml -- --package {package_name}".into(),
18+
);
19+
}
20+
1021
// Get the package name from command-line arguments
1122
let args: Vec<String> = env::args().collect();
1223
if args.len() != 3 || args[1] != "--package" {
@@ -18,17 +29,28 @@ fn main() -> Result<(), Box<dyn Error>> {
1829
let path = Path::new(&path_str);
1930

2031
// Call cargo +nightly rustdoc to generate the JSON file
21-
let output = Command::new("cargo")
22-
.arg("+nightly")
32+
let channel = env!("TOOLCHAIN_CHANNEL");
33+
let mut command = Command::new("cargo");
34+
command
35+
.arg(format!("+{channel}"))
2336
.arg("rustdoc")
2437
.arg("-Z")
2538
.arg("unstable-options")
2639
.arg("--output-format")
2740
.arg("json")
2841
.arg("--package")
2942
.arg(package_name)
30-
.arg("--all-features")
31-
.output()?;
43+
.arg("--all-features");
44+
println!(
45+
"Running: {} {}",
46+
command.get_program().to_string_lossy(),
47+
command
48+
.get_args()
49+
.collect::<Vec<&OsStr>>()
50+
.join(OsStr::new(" "))
51+
.to_string_lossy(),
52+
);
53+
let output = command.output()?;
3254

3355
if !output.status.success() {
3456
eprintln!(
@@ -42,6 +64,8 @@ fn main() -> Result<(), Box<dyn Error>> {
4264
let mut contents = String::new();
4365
file.read_to_string(&mut contents)?;
4466

67+
println!("Processing rustdoc output for package: {}", package_name);
68+
4569
let mut root: Crate = serde_json::from_str(&contents)?;
4670

4771
// Remove items

0 commit comments

Comments
 (0)