Skip to content

Commit

Permalink
Adding features to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zakstucke committed Feb 16, 2024
1 parent e4584b2 commit 73c0c9f
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
with:
node-version: "20"

- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install rust toolchain (doc builds use nightly features)
uses: dtolnay/rust-toolchain@nightly

- name: Install dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion dev_scripts/docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ js_sub_build () {

# Builds the nested js site:
rust_sub_build () {
rm -rf ./docs/rust_ref && cargo doc --no-deps --manifest-path ./rust/Cargo.toml --target-dir ./docs/rust_ref
rm -rf ./docs/rust_ref && cargo +nightly doc --no-deps --manifest-path ./rust/Cargo.toml --target-dir ./docs/rust_ref --all-features
}

build () {
Expand Down
1 change: 1 addition & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ name = "bitbazaar"
crate-type = ["lib"]
path = "bitbazaar/lib.rs"

[build-dependencies]
rustc_version = "0.4.0"

[package.metadata.docs.rs]
# We use feature(doc_auto_cfg) so show which features needed for which code.
# For the features to show in docs.rs, need to tell it to include them:
all-features = true

[features]
cli = ['dep:normpath', 'dep:conch-parser', 'dep:homedir']
redis = ['dep:deadpool-redis', 'dep:redis', 'dep:sha1_smol']
Expand Down
2 changes: 2 additions & 0 deletions rust/bitbazaar/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![warn(clippy::disallowed_types)]
#![warn(missing_docs)]
// https://stackoverflow.com/questions/61417452/how-to-get-a-feature-requirement-tag-in-the-documentation-generated-by-cargo-do
#![cfg_attr(all(doc, CHANNEL_NIGHTLY), feature(doc_auto_cfg))]

//! bitbazaar - An assortment of publicly available cross-language utilities useful to my projects.
Expand Down
14 changes: 14 additions & 0 deletions rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use rustc_version::{version_meta, Channel};

// This build script sets the `cfg` flag `CHANNEL_STABLE`, `CHANNEL_BETA`, `CHANNEL_NIGHTLY` or `CHANNEL_DEV` depending on the release channel of the compiler being used.
// https://stackoverflow.com/questions/61417452/how-to-get-a-feature-requirement-tag-in-the-documentation-generated-by-cargo-do
fn main() {
// Set cfg flags depending on release channel
let channel = match version_meta().unwrap().channel {
Channel::Stable => "CHANNEL_STABLE",
Channel::Beta => "CHANNEL_BETA",
Channel::Nightly => "CHANNEL_NIGHTLY",
Channel::Dev => "CHANNEL_DEV",
};
println!("cargo:rustc-cfg={}", channel)
}

0 comments on commit 73c0c9f

Please sign in to comment.