bootstrap/core/config/toml/
install.rs

1//! This module defines the `Install` struct, which represents the `[install]` table
2//! in the `bootstrap.toml` configuration file.
3//!
4//! The `[install]` table contains options that specify the installation paths
5//! for various components of the Rust toolchain. These paths determine where
6//! executables, libraries, documentation, and other files will be placed
7//! during the `install` stage of the build.
8
9use serde::{Deserialize, Deserializer};
10
11use crate::core::config::toml::ReplaceOpt;
12use crate::core::config::{Merge, set};
13use crate::{Config, HashSet, PathBuf, define_config, exit};
14
15define_config! {
16    /// TOML representation of various global install decisions.
17    struct Install {
18        prefix: Option<String> = "prefix",
19        sysconfdir: Option<String> = "sysconfdir",
20        docdir: Option<String> = "docdir",
21        bindir: Option<String> = "bindir",
22        libdir: Option<String> = "libdir",
23        mandir: Option<String> = "mandir",
24        datadir: Option<String> = "datadir",
25    }
26}
27
28impl Config {
29    /// Applies installation-related configuration from the `Install` struct
30    /// to the global `Config` structure.
31    pub fn apply_install_config(&mut self, toml_install: Option<Install>) {
32        if let Some(install) = toml_install {
33            let Install { prefix, sysconfdir, docdir, bindir, libdir, mandir, datadir } = install;
34            self.prefix = prefix.map(PathBuf::from);
35            self.sysconfdir = sysconfdir.map(PathBuf::from);
36            self.datadir = datadir.map(PathBuf::from);
37            self.docdir = docdir.map(PathBuf::from);
38            set(&mut self.bindir, bindir.map(PathBuf::from));
39            self.libdir = libdir.map(PathBuf::from);
40            self.mandir = mandir.map(PathBuf::from);
41        }
42    }
43}