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