Skip to content

Commit f1d5216

Browse files
committed
xtask/kimchi-bindings-stubs: use match statement instead of if-else
1 parent e8b5b32 commit f1d5216

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

xtask/src/main.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,26 @@ fn build_kimchi_stubs(target_dir: Option<&str>, offline: bool) -> Result<()> {
9696

9797
// If optimisations are enabled and the CPU supports ADX and BMI2, we enable
9898
// those features.
99-
let rustflags = if optimisations_enabled && cpu_supports_adx_bmi2 {
100-
Some("-C target-feature=+bmi2,+adx".to_string())
101-
} else if !optimisations_enabled && cpu_supports_adx_bmi2 {
102-
// If optimisations are disabled but the CPU supports ADX and BMI2,
103-
// we explicitly disable them.
104-
Some("-C target-feature=-bmi2,-adx".to_string())
105-
} else if !cpu_supports_adx_bmi2 {
106-
// If the CPU does not support ADX and BMI2, we do not set any
107-
// target features. It could be handled in the `else` branch, but we
108-
// want to be explicit. If the CPU does not support these features, but
109-
// we still add the -bmi2 and -adx flags, it will cause a build warning
110-
// we want to avoid on the user console.
111-
None
112-
} else {
113-
None
99+
let rustflags = match (optimisations_enabled, cpu_supports_adx_bmi2) {
100+
(true, true) => {
101+
// If optimisations are enabled and the CPU supports ADX and BMI2,
102+
// we enable them.
103+
Some("-C target-feature=+bmi2,+adx".to_string())
104+
}
105+
(false, true) => {
106+
// If optimisations are disabled but the CPU supports ADX and BMI2,
107+
// we explicitly disable them.
108+
Some("-C target-feature=-bmi2,-adx".to_string())
109+
}
110+
(true, false) => {
111+
// If the CPU does not support ADX and BMI2, we do not set any
112+
// target features. It could be handled in the `else` branch, but we
113+
// want to be explicit. If the CPU does not support these features, but
114+
// we still add the -bmi2 and -adx flags, it will cause a build warning
115+
// we want to avoid on the user console.
116+
None
117+
}
118+
(false, false) => None,
114119
};
115120

116121
let target_dir = target_dir.unwrap_or("target/kimchi_stubs_build");

0 commit comments

Comments
 (0)