icydb_core/
macros.rs

1// start
2// macro to be included at the start of each canister lib.rs file
3#[macro_export]
4macro_rules! start {
5    () => {
6        // actor.rs
7        include!(concat!(env!("OUT_DIR"), "/actor.rs"));
8    };
9}
10
11// build
12// for the various build.rs files
13#[macro_export]
14macro_rules! build {
15    ($actor:expr) => {
16        use std::{env::var, fs::File, io::Write, path::PathBuf};
17
18        //
19        // CARGO
20        //
21        // should include the build flags we need to get
22        // different targets working
23        //
24
25        // all
26        println!("cargo:rerun-if-changed=build.rs");
27
28        // add the cfg flag
29        println!("cargo:rustc-check-cfg=cfg(icydb)");
30        println!("cargo:rustc-cfg=icydb");
31
32        // Get the output directory set by Cargo
33        let out_dir = var("OUT_DIR").expect("OUT_DIR not set");
34
35        //
36        // ACTOR CODE
37        //
38
39        let output = ::icydb::build::generate($actor);
40
41        // write the file
42        let actor_file = PathBuf::from(out_dir.clone()).join("actor.rs");
43        let mut file = File::create(actor_file)?;
44        file.write_all(output.as_bytes())?;
45    };
46}
47
48// db
49#[macro_export]
50#[allow(clippy::crate_in_macro_def)]
51macro_rules! db {
52    () => {
53        crate::db()
54    };
55
56    (debug) => {
57        crate::db().debug()
58    };
59}