Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix: let the build continue to rustc on cbindgen failures
Browse files Browse the repository at this point in the history
silently remove autopush.h instead just in case cbindgen fails when rustc
doesn't (to indicate something went wrong)

Closes #1235
  • Loading branch information
pjenvey committed May 15, 2018
1 parent 8849b83 commit 46f048a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions autopush_rs/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
//! Generate autopush.h via cbindgen
extern crate cbindgen;

use std::env;
use std::{env, fs, path::PathBuf};

fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR undefined");
let pkg_name = env::var("CARGO_PKG_NAME").expect("CARGO_PKG_NAME undefined");
let target = format!("{}/target/{}.h", crate_dir, pkg_name);
cbindgen::Builder::new()
let target = PathBuf::from(format!("{}/target/{}.h", crate_dir, pkg_name));

let result = cbindgen::Builder::new()
.with_crate(crate_dir)
.with_language(cbindgen::Language::C)
.generate()
.expect("cbindgen unable to generate bindings")
.write_to_file(target.as_str());
.generate();
match result {
Ok(bindings) => {
bindings.write_to_file(target);
}
Err(e) => {
eprintln!("cbindgen unable to generate bindings: {}", e);
if target.exists() {
fs::remove_file(target).unwrap();
}
}
}
}

0 comments on commit 46f048a

Please sign in to comment.