build.rs 813 Bytes
Newer Older
nhynes committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
extern crate ar;

use std::{env, path::PathBuf, process::Command};

use ar::Builder;
use std::fs::File;

fn main() {
  let out_dir = env::var("OUT_DIR").unwrap();

  let output = Command::new(concat!(
    env!("CARGO_MANIFEST_DIR"),
    "/src/build_test_lib.py"
  )).arg(&out_dir)
    .output()
    .expect("Failed to execute command");
  if output.stderr.len() > 0 {
    panic!(String::from_utf8(output.stderr).unwrap());
  }

  let in_path: PathBuf = [&out_dir, "test.o"].iter().collect();
  let out_path: PathBuf = [&out_dir, "libtest.a"].iter().collect();
  let mut builder = Builder::new(File::create(out_path.to_str().unwrap()).unwrap());
  builder.append_path(in_path.to_str().unwrap()).unwrap();

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