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