2022-09-13 17:55:17 +00:00
|
|
|
// Copyright 2022 The ChromiumOS Authors
|
2022-04-14 08:15:23 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2022-03-25 23:10:28 +00:00
|
|
|
|
|
|
|
use std::env;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2022-07-27 18:11:32 +00:00
|
|
|
use anyhow::Context;
|
|
|
|
use anyhow::Result;
|
|
|
|
use cbindgen::Config;
|
|
|
|
use cbindgen::Language;
|
2022-04-14 08:56:47 +00:00
|
|
|
|
2022-09-13 17:55:17 +00:00
|
|
|
static COPYRIGHT_CLAUSE: &str = "// Copyright 2022 The ChromiumOS Authors
|
2022-06-20 08:19:59 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.";
|
|
|
|
|
|
|
|
static AUTOGENERATED_DISCLAIMER: &str =
|
|
|
|
"/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */";
|
|
|
|
|
|
|
|
static INCLUDE_GUARD: &str = "CROSVM_CONTROL_H_";
|
|
|
|
|
2022-04-14 08:56:47 +00:00
|
|
|
fn main() -> Result<()> {
|
2022-04-14 08:59:29 +00:00
|
|
|
// Skip building dependencies when generating documents.
|
|
|
|
if std::env::var("CARGO_DOC").is_ok() {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2022-03-25 23:10:28 +00:00
|
|
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
|
|
|
2022-04-14 08:56:47 +00:00
|
|
|
let target_dir = env::var("OUT_DIR").context("failed to get OUT_DIR")?;
|
|
|
|
let output_file = PathBuf::from(target_dir)
|
2022-03-25 23:10:28 +00:00
|
|
|
.join("crosvm_control.h")
|
|
|
|
.display()
|
|
|
|
.to_string();
|
|
|
|
|
2022-06-20 08:19:59 +00:00
|
|
|
let config = Config {
|
|
|
|
language: Language::C,
|
|
|
|
cpp_compat: true,
|
|
|
|
header: Some(String::from(COPYRIGHT_CLAUSE)),
|
|
|
|
include_guard: Some(String::from(INCLUDE_GUARD)),
|
|
|
|
autogen_warning: Some(String::from(AUTOGENERATED_DISCLAIMER)),
|
|
|
|
include_version: true,
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2022-03-25 23:10:28 +00:00
|
|
|
cbindgen::Builder::new()
|
|
|
|
.with_crate(crate_dir)
|
2022-06-20 08:19:59 +00:00
|
|
|
.with_config(config)
|
2022-03-25 23:10:28 +00:00
|
|
|
.generate()
|
2022-04-14 08:56:47 +00:00
|
|
|
.context("Unable to generate bindings")?
|
2022-03-25 23:10:28 +00:00
|
|
|
.write_to_file(&output_file);
|
2022-04-14 08:56:47 +00:00
|
|
|
|
|
|
|
Ok(())
|
2022-03-25 23:10:28 +00:00
|
|
|
}
|