Skip to main content

canic_core/bootstrap/
mod.rs

1use crate::config::{Config, ConfigError, schema::ConfigModel};
2use std::sync::Arc;
3
4#[cfg(any(not(target_arch = "wasm32"), test))]
5mod render;
6
7#[doc(hidden)]
8pub mod compiled {
9    pub use crate::{
10        cdk::{candid::Principal, types::Cycles},
11        config::schema::{
12            AppConfig, AppInitMode, AuthConfig, CanisterConfig, CanisterKind, CanisterPool,
13            ConfigModel, DelegatedAuthCanisterConfig, DelegatedTokenConfig,
14            DelegationProofCacheConfig, DelegationProofCacheProfile, LogConfig, PoolImport,
15            RandomnessConfig, RandomnessSource, RoleAttestationConfig, ScalePool, ScalePoolPolicy,
16            ScalingConfig, ShardPool, ShardPoolPolicy, ShardingConfig, Standards,
17            StandardsCanisterConfig, SubnetConfig, TopupPolicy, Whitelist,
18        },
19        ids::{CanisterRole, SubnetRole},
20    };
21}
22
23///
24/// EmbeddedRootReleaseEntry
25///
26
27#[derive(Clone, Copy, Debug, Eq, PartialEq)]
28pub struct EmbeddedRootReleaseEntry {
29    pub role: &'static str,
30    pub wasm_module: &'static [u8],
31}
32
33///
34/// EmbeddedRootBootstrapEntry
35///
36
37#[derive(Clone, Copy, Debug, Eq, PartialEq)]
38pub struct EmbeddedRootBootstrapEntry {
39    pub role: &'static str,
40    pub wasm_module: &'static [u8],
41    pub artifact_path: &'static str,
42    pub embedded_artifact_path: &'static str,
43    pub artifact_kind: &'static str,
44    pub artifact_size_bytes: u64,
45    pub artifact_sha256_hex: &'static str,
46    pub decompressed_size_bytes: Option<u64>,
47    pub decompressed_sha256_hex: Option<&'static str>,
48}
49
50// Install a build-produced configuration model and its canonical TOML source.
51pub fn init_compiled_config(
52    config: ConfigModel,
53    source_toml: &str,
54) -> Result<Arc<ConfigModel>, ConfigError> {
55    Config::init_from_model(config, source_toml)
56}
57
58// Parse and validate the source TOML into a configuration model on host targets.
59#[cfg(any(not(target_arch = "wasm32"), test))]
60pub fn parse_config_model(toml: &str) -> Result<ConfigModel, ConfigError> {
61    Config::parse_toml(toml)
62}
63
64// Compact a validated Canic TOML source without changing value encodings.
65#[cfg(any(not(target_arch = "wasm32"), test))]
66#[must_use]
67pub fn compact_config_source(toml: &str) -> String {
68    let mut compact = String::new();
69
70    for line in toml.lines() {
71        let trimmed = line.trim();
72
73        if trimmed.is_empty() || trimmed.starts_with('#') {
74            continue;
75        }
76
77        compact.push_str(trimmed);
78        compact.push('\n');
79    }
80
81    compact
82}
83
84// Render the validated configuration model as Rust source for `include!` at runtime.
85#[cfg(any(not(target_arch = "wasm32"), test))]
86#[must_use]
87pub fn emit_config_model_source(config: &ConfigModel) -> String {
88    render::config_model(config)
89}