icydb_core/
macros.rs

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