diff --git a/Cargo.lock b/Cargo.lock index b71488837041..dd4d48c126fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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" diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 9ad453497f69..1f218dd8d67b 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -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] diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 7a4593a75f28..fcca783fbfe3 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -357,105 +357,132 @@ impl Merge for TomlConfig { } } -/// TOML representation of various global build decisions. -#[derive(Deserialize, Default, Clone, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct Build { - build: Option, - host: Option>, - target: Option>, - // This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable - build_dir: Option, - cargo: Option, - rustc: Option, - rustfmt: Option, - docs: Option, - compiler_docs: Option, - docs_minification: Option, - submodules: Option, - fast_submodules: Option, - gdb: Option, - nodejs: Option, - npm: Option, - python: Option, - locked_deps: Option, - vendor: Option, - full_bootstrap: Option, - extended: Option, - tools: Option>, - verbose: Option, - sanitizers: Option, - profiler: Option, - cargo_native_static: Option, - low_priority: Option, - configure_args: Option>, - local_rebuild: Option, - print_step_timings: Option, - print_step_rusage: Option, - check_stage: Option, - doc_stage: Option, - build_stage: Option, - test_stage: Option, - install_stage: Option, - dist_stage: Option, - bench_stage: Option, - patch_binaries_for_nix: Option, +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); + )* + } + } + } } -/// TOML representation of various global install decisions. -#[derive(Deserialize, Default, Clone, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct Install { - prefix: Option, - sysconfdir: Option, - docdir: Option, - bindir: Option, - libdir: Option, - mandir: Option, - datadir: Option, +derive_merge! { + /// TOML representation of various global build decisions. + #[derive(Deserialize, Default, Clone)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct Build { + build: Option, + host: Option>, + target: Option>, + // This is ignored, the rust code always gets the build directory from the `BUILD_DIR` env variable + build_dir: Option, + cargo: Option, + rustc: Option, + rustfmt: Option, + docs: Option, + compiler_docs: Option, + docs_minification: Option, + submodules: Option, + fast_submodules: Option, + gdb: Option, + nodejs: Option, + npm: Option, + python: Option, + locked_deps: Option, + vendor: Option, + full_bootstrap: Option, + extended: Option, + tools: Option>, + verbose: Option, + sanitizers: Option, + profiler: Option, + cargo_native_static: Option, + low_priority: Option, + configure_args: Option>, + local_rebuild: Option, + print_step_timings: Option, + print_step_rusage: Option, + check_stage: Option, + doc_stage: Option, + build_stage: Option, + test_stage: Option, + install_stage: Option, + dist_stage: Option, + bench_stage: Option, + patch_binaries_for_nix: Option, + } } -/// TOML representation of how the LLVM build is configured. -#[derive(Deserialize, Default, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct Llvm { - skip_rebuild: Option, - optimize: Option, - thin_lto: Option, - release_debuginfo: Option, - assertions: Option, - tests: Option, - plugins: Option, - ccache: Option, - version_check: Option, - static_libstdcpp: Option, - ninja: Option, - targets: Option, - experimental_targets: Option, - link_jobs: Option, - link_shared: Option, - version_suffix: Option, - clang_cl: Option, - cflags: Option, - cxxflags: Option, - ldflags: Option, - use_libcxx: Option, - use_linker: Option, - allow_old_toolchain: Option, - polly: Option, - clang: Option, - download_ci_llvm: Option, +derive_merge! { + /// TOML representation of various global install decisions. + #[derive(Deserialize, Default, Clone)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct Install { + prefix: Option, + sysconfdir: Option, + docdir: Option, + bindir: Option, + libdir: Option, + mandir: Option, + datadir: Option, + } } -#[derive(Deserialize, Default, Clone, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct Dist { - sign_folder: Option, - gpg_password_file: Option, - upload_addr: Option, - src_tarball: Option, - missing_tools: Option, - compression_formats: Option>, +derive_merge! { + /// TOML representation of how the LLVM build is configured. + #[derive(Deserialize, Default)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct Llvm { + skip_rebuild: Option, + optimize: Option, + thin_lto: Option, + release_debuginfo: Option, + assertions: Option, + tests: Option, + plugins: Option, + ccache: Option, + version_check: Option, + static_libstdcpp: Option, + ninja: Option, + targets: Option, + experimental_targets: Option, + link_jobs: Option, + link_shared: Option, + version_suffix: Option, + clang_cl: Option, + cflags: Option, + cxxflags: Option, + ldflags: Option, + use_libcxx: Option, + use_linker: Option, + allow_old_toolchain: Option, + polly: Option, + clang: Option, + download_ci_llvm: Option, + } +} + +derive_merge! { + #[derive(Deserialize, Default, Clone)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct Dist { + sign_folder: Option, + gpg_password_file: Option, + upload_addr: Option, + src_tarball: Option, + missing_tools: Option, + compression_formats: Option>, + } } #[derive(Deserialize)] @@ -471,80 +498,84 @@ impl Default for StringOrBool { } } -/// TOML representation of how the Rust build is configured. -#[derive(Deserialize, Default, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct Rust { - optimize: Option, - debug: Option, - codegen_units: Option, - codegen_units_std: Option, - debug_assertions: Option, - debug_assertions_std: Option, - overflow_checks: Option, - overflow_checks_std: Option, - debug_logging: Option, - debuginfo_level: Option, - debuginfo_level_rustc: Option, - debuginfo_level_std: Option, - debuginfo_level_tools: Option, - debuginfo_level_tests: Option, - run_dsymutil: Option, - backtrace: Option, - incremental: Option, - parallel_compiler: Option, - default_linker: Option, - channel: Option, - description: Option, - musl_root: Option, - rpath: Option, - verbose_tests: Option, - optimize_tests: Option, - codegen_tests: Option, - ignore_git: Option, - dist_src: Option, - save_toolstates: Option, - codegen_backends: Option>, - lld: Option, - use_lld: Option, - llvm_tools: Option, - deny_warnings: Option, - backtrace_on_ice: Option, - verify_llvm_ir: Option, - thin_lto_import_instr_limit: Option, - remap_debuginfo: Option, - jemalloc: Option, - test_compare_mode: Option, - llvm_libunwind: Option, - control_flow_guard: Option, - new_symbol_mangling: Option, - profile_generate: Option, - profile_use: Option, - // ignored; this is set from an env var set by bootstrap.py - download_rustc: Option, +derive_merge! { + /// TOML representation of how the Rust build is configured. + #[derive(Deserialize, Default)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct Rust { + optimize: Option, + debug: Option, + codegen_units: Option, + codegen_units_std: Option, + debug_assertions: Option, + debug_assertions_std: Option, + overflow_checks: Option, + overflow_checks_std: Option, + debug_logging: Option, + debuginfo_level: Option, + debuginfo_level_rustc: Option, + debuginfo_level_std: Option, + debuginfo_level_tools: Option, + debuginfo_level_tests: Option, + run_dsymutil: Option, + backtrace: Option, + incremental: Option, + parallel_compiler: Option, + default_linker: Option, + channel: Option, + description: Option, + musl_root: Option, + rpath: Option, + verbose_tests: Option, + optimize_tests: Option, + codegen_tests: Option, + ignore_git: Option, + dist_src: Option, + save_toolstates: Option, + codegen_backends: Option>, + lld: Option, + use_lld: Option, + llvm_tools: Option, + deny_warnings: Option, + backtrace_on_ice: Option, + verify_llvm_ir: Option, + thin_lto_import_instr_limit: Option, + remap_debuginfo: Option, + jemalloc: Option, + test_compare_mode: Option, + llvm_libunwind: Option, + control_flow_guard: Option, + new_symbol_mangling: Option, + profile_generate: Option, + profile_use: Option, + // ignored; this is set from an env var set by bootstrap.py + download_rustc: Option, + } } -/// TOML representation of how each build target is configured. -#[derive(Deserialize, Default, Merge)] -#[serde(deny_unknown_fields, rename_all = "kebab-case")] -struct TomlTarget { - cc: Option, - cxx: Option, - ar: Option, - ranlib: Option, - default_linker: Option, - linker: Option, - llvm_config: Option, - llvm_filecheck: Option, - android_ndk: Option, - sanitizers: Option, - profiler: Option, - crt_static: Option, - musl_root: Option, - musl_libdir: Option, - wasi_root: Option, - qemu_rootfs: Option, - no_std: Option, +derive_merge! { + /// TOML representation of how each build target is configured. + #[derive(Deserialize, Default)] + #[serde(deny_unknown_fields, rename_all = "kebab-case")] + struct TomlTarget { + cc: Option, + cxx: Option, + ar: Option, + ranlib: Option, + default_linker: Option, + linker: Option, + llvm_config: Option, + llvm_filecheck: Option, + android_ndk: Option, + sanitizers: Option, + profiler: Option, + crt_static: Option, + musl_root: Option, + musl_libdir: Option, + wasi_root: Option, + qemu_rootfs: Option, + no_std: Option, + } } impl Config {