blob: 3510ef2e84999e4ae62171e84b7ed63ffbcf8a6f [file] [log] [blame] [edit]
// Copyright 2024 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use anyhow::Context;
use anyhow::Result;
use cbindgen::Config;
use cbindgen::EnumConfig;
use cbindgen::Language;
use cbindgen::RenameRule;
use std::env;
use std::path::PathBuf;
static COPYRIGHT_CLAUSE: &str = "// Copyright 2024 The ChromiumOS Authors
// 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 = "ARC_SETUP_RS_H_";
fn main() -> Result<()> {
extern crate cbindgen;
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let output_dir = PathBuf::from(env::var("OUT_DIR").context("failed to get OUT_DIR")?);
let output_file = output_dir
.join("arc-setup-rs.h")
.display()
.to_string();
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,
enumeration: EnumConfig {
rename_variants: RenameRule::ScreamingSnakeCase,
..Default::default()
},
..Default::default()
};
cbindgen::Builder::new()
.with_crate(crate_dir)
.with_config(config)
.with_parse_deps(true)
.with_parse_include(&["swap"])
.generate()
.context("Unable to generate bindings")?
.write_to_file(output_file);
Ok(())
}