crosvm/crosvm_control/build.rs
Keiichi Watanabe 94e753c41e crosvm_control: Skip build.rs when cargo-doc is called
This will fix GitHub Action's failure.
This couldn't be caught in kokoro because kokoro sets correct
environment variables for testing.

BUG=none
TEST=./tools/cargo-doc

Change-Id: I1db2e459422e755f6231cb0a6e5e082ffa0727ae
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3581449
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Kameron Lutes <kalutes@chromium.org>
2022-04-21 00:17:25 +00:00

31 lines
844 B
Rust

// Copyright 2022 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::env;
use std::path::PathBuf;
use anyhow::{Context, Result};
fn main() -> Result<()> {
// Skip building dependencies when generating documents.
if std::env::var("CARGO_DOC").is_ok() {
return Ok(());
}
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let target_dir = env::var("OUT_DIR").context("failed to get OUT_DIR")?;
let output_file = PathBuf::from(target_dir)
.join("crosvm_control.h")
.display()
.to_string();
cbindgen::Builder::new()
.with_crate(crate_dir)
.generate()
.context("Unable to generate bindings")?
.write_to_file(&output_file);
Ok(())
}