Skip to content

Commit a77d364

Browse files
committed
wip
1 parent 63eba0f commit a77d364

File tree

4 files changed

+289
-240
lines changed

4 files changed

+289
-240
lines changed

config.toml.example

+3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ changelog-seen = 2
6565
# Indicates whether an LLVM Release build should include debug info
6666
#release-debuginfo = false
6767

68+
# Indicates whether we should build the LLVM Plugin Enzyme
69+
enzyme = true
70+
6871
# Indicates whether the LLVM assertions are enabled or not
6972
#assertions = false
7073

src/bootstrap/config.rs

+73-67
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! check_ci_llvm {
2525
$name.is_none(),
2626
"setting {} is incompatible with download-ci-llvm.",
2727
stringify!($name)
28-
);
28+
);
2929
};
3030
}
3131

@@ -89,6 +89,7 @@ pub struct Config {
8989
pub llvm_skip_rebuild: bool,
9090
pub llvm_assertions: bool,
9191
pub llvm_tests: bool,
92+
pub llvm_enzyme: bool,
9293
pub llvm_plugins: bool,
9394
pub llvm_optimize: bool,
9495
pub llvm_thin_lto: bool,
@@ -341,7 +342,7 @@ impl Merge for TomlConfig {
341342
fn merge(
342343
&mut self,
343344
TomlConfig { build, install, llvm, rust, dist, target, profile: _, changelog_seen: _ }: Self,
344-
) {
345+
) {
345346
fn do_merge<T: Merge>(x: &mut Option<T>, y: Option<T>) {
346347
if let Some(new) = y {
347348
if let Some(original) = x {
@@ -367,17 +368,17 @@ macro_rules! define_config {
367368
$($field:ident: Option<$field_ty:ty> = $field_key:literal,)*
368369
}) => {
369370
$(#[$attr])*
370-
struct $name {
371-
$($field: Option<$field_ty>,)*
372-
}
371+
struct $name {
372+
$($field: Option<$field_ty>,)*
373+
}
373374

374375
impl Merge for $name {
375376
fn merge(&mut self, other: Self) {
376377
$(
377378
if !self.$field.is_some() {
378379
self.$field = other.$field;
379380
}
380-
)*
381+
)*
381382
}
382383
}
383384

@@ -386,64 +387,64 @@ macro_rules! define_config {
386387
// compile time of rustbuild.
387388
impl<'de> Deserialize<'de> for $name {
388389
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
389-
where
390-
D: Deserializer<'de>,
391-
{
392-
struct Field;
393-
impl<'de> serde::de::Visitor<'de> for Field {
394-
type Value = $name;
395-
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
396-
f.write_str(concat!("struct ", stringify!($name)))
397-
}
390+
where
391+
D: Deserializer<'de>,
392+
{
393+
struct Field;
394+
impl<'de> serde::de::Visitor<'de> for Field {
395+
type Value = $name;
396+
fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
397+
f.write_str(concat!("struct ", stringify!($name)))
398+
}
398399

399-
#[inline]
400-
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
401-
where
402-
A: serde::de::MapAccess<'de>,
403-
{
404-
$(let mut $field: Option<$field_ty> = None;)*
405-
while let Some(key) =
406-
match serde::de::MapAccess::next_key::<String>(&mut map) {
407-
Ok(val) => val,
408-
Err(err) => {
409-
return Err(err);
410-
}
411-
}
412-
{
413-
match &*key {
414-
$($field_key => {
415-
if $field.is_some() {
416-
return Err(<A::Error as serde::de::Error>::duplicate_field(
417-
$field_key,
418-
));
419-
}
420-
$field = match serde::de::MapAccess::next_value::<$field_ty>(
421-
&mut map,
422-
) {
423-
Ok(val) => Some(val),
424-
Err(err) => {
425-
return Err(err);
400+
#[inline]
401+
fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error>
402+
where
403+
A: serde::de::MapAccess<'de>,
404+
{
405+
$(let mut $field: Option<$field_ty> = None;)*
406+
while let Some(key) =
407+
match serde::de::MapAccess::next_key::<String>(&mut map) {
408+
Ok(val) => val,
409+
Err(err) => {
410+
return Err(err);
411+
}
412+
}
413+
{
414+
match &*key {
415+
$($field_key => {
416+
if $field.is_some() {
417+
return Err(<A::Error as serde::de::Error>::duplicate_field(
418+
$field_key,
419+
));
420+
}
421+
$field = match serde::de::MapAccess::next_value::<$field_ty>(
422+
&mut map,
423+
) {
424+
Ok(val) => Some(val),
425+
Err(err) => {
426+
return Err(err);
427+
}
428+
};
429+
})*
430+
key => {
431+
return Err(serde::de::Error::unknown_field(key, FIELDS));
426432
}
427-
};
428-
})*
429-
key => {
430-
return Err(serde::de::Error::unknown_field(key, FIELDS));
433+
}
431434
}
435+
Ok($name { $($field),* })
432436
}
433-
}
434-
Ok($name { $($field),* })
435437
}
438+
const FIELDS: &'static [&'static str] = &[
439+
$($field_key,)*
440+
];
441+
Deserializer::deserialize_struct(
442+
deserializer,
443+
stringify!($name),
444+
FIELDS,
445+
Field,
446+
)
436447
}
437-
const FIELDS: &'static [&'static str] = &[
438-
$($field_key,)*
439-
];
440-
Deserializer::deserialize_struct(
441-
deserializer,
442-
stringify!($name),
443-
FIELDS,
444-
Field,
445-
)
446-
}
447448
}
448449
}
449450
}
@@ -515,6 +516,7 @@ define_config! {
515516
release_debuginfo: Option<bool> = "release-debuginfo",
516517
assertions: Option<bool> = "assertions",
517518
tests: Option<bool> = "tests",
519+
enzyme: Option<bool> = "enzyme",
518520
plugins: Option<bool> = "plugins",
519521
ccache: Option<StringOrBool> = "ccache",
520522
version_check: Option<bool> = "version-check",
@@ -708,13 +710,13 @@ impl Config {
708710
// TomlConfig and sub types to be monomorphized 5x by toml.
709711
match toml::from_str(&contents)
710712
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
711-
{
712-
Ok(table) => table,
713-
Err(err) => {
714-
println!("failed to parse TOML configuration '{}': {}", file.display(), err);
715-
process::exit(2);
713+
{
714+
Ok(table) => table,
715+
Err(err) => {
716+
println!("failed to parse TOML configuration '{}': {}", file.display(), err);
717+
process::exit(2);
718+
}
716719
}
717-
}
718720
};
719721

720722
// Read from `--config`, then `RUST_BOOTSTRAP_CONFIG`, then `./config.toml`, then `config.toml` in the root directory.
@@ -831,6 +833,7 @@ impl Config {
831833
// we'll infer default values for them later
832834
let mut llvm_assertions = None;
833835
let mut llvm_tests = None;
836+
let mut llvm_enzyme = None;
834837
let mut llvm_plugins = None;
835838
let mut debug = None;
836839
let mut debug_assertions = None;
@@ -857,6 +860,7 @@ impl Config {
857860
set(&mut config.ninja_in_file, llvm.ninja);
858861
llvm_assertions = llvm.assertions;
859862
llvm_tests = llvm.tests;
863+
llvm_enzyme = llvm.enzyme;
860864
llvm_plugins = llvm.plugins;
861865
llvm_skip_rebuild = llvm_skip_rebuild.or(llvm.skip_rebuild);
862866
set(&mut config.llvm_optimize, llvm.optimize);
@@ -917,7 +921,7 @@ impl Config {
917921
"x86_64-unknown-illumos",
918922
"x86_64-unknown-linux-musl",
919923
"x86_64-unknown-netbsd",
920-
];
924+
];
921925
supported_platforms.contains(&&*config.build.triple)
922926
}
923927
Some(StringOrBool::Bool(b)) => b,
@@ -950,6 +954,7 @@ impl Config {
950954
check_ci_llvm!(llvm.polly);
951955
check_ci_llvm!(llvm.clang);
952956
check_ci_llvm!(llvm.build_config);
957+
check_ci_llvm!(llvm.enzyme);
953958
check_ci_llvm!(llvm.plugins);
954959

955960
// CI-built LLVM can be either dynamic or static.
@@ -961,7 +966,7 @@ impl Config {
961966
let link_type = t!(
962967
std::fs::read_to_string(ci_llvm.join("link-type.txt")),
963968
format!("CI llvm missing: {}", ci_llvm.display())
964-
);
969+
);
965970
link_type == "dynamic"
966971
};
967972
}
@@ -1111,6 +1116,7 @@ impl Config {
11111116
config.llvm_skip_rebuild = llvm_skip_rebuild.unwrap_or(false);
11121117
config.llvm_assertions = llvm_assertions.unwrap_or(false);
11131118
config.llvm_tests = llvm_tests.unwrap_or(false);
1119+
config.llvm_enzyme = llvm_enzyme.unwrap_or(false);
11141120
config.llvm_plugins = llvm_plugins.unwrap_or(false);
11151121
config.rust_optimize = optimize.unwrap_or(true);
11161122

@@ -1180,7 +1186,7 @@ impl Config {
11801186
config.stage, 2,
11811187
"x.py should be run with `--stage 2` on CI, but was run with `--stage {}`",
11821188
config.stage,
1183-
);
1189+
);
11841190
}
11851191
Subcommand::Clean { .. }
11861192
| Subcommand::Check { .. }

0 commit comments

Comments
 (0)