2020-10-26 00:09:53 +03:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
use std::path::Path;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
fn main() {
|
2020-10-26 06:22:30 +03:00
|
|
|
let src_path = fs::canonicalize("./../builtins/bitcode/src/main.zig")
|
2020-10-26 00:09:53 +03:00
|
|
|
.expect("Failed to resolve bitcode source");
|
|
|
|
let src = src_path.to_str().expect("Invalid src path");
|
|
|
|
|
|
|
|
let out_dir = env::var_os("OUT_DIR").unwrap();
|
2020-10-27 03:37:02 +03:00
|
|
|
|
2020-10-26 06:22:30 +03:00
|
|
|
let dest_ll_path = Path::new(&out_dir).join("builtins.ll");
|
|
|
|
let dest_ll = dest_ll_path.to_str().expect("Invalid dest ir path");
|
2020-10-27 03:37:02 +03:00
|
|
|
let emit_ir_arg = "-femit-llvm-ir=".to_owned() + dest_ll;
|
2020-10-26 06:22:30 +03:00
|
|
|
Command::new("zig")
|
2020-10-27 03:37:02 +03:00
|
|
|
.args(&["build-obj", src, &emit_ir_arg, "-fno-emit-bin", "--strip", "-O", "ReleaseFast"])
|
2020-10-26 06:22:30 +03:00
|
|
|
.status()
|
|
|
|
.unwrap();
|
|
|
|
|
2020-10-27 03:37:02 +03:00
|
|
|
let dest_bc_path = Path::new(&out_dir).join("builtins.bc");
|
|
|
|
let dest_bc = dest_bc_path.to_str().expect("Invalid dest bc path");
|
2020-10-26 06:22:30 +03:00
|
|
|
Command::new("llvm-as")
|
|
|
|
.args(&[dest_ll, "-o", dest_bc])
|
2020-10-26 00:09:53 +03:00
|
|
|
.status()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
|
|
println!("cargo:rerun-if-changed={}", src);
|
2020-10-26 06:22:30 +03:00
|
|
|
println!("cargo:rustc-env=BUILTINS_BC={}", dest_bc);
|
2020-10-26 00:09:53 +03:00
|
|
|
}
|