Skip to content

Commit

Permalink
Fix docs.rs build
Browse files Browse the repository at this point in the history
  • Loading branch information
oberrich committed Apr 10, 2024
1 parent f3944a3 commit 4a19278
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ build = "src/build.rs"
description = "Rust bindings to the System Informer's (formerly known as Process Hacker) `phnt` native Windows headers"
# exclude = ["deps"]

[features]
vendored = []

[package.metadata.docs.rs]
all-features = true
default-target = "x86_64-pc-windows-msvc"
targets = ["x86_64-pc-windows-msvc"]
rustdoc-args = ["--cfg=docsrs"]
rustc-args = ["--cfg=docsrs"]
rustdoc-args = ["--cfg", "docsrs"]

[build-dependencies]
windows.features = ["Win32_Foundation"]
Expand Down
12 changes: 7 additions & 5 deletions src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,15 @@ impl BindgenConfig {
}
}

#[cfg(not(docsrs))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "vendored", docsrs))))]
#[cfg(any(feature = "vendored", docsrs))]
fn main() {
if cfg!(docsrs) {
println!("Skipping regeneration of bindings for docs.rs.");
return;
}
println!("Using vendored bindings, build script skipped.");
}

#[cfg_attr(docsrs, doc(cfg(all(not(feature = "vendored"), not(docsrs)))))]
#[cfg(all(not(feature = "vendored"), not(docsrs)))]
fn main() {
std::process::Command::new("git")
.args(["submodule", "update", "--remote", "--recursive"])
.output()
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
#![allow(
warnings,
Expand All @@ -31,12 +32,14 @@

/// Bindings for `phnt` (nightly) generated by `bindgen`
pub mod ffi {
// use vendored `generated.rs` for docs.rs
#[cfg(docsrs)]
// use vendored bindings
#[cfg_attr(docsrs, doc(cfg(any(feature = "vendored", docsrs))))]
#[cfg(any(feature = "vendored", docsrs))]
include!("ffi/generated.rs");

// use regenerated bindings in production
#[cfg(not(docsrs))]
// use re-generated bindings
#[cfg_attr(docsrs, doc(cfg(all(not(feature = "vendored"), not(docsrs)))))]
#[cfg(all(not(feature = "vendored"), not(docsrs)))]
include!(concat!(env!("OUT_DIR"), "\\generated.rs"));
}

Expand Down

0 comments on commit 4a19278

Please sign in to comment.