roc/compiler/gen/build.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

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")
.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])
.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);
}