Skip to main content

canic_host/
lib.rs

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