bootstrap/core/config/toml/
llvm.rs1use serde::{Deserialize, Deserializer};
5
6use crate::core::config::StringOrBool;
7use crate::core::config::toml::{Merge, ReplaceOpt, TomlConfig};
8use crate::{HashMap, HashSet, PathBuf, define_config, exit};
9
10define_config! {
11 #[derive(Default)]
13 struct Llvm {
14 optimize: Option<bool> = "optimize",
15 thin_lto: Option<bool> = "thin-lto",
16 release_debuginfo: Option<bool> = "release-debuginfo",
17 assertions: Option<bool> = "assertions",
18 tests: Option<bool> = "tests",
19 enzyme: Option<bool> = "enzyme",
20 plugins: Option<bool> = "plugins",
21 static_libstdcpp: Option<bool> = "static-libstdcpp",
22 libzstd: Option<bool> = "libzstd",
23 ninja: Option<bool> = "ninja",
24 targets: Option<String> = "targets",
25 experimental_targets: Option<String> = "experimental-targets",
26 link_jobs: Option<u32> = "link-jobs",
27 link_shared: Option<bool> = "link-shared",
28 version_suffix: Option<String> = "version-suffix",
29 clang_cl: Option<String> = "clang-cl",
30 cflags: Option<String> = "cflags",
31 cxxflags: Option<String> = "cxxflags",
32 ldflags: Option<String> = "ldflags",
33 use_libcxx: Option<bool> = "use-libcxx",
34 use_linker: Option<String> = "use-linker",
35 allow_old_toolchain: Option<bool> = "allow-old-toolchain",
36 offload: Option<bool> = "offload",
37 polly: Option<bool> = "polly",
38 clang: Option<bool> = "clang",
39 enable_warnings: Option<bool> = "enable-warnings",
40 download_ci_llvm: Option<StringOrBool> = "download-ci-llvm",
41 build_config: Option<HashMap<String, String>> = "build-config",
42 }
43}
44
45#[cfg(not(test))]
48pub fn check_incompatible_options_for_ci_llvm(
49 current_config_toml: TomlConfig,
50 ci_config_toml: TomlConfig,
51) -> Result<(), String> {
52 macro_rules! err {
53 ($current:expr, $expected:expr) => {
54 if let Some(current) = &$current {
55 if Some(current) != $expected.as_ref() {
56 return Err(format!(
57 "ERROR: Setting `llvm.{}` is incompatible with `llvm.download-ci-llvm`. \
58 Current value: {:?}, Expected value(s): {}{:?}",
59 stringify!($expected).replace("_", "-"),
60 $current,
61 if $expected.is_some() { "None/" } else { "" },
62 $expected,
63 ));
64 };
65 };
66 };
67 }
68
69 macro_rules! warn {
70 ($current:expr, $expected:expr) => {
71 if let Some(current) = &$current {
72 if Some(current) != $expected.as_ref() {
73 println!(
74 "WARNING: `llvm.{}` has no effect with `llvm.download-ci-llvm`. \
75 Current value: {:?}, Expected value(s): {}{:?}",
76 stringify!($expected).replace("_", "-"),
77 $current,
78 if $expected.is_some() { "None/" } else { "" },
79 $expected,
80 );
81 };
82 };
83 };
84 }
85
86 let (Some(current_llvm_config), Some(ci_llvm_config)) =
87 (current_config_toml.llvm, ci_config_toml.llvm)
88 else {
89 return Ok(());
90 };
91
92 let Llvm {
93 optimize,
94 thin_lto,
95 release_debuginfo,
96 assertions: _,
97 tests: _,
98 plugins,
99 static_libstdcpp: _,
100 libzstd,
101 ninja: _,
102 targets,
103 experimental_targets,
104 link_jobs: _,
105 link_shared: _,
106 version_suffix,
107 clang_cl,
108 cflags,
109 cxxflags,
110 ldflags,
111 use_libcxx,
112 use_linker,
113 allow_old_toolchain,
114 offload,
115 polly,
116 clang,
117 enable_warnings,
118 download_ci_llvm: _,
119 build_config,
120 enzyme,
121 } = ci_llvm_config;
122
123 err!(current_llvm_config.optimize, optimize);
124 err!(current_llvm_config.thin_lto, thin_lto);
125 err!(current_llvm_config.release_debuginfo, release_debuginfo);
126 err!(current_llvm_config.libzstd, libzstd);
127 err!(current_llvm_config.targets, targets);
128 err!(current_llvm_config.experimental_targets, experimental_targets);
129 err!(current_llvm_config.clang_cl, clang_cl);
130 err!(current_llvm_config.version_suffix, version_suffix);
131 err!(current_llvm_config.cflags, cflags);
132 err!(current_llvm_config.cxxflags, cxxflags);
133 err!(current_llvm_config.ldflags, ldflags);
134 err!(current_llvm_config.use_libcxx, use_libcxx);
135 err!(current_llvm_config.use_linker, use_linker);
136 err!(current_llvm_config.allow_old_toolchain, allow_old_toolchain);
137 err!(current_llvm_config.offload, offload);
138 err!(current_llvm_config.polly, polly);
139 err!(current_llvm_config.clang, clang);
140 err!(current_llvm_config.build_config, build_config);
141 err!(current_llvm_config.plugins, plugins);
142 err!(current_llvm_config.enzyme, enzyme);
143
144 warn!(current_llvm_config.enable_warnings, enable_warnings);
145
146 Ok(())
147}