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