-
Notifications
You must be signed in to change notification settings - Fork 167
/
build.rs
42 lines (33 loc) · 1.49 KB
/
build.rs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{env, path::Path};
use assembly::{
diagnostics::{IntoDiagnostic, Result},
Assembler, Library, LibraryNamespace,
};
// CONSTANTS
// ================================================================================================
const ASM_DIR_PATH: &str = "asm";
const ASL_DIR_PATH: &str = "assets";
// PRE-PROCESSING
// ================================================================================================
/// Read and parse the contents from `./asm` into a `LibraryContents` struct, serializing it into
/// `assets` folder under `std` namespace.
fn main() -> Result<()> {
// re-build the `[OUT_DIR]/assets/std.masl` file iff something in the `./asm` directory
// or its builder changed:
println!("cargo:rerun-if-changed=asm");
println!("cargo:rerun-if-changed=../assembly/src");
let manifest_dir = env!("CARGO_MANIFEST_DIR");
let asm_dir = Path::new(manifest_dir).join(ASM_DIR_PATH);
let assembler = Assembler::default().with_debug_mode(cfg!(feature = "with-debug-info"));
let namespace = "std".parse::<LibraryNamespace>().expect("invalid base namespace");
let stdlib = Library::from_dir(asm_dir, namespace, assembler)?;
// write the masl output
let build_dir = env::var("OUT_DIR").unwrap();
let build_dir = Path::new(&build_dir);
let output_file = build_dir
.join(ASL_DIR_PATH)
.join("std")
.with_extension(Library::LIBRARY_EXTENSION);
stdlib.write_to_file(output_file).into_diagnostic()?;
Ok(())
}