Simplify checking of crt_static_feature()

This commit is contained in:
12101111 2020-03-08 14:24:02 +08:00
parent 84349cc564
commit dbed65afae

View File

@ -556,33 +556,17 @@ pub fn crt_static_feature(&self, crate_type: Option<config::CrateType>) -> bool
let found_negative = requested_features.clone().any(|r| r == "-crt-static"); let found_negative = requested_features.clone().any(|r| r == "-crt-static");
let found_positive = requested_features.clone().any(|r| r == "+crt-static"); let found_positive = requested_features.clone().any(|r| r == "+crt-static");
if self.target.target.options.crt_static_default { if found_positive || found_negative {
// `proc-macro` always required to be compiled to dylibs. found_positive
// We don't use a static crt unless the `+crt-static` feature was passed. } else if crate_type == Some(config::CrateType::ProcMacro)
if !self.target.target.options.crt_static_allows_dylibs { || self.opts.crate_types.contains(&config::CrateType::ProcMacro)
match crate_type { {
Some(config::CrateType::ProcMacro) => found_positive,
Some(_) => !found_negative,
None => {
// FIXME: When crate_type is not available, // FIXME: When crate_type is not available,
// we use compiler options to determine the crate_type. // we use compiler options to determine the crate_type.
// We can't check `#![crate_type = "proc-macro"]` here. // We can't check `#![crate_type = "proc-macro"]` here.
if self.opts.crate_types.contains(&config::CrateType::ProcMacro) { false
found_positive
} else { } else {
!found_negative self.target.target.options.crt_static_default
}
}
}
} else {
// If the target we're compiling for requests a static crt by default,
// then see if the `-crt-static` feature was passed to disable that.
!found_negative
}
} else {
// If the target we're compiling for don't have a static crt by default then see if the
// `+crt-static` feature was passed.
found_positive
} }
} }