mirror of
https://github.com/openharmony/third_party_rust_regex.git
synced 2026-07-01 21:33:59 -04:00
build: refactor build.rs slightly
Hopefully the next MSRV bump will bring us beyond (or at) 1.27 and we will no longer need this.
This commit is contained in:
@@ -3,36 +3,29 @@ use std::ffi::OsString;
|
||||
use std::process::Command;
|
||||
|
||||
fn main() {
|
||||
let rustc = env::var_os("RUSTC").unwrap_or(OsString::from("rustc"));
|
||||
let output = Command::new(&rustc)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.unwrap()
|
||||
.stdout;
|
||||
let version = String::from_utf8(output).unwrap();
|
||||
|
||||
enable_simd_optimizations(&version);
|
||||
let version = match Version::read() {
|
||||
Ok(version) => version,
|
||||
Err(err) => {
|
||||
eprintln!("failed to parse `rustc --version`: {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
enable_simd_optimizations(version);
|
||||
}
|
||||
|
||||
fn enable_simd_optimizations(version: &str) {
|
||||
fn enable_simd_optimizations(version: Version) {
|
||||
// We don't activate SIMD optimizations these if we've explicitly disabled
|
||||
// them. Disabling auto optimizations is intended for use in tests, so that
|
||||
// we can reliably test fallback implementations.
|
||||
if env::var_os("CARGO_CFG_REGEX_DISABLE_AUTO_OPTIMIZATIONS").is_some() {
|
||||
return;
|
||||
}
|
||||
let parsed = match Version::parse(&version) {
|
||||
Ok(parsed) => parsed,
|
||||
Err(err) => {
|
||||
eprintln!("failed to parse `rustc --version`: {}", err);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let minimum = Version { major: 1, minor: 27, patch: 0 };
|
||||
if version.contains("nightly") || parsed >= minimum {
|
||||
println!("cargo:rustc-cfg=regex_runtime_teddy_ssse3");
|
||||
println!("cargo:rustc-cfg=regex_runtime_teddy_avx2");
|
||||
if version < (Version { major: 1, minor: 27, patch: 0 }) {
|
||||
return;
|
||||
}
|
||||
|
||||
println!("cargo:rustc-cfg=regex_runtime_teddy_ssse3");
|
||||
println!("cargo:rustc-cfg=regex_runtime_teddy_avx2");
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq, PartialOrd, Ord)]
|
||||
@@ -43,6 +36,16 @@ struct Version {
|
||||
}
|
||||
|
||||
impl Version {
|
||||
fn read() -> Result<Version, String> {
|
||||
let rustc = env::var_os("RUSTC").unwrap_or(OsString::from("rustc"));
|
||||
let output = Command::new(&rustc)
|
||||
.arg("--version")
|
||||
.output()
|
||||
.unwrap()
|
||||
.stdout;
|
||||
Version::parse(&String::from_utf8(output).unwrap())
|
||||
}
|
||||
|
||||
fn parse(mut s: &str) -> Result<Version, String> {
|
||||
if !s.starts_with("rustc ") {
|
||||
return Err(format!("unrecognized version string: {}", s));
|
||||
|
||||
Reference in New Issue
Block a user