bootstrap/core/config/toml/
dist.rs

1//! This module defines the `Dist` struct, which represents the `[dist]` table
2//! in the `bootstrap.toml` configuration file.
3//!
4//! The `[dist]` table contains options related to the distribution process,
5//! including signing, uploading artifacts, source tarballs, compression settings,
6//! and inclusion of specific tools.
7
8use serde::{Deserialize, Deserializer};
9
10use crate::core::config::toml::ReplaceOpt;
11use crate::core::config::{Merge, set};
12use crate::{Config, HashSet, PathBuf, define_config, exit};
13
14define_config! {
15    struct Dist {
16        sign_folder: Option<String> = "sign-folder",
17        upload_addr: Option<String> = "upload-addr",
18        src_tarball: Option<bool> = "src-tarball",
19        compression_formats: Option<Vec<String>> = "compression-formats",
20        compression_profile: Option<String> = "compression-profile",
21        include_mingw_linker: Option<bool> = "include-mingw-linker",
22        vendor: Option<bool> = "vendor",
23    }
24}
25
26impl Config {
27    /// Applies distribution-related configuration from the `Dist` struct
28    /// to the global `Config` structure.
29    pub fn apply_dist_config(&mut self, toml_dist: Option<Dist>) {
30        if let Some(dist) = toml_dist {
31            let Dist {
32                sign_folder,
33                upload_addr,
34                src_tarball,
35                compression_formats,
36                compression_profile,
37                include_mingw_linker,
38                vendor,
39            } = dist;
40            self.dist_sign_folder = sign_folder.map(PathBuf::from);
41            self.dist_upload_addr = upload_addr;
42            self.dist_compression_formats = compression_formats;
43            set(&mut self.dist_compression_profile, compression_profile);
44            set(&mut self.rust_dist_src, src_tarball);
45            set(&mut self.dist_include_mingw_linker, include_mingw_linker);
46            self.dist_vendor = vendor.unwrap_or_else(|| {
47                // If we're building from git or tarball sources, enable it by default.
48                self.rust_info.is_managed_git_subrepository() || self.rust_info.is_from_tarball()
49            });
50        }
51    }
52}