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

APIView for Rust #9592

Draft
wants to merge 52 commits into
base: main
Choose a base branch
from

Conversation

HarshaNalluru
Copy link
Member

@HarshaNalluru HarshaNalluru commented Jan 7, 2025

Issue Azure/azure-sdk-for-rust#1621

Rust API Parser

This repository contains the tool for parsing rustdoc output into API view.

Links

Related work

Output from generate_api_report at Azure/azure-sdk-for-rust#2019 is fed into rust-api-parser here as input.

rust-api-parser

  • This TypeScript tool processes the cleaned JSON output from generate_api_report.
  • Generates a structured document representing the API view as text.
  • Generates a JSON document following the APIView JSON schema that lets us supply the file to the apiview tool directly.
  • Organizes the API elements into modules, functions, and other Rust constructs.

Usage

  1. Ensure you have Node.js installed. If not, you can install it from nodejs.org.
  2. Navigate to the get-api-view folder.
  3. Install the necessary dependencies by running:
    npm install
    npm install -g ts-node typescript
  4. Run the tool using:
    ts-node main.ts

To Dos

  • Transform the current output to the JSON schema expected by the API view tool
  • Expand the coverage to span all kinds of elements from the exported API surface
  • Finalize the workflow
  • Hook up with the APIView Web workflow

@RickWinter RickWinter requested a review from heaths January 7, 2025 17:35
@heaths
Copy link
Member

heaths commented Jan 10, 2025

It removes private items

Interesting. Last I looked only the public API surface i.e., anything reachable via public API, was included. How did you ascertain elements were truly private?

cargo build

You don't need to do this separately. Just have them run cargo run. Like dotnet run et. al., it'll restore, build, and run. IIRC, only node (npm or similar) makes you do it separately.

@HarshaNalluru
Copy link
Member Author

Last I looked only the public API surface i.e., anything reachable via public API, was included. How did you ascertain elements were truly private?

It's a miss on my part. By filtering with the visibility, I got a much smaller copy of the API that resembled my expected output. I shouldn't have called the others' private.

- JSON Schema expected by the APIView tool
- RustDoc JSON output encoding in Typescript
- segregating the item classification and parsing into different files, functions, modules and traits are done
@LarryOsterman
Copy link
Member

It removes private items

Interesting. Last I looked only the public API surface i.e., anything reachable via public API, was included. How did you ascertain elements were truly private?

Does this imply that Rust allows you to access the transitive closure of all types reachable via public API? That is a surprising behavior - most languages hide non-public elements of public APIs (and types referenced by public APIs). Some return errors if a non-public type is returned by a public API (I thought Rust did this), which means that private types reachable via public API were not a thing.

And wouldn't it be the job of rustdoc to figure out which types are public and which types are not public (in other words, the ApiView tool wouldn't necessarily have to handle this).

@HarshaNalluru HarshaNalluru changed the title APIView for Rust - Draft APIView for Rust Jan 27, 2025
@HarshaNalluru
Copy link
Member Author

Regarding the private items..

You're right @LarryOsterman. It's a miss on my part in the initial stages. Ignore the comment.
By filtering with the visibility, I got a much smaller copy of the API that resembled my expected output in the initial stages. I shouldn't have called the others' private.
I took my words back and the current version of the parser doesn't take those statements into account.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants