gecko-dev/third_party/rust/httparse/build.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

156 строки
4.4 KiB
Rust
Исходник Обычный вид История

Bug 1550903 - Part 2: Revendor dependencies. r=emilio,kats,froydnj It was unhappy about the new LICENSE (fuchsia-cprng) but it's the same as the other fuschia crates. Since I don't think this is used at build time but has the same license as the other fuschia crates, I put it in the RUNTIME_LICENSE_PACKAGE_WHITELIST list. I also removed sha1 from that list as it's not used anymore Differential Revision: https://phabricator.services.mozilla.com/D30746 --HG-- rename : third_party/rust/httparse/Cargo.toml => third_party/rust/autocfg/Cargo.toml rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/autocfg/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/autocfg/LICENSE-MIT rename : third_party/rust/httparse/Cargo.toml => third_party/rust/cloudabi/Cargo.toml rename : third_party/rust/httparse/Cargo.toml => third_party/rust/fuchsia-cprng/Cargo.toml rename : third_party/rust/sha1/LICENSE => third_party/rust/fuchsia-cprng/LICENSE rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/mio-extras/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/mio-extras/LICENSE-MIT rename : third_party/rust/rand/.cargo-checksum.json => third_party/rust/rand-0.4.3/.cargo-checksum.json rename : third_party/rust/rand/CHANGELOG.md => third_party/rust/rand-0.4.3/CHANGELOG.md rename : third_party/rust/rand/Cargo.toml => third_party/rust/rand-0.4.3/Cargo.toml rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand-0.4.3/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand-0.4.3/LICENSE-MIT rename : third_party/rust/rand/README.md => third_party/rust/rand-0.4.3/README.md rename : third_party/rust/rand/appveyor.yml => third_party/rust/rand-0.4.3/appveyor.yml rename : third_party/rust/rand/benches/bench.rs => third_party/rust/rand-0.4.3/benches/bench.rs rename : third_party/rust/rand/benches/distributions/exponential.rs => third_party/rust/rand-0.4.3/benches/distributions/exponential.rs rename : third_party/rust/rand/benches/distributions/gamma.rs => third_party/rust/rand-0.4.3/benches/distributions/gamma.rs rename : third_party/rust/rand/benches/distributions/mod.rs => third_party/rust/rand-0.4.3/benches/distributions/mod.rs rename : third_party/rust/rand/benches/distributions/normal.rs => third_party/rust/rand-0.4.3/benches/distributions/normal.rs rename : third_party/rust/rand/benches/generators.rs => third_party/rust/rand-0.4.3/benches/generators.rs rename : third_party/rust/rand/benches/misc.rs => third_party/rust/rand-0.4.3/benches/misc.rs rename : third_party/rust/rand/src/distributions/exponential.rs => third_party/rust/rand-0.4.3/src/distributions/exponential.rs rename : third_party/rust/rand/src/distributions/gamma.rs => third_party/rust/rand-0.4.3/src/distributions/gamma.rs rename : third_party/rust/rand/src/distributions/mod.rs => third_party/rust/rand-0.4.3/src/distributions/mod.rs rename : third_party/rust/rand/src/distributions/normal.rs => third_party/rust/rand-0.4.3/src/distributions/normal.rs rename : third_party/rust/rand/src/distributions/range.rs => third_party/rust/rand-0.4.3/src/distributions/range.rs rename : third_party/rust/rand/src/distributions/ziggurat_tables.rs => third_party/rust/rand-0.4.3/src/distributions/ziggurat_tables.rs rename : third_party/rust/rand/src/jitter.rs => third_party/rust/rand-0.4.3/src/jitter.rs rename : third_party/rust/rand/src/lib.rs => third_party/rust/rand-0.4.3/src/lib.rs rename : third_party/rust/rand/src/os.rs => third_party/rust/rand-0.4.3/src/os.rs rename : third_party/rust/rand/src/prng/chacha.rs => third_party/rust/rand-0.4.3/src/prng/chacha.rs rename : third_party/rust/rand/src/prng/isaac.rs => third_party/rust/rand-0.4.3/src/prng/isaac.rs rename : third_party/rust/rand/src/prng/isaac64.rs => third_party/rust/rand-0.4.3/src/prng/isaac64.rs rename : third_party/rust/rand/src/prng/mod.rs => third_party/rust/rand-0.4.3/src/prng/mod.rs rename : third_party/rust/rand/src/prng/xorshift.rs => third_party/rust/rand-0.4.3/src/prng/xorshift.rs rename : third_party/rust/rand/src/rand_impls.rs => third_party/rust/rand-0.4.3/src/rand_impls.rs rename : third_party/rust/rand/src/read.rs => third_party/rust/rand-0.4.3/src/read.rs rename : third_party/rust/rand/src/reseeding.rs => third_party/rust/rand-0.4.3/src/reseeding.rs rename : third_party/rust/rand/src/seq.rs => third_party/rust/rand-0.4.3/src/seq.rs rename : third_party/rust/rand/utils/ziggurat_tables.py => third_party/rust/rand-0.4.3/utils/ziggurat_tables.py rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_chacha/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_chacha/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_core-0.3.1/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_core-0.3.1/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_core/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_core/LICENSE-MIT rename : third_party/rust/httparse/Cargo.toml => third_party/rust/rand_hc/Cargo.toml rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_hc/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_hc/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_isaac/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_isaac/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_jitter/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_jitter/LICENSE-MIT rename : third_party/rust/rand/src/jitter.rs => third_party/rust/rand_jitter/src/lib.rs rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_os/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_os/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_pcg/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_pcg/LICENSE-MIT rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/rand_xorshift/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/rand_xorshift/LICENSE-MIT rename : third_party/rust/httparse/Cargo.toml => third_party/rust/rdrand/Cargo.toml rename : third_party/rust/rand/LICENSE-APACHE => third_party/rust/sha-1/LICENSE-APACHE rename : third_party/rust/rand/LICENSE-MIT => third_party/rust/sha-1/LICENSE-MIT extra : moz-landing-system : lando
2019-05-18 16:39:31 +03:00
use std::env;
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()
.expect("failed to check 'rustc --version'")
.stdout;
let version = String::from_utf8(output)
.expect("rustc version output should be utf-8");
enable_new_features(&version);
}
fn enable_new_features(raw_version: &str) {
let version = match Version::parse(raw_version) {
Ok(version) => version,
Err(err) => {
println!("cargo:warning=failed to parse `rustc --version`: {}", err);
return;
}
};
enable_simd(version);
}
fn enable_simd(version: Version) {
if env::var_os("CARGO_FEATURE_STD").is_none() {
println!("cargo:warning=building for no_std disables httparse SIMD");
return;
}
let env_disable = "CARGO_CFG_HTTPARSE_DISABLE_SIMD";
if env::var_os(env_disable).is_some() {
println!("cargo:warning=detected {} environment variable, disabling SIMD", env_disable);
return;
}
let min_simd_version = Version {
major: 1,
minor: 27,
patch: 0,
};
if version >= min_simd_version {
println!("cargo:rustc-cfg=httparse_simd");
}
// cfg(target_feature) isn't stable yet, but CARGO_CFG_TARGET_FEATURE has
// a list... We aren't doing anything unsafe, since the is_x86_feature_detected
// macro still checks in the actual lib, BUT!
//
// By peeking at the list here, we can change up slightly how we do feature
// detection in the lib. If our features aren't in the feature list, we
// stick with a cached runtime detection strategy.
//
// But if the features *are* in the list, we benefit from removing our cache,
// since the compiler will eliminate several branches with its internal
// cfg(target_feature) usage.
let env_runtime_only = "CARGO_CFG_HTTPARSE_DISABLE_SIMD_COMPILETIME";
if env::var_os(env_runtime_only).is_some() {
println!("cargo:warning=detected {} environment variable, using runtime SIMD detection only", env_runtime_only);
return;
}
let feature_list = match env::var_os("CARGO_CFG_TARGET_FEATURE") {
Some(var) => match var.into_string() {
Ok(s) => s,
Err(_) => {
println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not valid utf-8");
return;
},
},
None => {
println!("cargo:warning=CARGO_CFG_TARGET_FEATURE was not set");
return
},
};
let mut saw_sse42 = false;
let mut saw_avx2 = false;
for feature in feature_list.split(',') {
let feature = feature.trim();
if !saw_sse42 && feature == "sse4.2" {
saw_sse42 = true;
println!("cargo:rustc-cfg=httparse_simd_target_feature_sse42");
}
if !saw_avx2 && feature == "avx2" {
saw_avx2 = true;
println!("cargo:rustc-cfg=httparse_simd_target_feature_avx2");
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
struct Version {
major: u32,
minor: u32,
patch: u32,
}
impl Version {
fn parse(mut s: &str) -> Result<Version, String> {
if !s.starts_with("rustc ") {
return Err(format!("unrecognized version string: {}", s));
}
s = &s["rustc ".len()..];
let parts: Vec<&str> = s.split(".").collect();
if parts.len() < 3 {
return Err(format!("not enough version parts: {:?}", parts));
}
let mut num = String::new();
for c in parts[0].chars() {
if !c.is_digit(10) {
break;
}
num.push(c);
}
let major = try!(num.parse::<u32>().map_err(|e| e.to_string()));
num.clear();
for c in parts[1].chars() {
if !c.is_digit(10) {
break;
}
num.push(c);
}
let minor = try!(num.parse::<u32>().map_err(|e| e.to_string()));
num.clear();
for c in parts[2].chars() {
if !c.is_digit(10) {
break;
}
num.push(c);
}
let patch = try!(num.parse::<u32>().map_err(|e| e.to_string()));
Ok(Version {
major: major,
minor: minor,
patch: patch,
})
}
}