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