// We are using a decl macro instead of a derive proc macro here to reduce the compile time of
// rustbuild.
-macro_rules! derive_merge {
+macro_rules! define_config {
($(#[$attr:meta])* struct $name:ident {
$($field:ident: $field_ty:ty,)*
}) => {
$(#[$attr])*
+ #[derive(Deserialize)]
+ #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct $name {
$($field: $field_ty,)*
}
}
}
-derive_merge! {
+define_config! {
/// TOML representation of various global build decisions.
- #[derive(Deserialize, Default)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
+ #[derive(Default)]
struct Build {
build: Option<String>,
host: Option<Vec<String>>,
}
}
-derive_merge! {
+define_config! {
/// TOML representation of various global install decisions.
- #[derive(Deserialize)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Install {
prefix: Option<String>,
sysconfdir: Option<String>,
}
}
-derive_merge! {
+define_config! {
/// TOML representation of how the LLVM build is configured.
- #[derive(Deserialize)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Llvm {
skip_rebuild: Option<bool>,
optimize: Option<bool>,
}
}
-derive_merge! {
- #[derive(Deserialize)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
+define_config! {
struct Dist {
sign_folder: Option<String>,
gpg_password_file: Option<String>,
}
}
-derive_merge! {
+define_config! {
/// TOML representation of how the Rust build is configured.
- #[derive(Deserialize)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Rust {
optimize: Option<bool>,
debug: Option<bool>,
}
}
-derive_merge! {
+define_config! {
/// TOML representation of how each build target is configured.
- #[derive(Deserialize)]
- #[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct TomlTarget {
cc: Option<String>,
cxx: Option<String>,
let get_toml = |file: &Path| {
use std::process;
- let contents = t!(fs::read_to_string(file), "`include` config not found");
+ let contents =
+ t!(fs::read_to_string(file), format!("config file {} not found", file.display()));
match toml::from_str(&contents) {
Ok(table) => table,
Err(err) => {
}
};
- // check --config first, then `$RUST_BOOTSTRAP_CONFIG` first, then `config.toml`
+ // Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory.
let toml_path = flags
.config
.clone()
- .or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from))
- .unwrap_or_else(|| PathBuf::from("config.toml"));
- let mut toml =
- if toml_path.exists() { get_toml(&toml_path) } else { TomlConfig::default() };
+ .or_else(|| env::var_os("RUST_BOOTSTRAP_CONFIG").map(PathBuf::from));
+ let using_default_path = toml_path.is_none();
+ let mut toml_path = toml_path.unwrap_or_else(|| PathBuf::from("config.toml"));
+ if using_default_path && !toml_path.exists() {
+ toml_path = config.src.join(toml_path);
+ }
+
+ // Give a hard error if `--config` or `RUST_BOOTSTRAP_CONFIG` are set to a missing path,
+ // but not if `config.toml` hasn't been created.
+ let mut toml = if !using_default_path || toml_path.exists() {
+ get_toml(&toml_path)
+ } else {
+ TomlConfig::default()
+ };
if let Some(include) = &toml.profile {
let mut include_path = config.src.clone();