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

Add documentation for Rust support #83715

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

d3zd3z
Copy link
Collaborator

@d3zd3z d3zd3z commented Jan 8, 2025

This brings in some basic documentation for Rust support, as well as adding workflow support to build the rust docs as part of CI.

@zephyrbot
Copy link
Collaborator

zephyrbot commented Jan 8, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff

All manifest checks OK

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@zephyrbot zephyrbot added manifest manifest-zephyr-lang-rust DNM This PR should not be merged (Do Not Merge) labels Jan 8, 2025
@d3zd3z d3zd3z force-pushed the r/docs-2025-01-08 branch 26 times, most recently from 89e25b8 to 45860a3 Compare January 13, 2025 22:48
@d3zd3z d3zd3z force-pushed the r/docs-2025-01-08 branch 2 times, most recently from 56c3f29 to c60aaf1 Compare January 14, 2025 19:44
@d3zd3z d3zd3z force-pushed the r/docs-2025-01-08 branch 2 times, most recently from 56dda2d to 19e46e6 Compare January 24, 2025 22:40
Create an initial document describing how to get started a Rust application
on Zephyr.

Signed-off-by: David Brown <david.brown@linaro.org>
This adds a job that builds the rustdoc documentation.

Signed-off-by: David Brown <david.brown@linaro.org>
Include the generated Rust documentation in the published docs, both for PR
and for main, if they were generated.

Signed-off-by: David Brown <david.brown@linaro.org>
run: |
cargo --version
cd zephyr
west build -t rustdoc -b nrf52840dk/nrf52840 ../modules/lang/rust/docgen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is west really needed to build rust docs? Also, why is a board required? I'm a bit surprised that rust docs are not generated on its own repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do generate rust docs in that repo, but they aren't correlated with any particular Zephyr release. This builds the rust docs that are specifically the version brought in.

As far as why west and a board are needed:

  • The rust code uses bindgen to generate bindings to the Zephyr API. In order to parse headers, the generated header files are needed, this requires much of the build tools to get that far.
  • The rust docs will be generated based on specific Kconfig values. The docgen app is intended to enable as many as possible in order to get the fullest docs.
  • Picking a specific board will make the contents of the docs, specifically for zephyr::raw also specific to that board. I intend to have instructions in the docs for Rust explain how to generate and view the docs locally, so developers can have those be accurate for their configuration and board. But, we need something so that we can reference the docs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised that rust docs are not generated on its own repo.

They are. But, using them in the main docs would be a bit complicated logistically. Namely, we currently generate docs for each PR in the rust repo. These will stick around for I think two weeks. We also generate docs for main (well, we will, there is a small issue to fix that), but these are replaced each time a change is merged. If we wanted to directly use that artifact from here, we'd need to also generate them for specific shas, and somehow know to only retire those when a manifest doesn't refer to them. It would have to check every possible branch's manifest (there will be backport branches after the first release containing this).

It seems just easier to regenerate them in the Zephyr repo for the correct version, that way they'll persist according to the rules here (for each PR, the two weeks, and latest getting updated).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do generate rust docs in that repo, but they aren't correlated with any particular Zephyr release. This builds the rust docs that are specifically the version brought in.

As far as why west and a board are needed:

  • The rust code uses bindgen to generate bindings to the Zephyr API. In order to parse headers, the generated header files are needed, this requires much of the build tools to get that far.

I understand you need a build target, but picking a nordic board feels weird unless explained. I'd rather choose some vendor-agnostic target.

  • The rust docs will be generated based on specific Kconfig values. The docgen app is intended to enable as many as possible in order to get the fullest docs.

Is it using https://github.com/zephyrproject-rtos/zephyr/blob/main/doc/_extensions/zephyr/kconfig/__init__.py#L133 ?

  • Picking a specific board will make the contents of the docs, specifically for zephyr::raw also specific to that board. I intend to have instructions in the docs for Rust explain how to generate and view the docs locally, so developers can have those be accurate for their configuration and board. But, we need something so that we can reference the docs.

Maybe you should instead create a "rustdoc" board as a build target that enables as much zephyr raw as possible for docs purposes. In general, I don't think rust users should really bother about the APIs exposed depending on the board... And zephyr::raw should likely be kept as something internal people should not rely on their apps.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand you need a build target, but picking a nordic board feels weird unless explained. I'd rather choose some vendor-agnostic target.

I could do one of the qemu targets. I think this will be reasonably complete, as most shouldn't depend on the particular devices that are present. Someone wanting to navigate the rust version of their devicetree really needs to be generating docs locally for their specific build anyway.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I don't think rust users should really bother about the APIs exposed depending on the board

Where this really matters is with the generated modules representing their current device tree. The user will need to use this to be able to get instances of the devices on their platform. And, this doesn't make sense to have it be generic.

Copy link
Member

@nashif nashif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an optional module. doc builds and workflows should not depend on optional modules. Basically we now will be building the rust docs and publishing them on each PR and few times a day? This also pushes generated docs of an optional module to https://docs.zephyrproject.org/, is this what we want with any optional module? shouldn't all of this be published i.e. in the module GH domain instead and just linked? I think this requires some more discussion and thought.

d3zd3z added a commit to d3zd3z/zephyr that referenced this pull request Feb 4, 2025
Based on review feedback on zephyrproject-rtos#83715, bring in changes to rust documentation
to generate for a vendor neutral platform (qemu).  This also brings in a
small invalid link error that had somehow made it in.

Signed-off-by: David Brown <david.brown@linaro.org>
d3zd3z added a commit to d3zd3z/zephyr that referenced this pull request Feb 4, 2025
Based on review feedback on zephyrproject-rtos#83715, bring in changes to rust documentation
to generate for a vendor neutral platform (qemu).  This also brings in a
small invalid link error that had somehow made it in.

Signed-off-by: David Brown <david.brown@linaro.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants