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 policy_gate;
29pub mod registry;
30pub mod release_set;
31pub mod replica_query;
32pub mod response_parse;
33pub mod subnet_catalog;
34pub mod table;
35#[cfg(test)]
36mod test_support;
37mod workspace_discovery;
38
39pub(crate) fn cargo_command() -> Command {
40    let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
41    let mut command = Command::new(cargo);
42
43    if let Some(toolchain) = std::env::var_os("RUSTUP_TOOLCHAIN") {
44        command.env("RUSTUP_TOOLCHAIN", toolchain);
45    }
46
47    command
48}
49
50pub(crate) fn icp_environment_from_env() -> String {
51    std::env::var("ICP_ENVIRONMENT").unwrap_or_else(|_| "local".to_string())
52}
53
54pub(crate) fn should_export_candid_artifacts(environment: &str) -> bool {
55    environment == "local"
56}
57
58pub(crate) fn remove_optional_file(path: &std::path::Path) -> std::io::Result<()> {
59    match std::fs::remove_file(path) {
60        Ok(()) => Ok(()),
61        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
62        Err(err) => Err(err),
63    }
64}
65
66#[cfg(test)]
67mod tests {
68    use super::should_export_candid_artifacts;
69
70    // Keep public Candid export restricted to local/development environments.
71    #[test]
72    fn candid_artifact_export_is_dev_only() {
73        assert!(should_export_candid_artifacts("local"));
74        assert!(!should_export_candid_artifacts("ic"));
75    }
76}