Skip to content

Commit

Permalink
libosdp-sys: Add out_dir as include dir in build.rs for osdp_export.h
Browse files Browse the repository at this point in the history
Signed-off-by: Siddharth Chandrasekaran <sidcha.dev@gmail.com>
  • Loading branch information
sidcha committed Mar 24, 2024
1 parent aba4009 commit a4187ee
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions libosdp-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ use std::{
};
type Result<T> = anyhow::Result<T, anyhow::Error>;

const OSDP_EXPORT_CONTENT: &str = "/* Auto generated from build.rs */
#ifndef OSDP_EXPORT_H_
#define OSDP_EXPORT_H_
#define OSDP_EXPORT
#define OSDP_NO_EXPORT
#define OSDP_DEPRECATED_EXPORT
#endif /* OSDP_EXPORT_H_ */
";

fn path_join(root: &str, path: &str) -> String {
Path::new(root)
.join(path)
Expand Down Expand Up @@ -64,11 +75,11 @@ impl GitInfo {
}

fn generate_osdp_build_headers(out_dir: &str) -> Result<()> {
// Add an empty file as we don't
let data = "#define OSDP_EXPORT";
std::fs::write(path_join(out_dir, "osdp_export.h"), data)
/* generate osdp_export.h */
std::fs::write(path_join(out_dir, "osdp_export.h"), OSDP_EXPORT_CONTENT)
.context("Failed to create osdp_export.h")?;

/* generate osdp_config.h */
let git = GitInfo::new()?;
let src = "vendor/src/osdp_config.h.in";
let dest = path_join(out_dir, "osdp_config.h");
Expand All @@ -95,6 +106,8 @@ fn main() -> Result<()> {

generate_osdp_build_headers(&out_dir)?;

/* build LibOSDP */

let mut build = cc::Build::new();
let mut build = build
.include("vendor/src")
Expand Down Expand Up @@ -151,8 +164,14 @@ fn main() -> Result<()> {

build.compile("libosdp.a");

/* generate bindings */

let args = vec![
format!("-I{}", &out_dir),
];
let bindings = bindgen::Builder::default()
.header("vendor/include/osdp.h")
.clang_args(args)
.generate()
.context("Unable to generate bindings")?;

Expand Down

0 comments on commit a4187ee

Please sign in to comment.