Skip to main content

cargo_dist/backend/installer/
mod.rs

1//! Installer Generation
2//!
3//! In the future this might get split up into submodules.
4
5use std::collections::BTreeMap;
6
7use camino::Utf8PathBuf;
8use cargo_dist_schema::{ArtifactId, EnvironmentVariables, Hosting, TripleName};
9use homebrew::HomebrewFragments;
10use macpkg::PkgInstallerInfo;
11use serde::Serialize;
12
13use crate::{
14    config::{JinjaInstallPathStrategy, LibraryStyle, ZipStyle},
15    platform::{PlatformSupport, RuntimeConditions},
16    InstallReceipt, ReleaseIdx,
17};
18
19use self::homebrew::HomebrewInstallerInfo;
20use self::msi::MsiInstallerInfo;
21use self::npm::NpmInstallerInfo;
22
23pub mod homebrew;
24pub mod macpkg;
25pub mod msi;
26pub mod npm;
27pub mod powershell;
28pub mod shell;
29
30/// A kind of an installer
31#[derive(Debug, Clone)]
32#[allow(clippy::large_enum_variant)]
33pub enum InstallerImpl {
34    /// shell installer script
35    Shell(InstallerInfo),
36    /// powershell installer script
37    Powershell(InstallerInfo),
38    /// npm installer package
39    Npm(NpmInstallerInfo),
40    /// Homebrew formula
41    Homebrew(HomebrewImpl),
42    /// Windows msi installer
43    Msi(MsiInstallerInfo),
44    /// Mac pkg installer
45    Pkg(PkgInstallerInfo),
46}
47
48/// Information needed to make a homebrew installer
49#[derive(Debug, Clone)]
50pub struct HomebrewImpl {
51    /// Base information
52    pub info: HomebrewInstallerInfo,
53
54    /// Various fragments (arm64 mac, x86_64 mac, arm64 linux, x86_64 linux, etc.)
55    pub fragments: HomebrewFragments<ExecutableZipFragment>,
56}
57
58/// Generic info about an installer
59#[derive(Debug, Clone, Serialize)]
60pub struct InstallerInfo {
61    /// The parent release
62    #[serde(skip)]
63    pub release: ReleaseIdx,
64    /// The path to generate the installer at
65    pub dest_path: Utf8PathBuf,
66    /// App name to use (display only)
67    pub app_name: String,
68    /// App version to use (display only)
69    pub app_version: String,
70    /// URL of the directory where artifacts can be fetched from
71    pub base_urls: Vec<String>,
72    /// Full information about configured hosting
73    pub hosting: Hosting,
74    /// Artifacts this installer can fetch
75    pub artifacts: Vec<ExecutableZipFragment>,
76    /// Description of the installer (a good heading)
77    pub desc: String,
78    /// Hint for how to run the installer
79    pub hint: String,
80    /// Where to install binaries
81    pub install_paths: Vec<JinjaInstallPathStrategy>,
82    /// Custom message to display on install success
83    pub install_success_msg: String,
84    /// Install receipt to write, if any
85    pub receipt: Option<InstallReceipt>,
86    /// Aliases to install binaries under
87    pub bin_aliases: BTreeMap<TripleName, BTreeMap<String, Vec<String>>>,
88    /// Whether to install generated C dynamic libraries
89    pub install_libraries: Vec<LibraryStyle>,
90    /// Platform-specific runtime conditions
91    pub runtime_conditions: RuntimeConditions,
92    /// platform support matrix
93    pub platform_support: Option<PlatformSupport>,
94    /// Environment variables for installer customization
95    pub env_vars: Option<EnvironmentVariables>,
96}
97
98/// A fake fragment of an ExecutableZip artifact for installers
99#[derive(Debug, Clone, Serialize)]
100pub struct ExecutableZipFragment {
101    /// The id of the artifact
102    pub id: ArtifactId,
103    /// The target the artifact supports
104    pub target_triple: TripleName,
105    /// The executables the artifact contains (name, assumed at root)
106    pub executables: Vec<String>,
107    /// The dynamic libraries the artifact contains (name, assumed at root)
108    pub cdylibs: Vec<String>,
109    /// The static libraries the artifact contains (name, assumed at root)
110    pub cstaticlibs: Vec<String>,
111    /// The style of zip this is
112    pub zip_style: ZipStyle,
113    /// The updater associated with this platform
114    pub updater: Option<UpdaterFragment>,
115    /// Conditions the system being installed to should ideally satisfy to install this
116    pub runtime_conditions: RuntimeConditions,
117}
118
119/// A fake fragment of an Updater artifact for installers
120#[derive(Debug, Clone, Serialize)]
121pub struct UpdaterFragment {
122    /// The id of the artifact
123    pub id: ArtifactId,
124    /// The binary the artifact contains (name, assumed at root)
125    pub binary: ArtifactId,
126}