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