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