| 1 |
# Generating documentation |
| 2 |
And finally the last feature. |
| 3 |
Just run the following command in the folder of the safe wrapper crate: |
| 4 |
|
| 5 |
```sh |
| 6 |
gir -c Gir.toml -d ../gir-files --doc-target-path docs.md -m doc |
| 7 |
``` |
| 8 |
|
| 9 |
* `-d ../gir-files`: flag to select the folder containing the .gir files. |
| 10 |
* `--doc-target-path docs.md`: flag to select the name of the markdown file containing the documentation. |
| 11 |
* `-m doc`: flag to select the work mode for generating the documentation. |
| 12 |
|
| 13 |
It'll generate a markdown file if everything went fine. |
| 14 |
It contains all of the crate's documentation. |
| 15 |
If you want to put it into your crate's source code like "normal" doc comments, run: |
| 16 |
|
| 17 |
```sh |
| 18 |
cargo install rustdoc-stripper |
| 19 |
rustdoc-stripper -g -o docs.md |
| 20 |
``` |
| 21 |
|
| 22 |
And now your crate should be completely documented as expected! |
| 23 |
|
| 24 |
Running the above commands again would duplicate the doc comments. |
| 25 |
Make sure to first remove the old ones before running the command again. |
| 26 |
You can do this by running the following commands: |
| 27 |
|
| 28 |
```sh |
| 29 |
rustdoc-stripper -s -n |
| 30 |
rustdoc-stripper -g -o docs.md |
| 31 |
``` |
| 32 |
|
| 33 |
Try building the documentation and also try it with the various features you might have: |
| 34 |
|
| 35 |
```sh |
| 36 |
cargo doc |
| 37 |
``` |
| 38 |
|
| 39 |
For building the docs on systems without the required dependencies installed, you can set the `DOCS_RS` environment variable. It is automatically set when building crates on docs.rs. |
| 40 |
This will disable the linking of the underlying C libraries and won't throw an error if those libraries are not available. |
| 41 |
|
| 42 |
On top of that, using the nightly compiler toolchain will enable the [doc_cfg feature](https://doc.rust-lang.org/beta/unstable-book/language-features/doc-cfg.html). |
| 43 |
This is mostly useful for clarifying feature requirements through the docs. |
| 44 |
|
| 45 |
To build the docs with the `DOCS_RS` environment variable, you can use the following command: |
| 46 |
|
| 47 |
```sh |
| 48 |
DOCS_RS=1 cargo +nightly doc --all-features |
| 49 |
``` |
| 50 |
|
| 51 |
Congratulations, we are done. |
| 52 |
You have successfully created the safe wrapper for a C library! |
| 53 |
|
| 54 |
You can easily publish your generated bindings and the wrapper to crates.io to allow others to use it. |
| 55 |
Publishing crates is easy but keep in mind that they need to be maintained as well. |
| 56 |
We set up the project folder in a way that easily allows sharing the code. |
| 57 |
All that is needed is to add some information to your Cargo.toml. |
| 58 |
Gir will not override them when you re-generate bindings. |
| 59 |
Easy, right. |
| 60 |
If this is your first time publishing a crate, you can find a detailed guide [here](https://doc.rust-lang.org/cargo/reference/publishing.html). |
| 61 |
|
| 62 |
Feel free to go back to the chapter about the [Cargo.toml file of the safe wrapper](high_level_rust_api.md#the-cargotoml-file) to read more about it. |
| 63 |
If you skip this step, your crate and all crates depending on it will not have documentation available on docs.rs. |