Avoid the merge derive macro in rustbuild

The task of the macro is simple enough that a decl macro is almost ten
times shorter than the original proc macro. The proc macro is 159 lines
while the decl macro is just 18 lines.

This reduces the amount of dependencies of rustbuild from 45 to 37. It
also slight reduces compilation time from 47s to 44s for debug builds.
This commit is contained in:
bjorn3 2021-12-26 15:05:12 +01:00
parent 2fe2728fa9
commit 043745cb96
3 changed files with 197 additions and 182 deletions

View File

@ -2225,22 +2225,6 @@ name = "merge"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10bbef93abb1da61525bbc45eeaff6473a41907d19f8f9aa5168d214e10693e9"
dependencies = [
"merge_derive",
"num-traits",
]
[[package]]
name = "merge_derive"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "209d075476da2e63b4b29e72a2ef627b840589588e71400a25e3565c4f849d07"
dependencies = [
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "minifier"

View File

@ -47,7 +47,7 @@ toml = "0.5"
time = "0.1"
ignore = "0.4.10"
opener = "0.5"
merge = "0.1.0"
merge = { version = "0.1.0", default-features = false, features = ["std"] }
once_cell = "1.7.2"
[target.'cfg(windows)'.dependencies.winapi]

View File

@ -357,8 +357,28 @@ impl Merge for TomlConfig {
}
}
macro_rules! derive_merge {
($(#[$attr:meta])* struct $name:ident {
$($field:ident: $field_ty:ty,)*
}) => {
$(#[$attr])*
struct $name {
$($field: $field_ty,)*
}
impl Merge for $name {
fn merge(&mut self, other: Self) {
$(
Merge::merge(&mut self.$field, other.$field);
)*
}
}
}
}
derive_merge! {
/// TOML representation of various global build decisions.
#[derive(Deserialize, Default, Clone, Merge)]
#[derive(Deserialize, Default, Clone)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Build {
build: Option<String>,
@ -401,9 +421,11 @@ struct Build {
bench_stage: Option<u32>,
patch_binaries_for_nix: Option<bool>,
}
}
derive_merge! {
/// TOML representation of various global install decisions.
#[derive(Deserialize, Default, Clone, Merge)]
#[derive(Deserialize, Default, Clone)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Install {
prefix: Option<String>,
@ -414,9 +436,11 @@ struct Install {
mandir: Option<String>,
datadir: Option<String>,
}
}
derive_merge! {
/// TOML representation of how the LLVM build is configured.
#[derive(Deserialize, Default, Merge)]
#[derive(Deserialize, Default)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Llvm {
skip_rebuild: Option<bool>,
@ -446,8 +470,10 @@ struct Llvm {
clang: Option<bool>,
download_ci_llvm: Option<StringOrBool>,
}
}
#[derive(Deserialize, Default, Clone, Merge)]
derive_merge! {
#[derive(Deserialize, Default, Clone)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Dist {
sign_folder: Option<String>,
@ -457,6 +483,7 @@ struct Dist {
missing_tools: Option<bool>,
compression_formats: Option<Vec<String>>,
}
}
#[derive(Deserialize)]
#[serde(untagged)]
@ -471,8 +498,9 @@ impl Default for StringOrBool {
}
}
derive_merge! {
/// TOML representation of how the Rust build is configured.
#[derive(Deserialize, Default, Merge)]
#[derive(Deserialize, Default)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct Rust {
optimize: Option<bool>,
@ -523,9 +551,11 @@ struct Rust {
// ignored; this is set from an env var set by bootstrap.py
download_rustc: Option<StringOrBool>,
}
}
derive_merge! {
/// TOML representation of how each build target is configured.
#[derive(Deserialize, Default, Merge)]
#[derive(Deserialize, Default)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
struct TomlTarget {
cc: Option<String>,
@ -546,6 +576,7 @@ struct TomlTarget {
qemu_rootfs: Option<String>,
no_std: Option<bool>,
}
}
impl Config {
fn path_from_python(var_key: &str) -> PathBuf {