crate_plugin_kit/install/mod.rs
1//! Installation: turning a plugin crate on crates.io into a loadable cdylib plus
2//! its manifest on disk.
3//!
4//! Two routes, chosen by [`crate::CratePluginKit::install`] based on
5//! [`crate::KitConfig::prefer_prebuilt`]:
6//!
7//! ```text
8//! prefer_prebuilt = true
9//! └─ prebuilt::try_install ──(no prebuilt published / cannot download)──> build_host::install
10//! prefer_prebuilt = false
11//! └─ build_host::install
12//! ```
13//!
14//! build-host is the default and the fallback: it goes through `cargo build` and
15//! therefore uses whatever registry or mirror the user has configured. prebuilt
16//! downloads from GitHub bypass those settings, so it is only an accelerator.
17
18pub mod build_host;
19pub mod prebuilt;
20
21use std::path::PathBuf;
22
23use crate::cache::InstallSource;
24
25/// The artifact of one successful install.
26#[derive(Debug, Clone)]
27pub struct Installed {
28 /// Full crate name, such as `bmux-plugin-cargo`.
29 pub crate_name: String,
30 /// The version actually installed.
31 pub version: String,
32 /// Install dir.
33 pub dir: PathBuf,
34 /// Path of the cdylib that landed on disk.
35 pub library: PathBuf,
36 /// Where it came from.
37 pub source: InstallSource,
38}
39
40/// Removes a directory (treating a missing one as success).
41pub(crate) fn remove_dir_if_exists(dir: &std::path::Path) -> std::io::Result<()> {
42 match std::fs::remove_dir_all(dir) {
43 Ok(()) => Ok(()),
44 Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(()),
45 Err(e) => Err(e),
46 }
47}