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