Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions crates/bin/docs_rs_web/templates/core/about/builds.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ <h4 id="setting-a-readme"> <a href="#setting-a-readme">Setting a README</a> </h4
<h4 id="detecting-docsrs"> <a href="#detecting-docsrs">Detecting Docs.rs</a> </h4>
<p>
To recognize Docs.rs from your Rust code, you can test for the <code>docsrs</code> cfg, e.g.:
{% filter dedent(None)|highlight("rust") -%}
#[cfg(docsrs)]
mod documentation;
{% filter highlight("rust") -%}
#[cfg(docsrs)]
mod documentation;
{%- endfilter %}
The `docsrs` cfg only applies to the final rustdoc invocation (i.e. the crate currently
being documented). It does not apply to dependencies (including workspace ones).
</p>
<p>
To recognize Docs.rs from <code>build.rs</code> files, you can test for the environment variable <code>DOCS_RS</code>, e.g.:
{% filter dedent(3)|highlight("rust") -%}
if std::env::var("DOCS_RS").is_ok() {
// ... your code here ...
}
{% filter highlight("rust") -%}
if std::env::var("DOCS_RS").is_ok() {
// ... your code here ...
}
{%- endfilter %}
This approach can be helpful if you need dependencies for building the library, but not for building the documentation.
</p>
Expand All @@ -56,9 +56,9 @@ <h4 id="cross-compiling"> <a href="#cross-compiling">Cross-compiling</a> </h4>

<p>
You can configure how your crate is built by adding <a href="metadata">package metadata</a> to your <code>Cargo.toml</code>, e.g.:
{% filter dedent(None)|highlight("toml") -%}
[package.metadata.docs.rs]
rustc-args = ["--cfg", "my_cfg"]
{% filter highlight("toml") -%}
[package.metadata.docs.rs]
rustc-args = ["--cfg", "my_cfg"]
{%- endfilter %}
Here, the compiler arguments are set so that <code>#[cfg(my_cfg)]</code> (not to be confused with <code>#[cfg(doc)]</code>) can be used for conditional compilation.
This approach is also useful for setting <a href="https://doc.rust-lang.org/cargo/reference/features.html">cargo features</a>.
Expand Down
Loading