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;
10pub mod canister_build;
11mod cargo_metadata;
12pub mod deployment_catalog;
13pub mod deployment_truth;
14pub mod evidence_envelope;
15pub mod format;
16pub mod icp;
17pub mod icp_config;
18pub mod install_root;
19pub mod installed_deployment;
20pub mod policy_gate;
21pub mod registry;
22pub mod release_set;
23pub mod replica_query;
24pub mod response_parse;
25pub mod table;
26#[cfg(test)]
27mod test_support;
28mod workspace_discovery;
29
30pub(crate) fn cargo_command() -> Command {
31    let cargo = std::env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
32    let mut command = Command::new(cargo);
33
34    if let Some(toolchain) = std::env::var_os("RUSTUP_TOOLCHAIN") {
35        command.env("RUSTUP_TOOLCHAIN", toolchain);
36    }
37
38    command
39}
40
41pub(crate) fn icp_environment_from_env() -> String {
42    std::env::var("ICP_ENVIRONMENT").unwrap_or_else(|_| "local".to_string())
43}
44
45pub(crate) fn should_export_candid_artifacts(environment: &str) -> bool {
46    environment == "local"
47}
48
49pub(crate) fn remove_optional_file(path: &std::path::Path) -> std::io::Result<()> {
50    match std::fs::remove_file(path) {
51        Ok(()) => Ok(()),
52        Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(()),
53        Err(err) => Err(err),
54    }
55}
56
57#[cfg(test)]
58mod tests {
59    use super::should_export_candid_artifacts;
60
61    // Keep public Candid export restricted to local/development environments.
62    #[test]
63    fn candid_artifact_export_is_dev_only() {
64        assert!(should_export_candid_artifacts("local"));
65        assert!(!should_export_candid_artifacts("ic"));
66    }
67}