Skip to content

Commit 8a807cd

Browse files
committed
This commit adds a toml module that represents various subsections of bootstrap.toml.
The module primarily defines the TOML representations of these subsections and their corresponding configuration parsing implementations, which are ultimately integrated into the main configuration. - `mod.rs` – Serves as the entry point for the TOML configuration and defines the `TomlConfig` struct along with its parsing implementation. - `rust.rs` – Defines the `Rust` subsection struct and its configuration parsing implementation. - `target.rs` – Defines the `Target` subsection struct and its configuration parsing implementation. - `llvm.rs` – Defines the `Llvm` subsection struct and its configuration parsing implementation. - `install.rs` – Defines the `Install` subsection struct and its configuration parsing implementation. - `gcc.rs` – Defines the `Gcc` subsection struct and its configuration parsing implementation. - `dist.rs` – Defines the `Dist` subsection struct and its configuration parsing implementation. - `build.rs` – Defines the `Build` subsection struct and its configuration parsing implementation.
1 parent b17dba4 commit 8a807cd

File tree

9 files changed

+1541
-0
lines changed

9 files changed

+1541
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//! This module defines the `Build` struct, which represents the `[build]` table
2+
//! in the `bootstrap.toml` configuration file.
3+
//!
4+
//! The `[build]` table contains global options that influence the overall build process,
5+
//! such as default host and target triples, paths to tools, build directories, and
6+
//! various feature flags. These options apply across different stages and components
7+
//! unless specifically overridden by other configuration sections or command-line flags.
8+
9+
use serde::{Deserialize, Deserializer};
10+
11+
use crate::core::config::toml::ReplaceOpt;
12+
use crate::core::config::{Merge, StringOrBool};
13+
use crate::{HashSet, PathBuf, define_config, exit};
14+
15+
define_config! {
16+
/// TOML representation of various global build decisions.
17+
#[derive(Default)]
18+
struct Build {
19+
build: Option<String> = "build",
20+
description: Option<String> = "description",
21+
host: Option<Vec<String>> = "host",
22+
target: Option<Vec<String>> = "target",
23+
build_dir: Option<String> = "build-dir",
24+
cargo: Option<PathBuf> = "cargo",
25+
rustc: Option<PathBuf> = "rustc",
26+
rustfmt: Option<PathBuf> = "rustfmt",
27+
cargo_clippy: Option<PathBuf> = "cargo-clippy",
28+
docs: Option<bool> = "docs",
29+
compiler_docs: Option<bool> = "compiler-docs",
30+
library_docs_private_items: Option<bool> = "library-docs-private-items",
31+
docs_minification: Option<bool> = "docs-minification",
32+
submodules: Option<bool> = "submodules",
33+
gdb: Option<String> = "gdb",
34+
lldb: Option<String> = "lldb",
35+
nodejs: Option<String> = "nodejs",
36+
npm: Option<String> = "npm",
37+
python: Option<String> = "python",
38+
reuse: Option<String> = "reuse",
39+
locked_deps: Option<bool> = "locked-deps",
40+
vendor: Option<bool> = "vendor",
41+
full_bootstrap: Option<bool> = "full-bootstrap",
42+
bootstrap_cache_path: Option<PathBuf> = "bootstrap-cache-path",
43+
extended: Option<bool> = "extended",
44+
tools: Option<HashSet<String>> = "tools",
45+
verbose: Option<usize> = "verbose",
46+
sanitizers: Option<bool> = "sanitizers",
47+
profiler: Option<bool> = "profiler",
48+
cargo_native_static: Option<bool> = "cargo-native-static",
49+
low_priority: Option<bool> = "low-priority",
50+
configure_args: Option<Vec<String>> = "configure-args",
51+
local_rebuild: Option<bool> = "local-rebuild",
52+
print_step_timings: Option<bool> = "print-step-timings",
53+
print_step_rusage: Option<bool> = "print-step-rusage",
54+
check_stage: Option<u32> = "check-stage",
55+
doc_stage: Option<u32> = "doc-stage",
56+
build_stage: Option<u32> = "build-stage",
57+
test_stage: Option<u32> = "test-stage",
58+
install_stage: Option<u32> = "install-stage",
59+
dist_stage: Option<u32> = "dist-stage",
60+
bench_stage: Option<u32> = "bench-stage",
61+
patch_binaries_for_nix: Option<bool> = "patch-binaries-for-nix",
62+
// NOTE: only parsed by bootstrap.py, `--feature build-metrics` enables metrics unconditionally
63+
metrics: Option<bool> = "metrics",
64+
android_ndk: Option<PathBuf> = "android-ndk",
65+
optimized_compiler_builtins: Option<bool> = "optimized-compiler-builtins",
66+
jobs: Option<u32> = "jobs",
67+
compiletest_diff_tool: Option<String> = "compiletest-diff-tool",
68+
compiletest_use_stage0_libtest: Option<bool> = "compiletest-use-stage0-libtest",
69+
ccache: Option<StringOrBool> = "ccache",
70+
exclude: Option<Vec<PathBuf>> = "exclude",
71+
}
72+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use serde::{Deserialize, Deserializer};
2+
use serde_derive::Deserialize;
3+
4+
/// This enum is used for deserializing change IDs from TOML, allowing both numeric values and the string `"ignore"`.
5+
#[derive(Clone, Debug, PartialEq)]
6+
pub enum ChangeId {
7+
Ignore,
8+
Id(usize),
9+
}
10+
11+
/// Since we use `#[serde(deny_unknown_fields)]` on `TomlConfig`, we need a wrapper type
12+
/// for the "change-id" field to parse it even if other fields are invalid. This ensures
13+
/// that if deserialization fails due to other fields, we can still provide the changelogs
14+
/// to allow developers to potentially find the reason for the failure in the logs..
15+
#[derive(Deserialize, Default)]
16+
pub(crate) struct ChangeIdWrapper {
17+
#[serde(alias = "change-id", default, deserialize_with = "deserialize_change_id")]
18+
pub(crate) inner: Option<ChangeId>,
19+
}
20+
21+
fn deserialize_change_id<'de, D: Deserializer<'de>>(
22+
deserializer: D,
23+
) -> Result<Option<ChangeId>, D::Error> {
24+
let value = toml::Value::deserialize(deserializer)?;
25+
Ok(match value {
26+
toml::Value::String(s) if s == "ignore" => Some(ChangeId::Ignore),
27+
toml::Value::Integer(i) => Some(ChangeId::Id(i as usize)),
28+
_ => {
29+
return Err(serde::de::Error::custom(
30+
"expected \"ignore\" or an integer for change-id",
31+
));
32+
}
33+
})
34+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
8+
use serde::{Deserialize, Deserializer};
9+
10+
use crate::core::config::toml::ReplaceOpt;
11+
use crate::core::config::{Merge, set};
12+
use crate::{Config, HashSet, PathBuf, define_config, exit};
13+
14+
define_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+
26+
impl 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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//! This module defines the `Gcc` struct, which represents the `[gcc]` table
2+
//! in the `bootstrap.toml` configuration file.
3+
//!
4+
//! The `[gcc]` table contains options specifically related to building or
5+
//! acquiring the GCC compiler for use within the Rust build process.
6+
7+
use serde::{Deserialize, Deserializer};
8+
9+
use crate::core::config::toml::ReplaceOpt;
10+
use crate::core::config::{GccCiMode, Merge};
11+
use crate::{Config, HashSet, PathBuf, define_config, exit};
12+
13+
define_config! {
14+
/// TOML representation of how the GCC build is configured.
15+
struct Gcc {
16+
download_ci_gcc: Option<bool> = "download-ci-gcc",
17+
}
18+
}
19+
20+
impl Config {
21+
/// Applies GCC-related configuration from the `TomlGcc` struct to the
22+
/// global `Config` structure.
23+
pub fn apply_gcc_config(&mut self, toml_gcc: Option<Gcc>) {
24+
if let Some(gcc) = toml_gcc {
25+
self.gcc_ci_mode = match gcc.download_ci_gcc {
26+
Some(value) => match value {
27+
true => GccCiMode::DownloadFromCi,
28+
false => GccCiMode::BuildLocally,
29+
},
30+
None => GccCiMode::default(),
31+
};
32+
}
33+
}
34+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
9+
use serde::{Deserialize, Deserializer};
10+
11+
use crate::core::config::toml::ReplaceOpt;
12+
use crate::core::config::{Merge, set};
13+
use crate::{Config, HashSet, PathBuf, define_config, exit};
14+
15+
define_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+
28+
impl 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+
}

0 commit comments

Comments
 (0)