icydb_build/
macros.rs

1// build
2/// Build-script helper that runs IcyDB codegen for the specified canister actor path.
3#[macro_export]
4macro_rules! build {
5    ($actor:expr) => {
6        use std::{env::var, fs::File, io::Write, path::PathBuf};
7
8        //
9        // CARGO
10        //
11        // should include the build flags we need to get
12        // different targets working
13        //
14
15        // all
16        println!("cargo:rerun-if-changed=build.rs");
17
18        // add the cfg flag
19        println!("cargo:rustc-check-cfg=cfg(icydb)");
20        println!("cargo:rustc-cfg=icydb");
21
22        // Get the output directory set by Cargo
23        let out_dir = var("OUT_DIR").expect("OUT_DIR not set");
24
25        //
26        // ACTOR CODE
27        //
28
29        let output = ::icydb::build::generate($actor);
30
31        // write the file
32        let actor_file = PathBuf::from(out_dir.clone()).join("actor.rs");
33        let mut file = File::create(actor_file)?;
34        file.write_all(output.as_bytes())?;
35    };
36}