drone-micropython-raw 0.1.1

Bindings to MicroPython.
extern crate bindgen;
extern crate make_cmd;

use make_cmd::make;
use std::env::{var, var_os};
use std::path::PathBuf;

fn main() {
  let target = var("TARGET").unwrap();
  let out_path = PathBuf::from(var_os("OUT_DIR").unwrap());
  let build_path = out_path
    .join("micropython")
    .into_os_string()
    .into_string()
    .unwrap();

  let mut make = make();
  make.arg("lib");
  make.arg(format!("BUILD={}", build_path));
  make.arg(format!("TARGET={}", target));
  if !make
    .status()
    .expect("make command failed to start")
    .success()
  {
    panic!("Build failed");
  }

  println!("cargo:rustc-link-search=native={}", build_path);
  println!("cargo:rustc-link-lib=static=micropython");

  let bindings = bindgen::builder()
    .header("src/wrapper.h")
    .clang_arg("-Isrc")
    .clang_arg("-Imicropython")
    .clang_arg(format!("-I{}", build_path))
    .use_core()
    .ctypes_prefix("::drone_ctypes")
    // FIXME https://github.com/rust-lang-nursery/rust-bindgen/issues/550
    .blacklist_type("max_align_t")
    .rustified_enum("mp_arg_flag_t")
    .rustified_enum("mp_binary_op_t")
    .rustified_enum("mp_fun_kind_t")
    .rustified_enum("mp_import_stat_t")
    .rustified_enum("_mp_map_lookup_kind_t")
    .rustified_enum("mp_parse_input_kind_t")
    .rustified_enum("mp_print_kind_t")
    .rustified_enum("mp_raw_code_kind_t")
    .rustified_enum("_mp_token_kind_t")
    .rustified_enum("mp_unary_op_t")
    .rustified_enum("mp_vm_return_kind_t")
    .generate()
    .expect("Unable to generate bindings");

  bindings
    .write_to_file(out_path.join("bindings.rs"))
    .expect("Couldn't write bindings!");
}