Skip to main content

canic_host/
lib.rs

1//! Host-side build, install, deployment, fleet-template, and release-set helpers for Canic workspaces.
2
3use std::process::Command;
4
5pub mod adoption;
6mod artifact_io;
7mod bootstrap_store;
8mod build_profile;
9pub mod build_provenance;
10mod cache_file;
11pub mod canister_build;
12mod cargo_metadata;
13pub mod deployment_catalog;
14pub mod deployment_truth;
15pub mod duration;
16pub mod evidence_envelope;
17pub mod format;
18pub mod icp;
19pub mod icp_config;
20pub mod install_root;
21pub mod installed_deployment;
22pub mod nns_data_center;
23pub mod nns_node;
24pub mod nns_node_operator;
25pub mod nns_node_provider;
26pub mod nns_registry;
27mod nns_render;
28pub mod nns_topology;
29pub mod policy_gate;
30pub mod registry;
31pub mod release_set;
32pub mod replica_query;
33pub mod response_parse;
34pub mod subnet_catalog;
35pub mod table;
36#[cfg(test)]
37mod test_support;
38mod workspace_discovery;
39
40pub(crate) fn cargo_command() -> Command {
41    let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
42    let mut command = Command::new(cargo);
43
44    if let Some(toolchain) = std::env::var_os("RUSTUP_TOOLCHAIN") {
45        command.env("RUSTUP_TOOLCHAIN", toolchain);
46    }
47
48    command
49}
50
51pub(crate) fn icp_environment_from_env() -> String {
52    std::env::var("ICP_ENVIRONMENT").unwrap_or_else(|_| "local".to_string())
53}
54
55pub(crate) fn should_export_candid_artifacts(environment: &str) -> bool {
56    environment == "local"
57}
58
59pub(crate) fn remove_optional_file(path: &std::path::Path) -> std::io::Result<()> {
60    match std::fs::remove_file(path) {
61        Ok(()) => Ok(()),
62        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
63        Err(err) => Err(err),
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::should_export_candid_artifacts;
70
71    // Keep public Candid export restricted to local/development environments.
72    #[test]
73    fn candid_artifact_export_is_dev_only() {
74        assert!(should_export_candid_artifacts("local"));
75        assert!(!should_export_candid_artifacts("ic"));
76    }
77}