Skip to main content

icydb_build/
macros.rs

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