]>
git.proxmox.com Git - cargo.git/blob - vendor/memchr/build.rs
4 enable_simd_optimizations();
8 // This adds various simd cfgs if this compiler and target support it.
10 // This can be disabled with RUSTFLAGS="--cfg memchr_disable_auto_simd", but
11 // this is generally only intended for testing.
13 // On targets which don't feature SSE2, this is disabled, as LLVM wouln't know
14 // how to work with SSE2 operands. Enabling SSE4.2 and AVX on SSE2-only targets
15 // is not a problem. In that case, the fastest option will be chosen at
17 fn enable_simd_optimizations() {
18 if is_env_set("CARGO_CFG_MEMCHR_DISABLE_AUTO_SIMD") {
21 let arch
= env
::var("CARGO_CFG_TARGET_ARCH").unwrap();
24 if !target_has_feature("sse2") {
27 println
!("cargo:rustc-cfg=memchr_runtime_simd");
28 println
!("cargo:rustc-cfg=memchr_runtime_sse2");
29 println
!("cargo:rustc-cfg=memchr_runtime_sse42");
30 println
!("cargo:rustc-cfg=memchr_runtime_avx");
32 "wasm32" | "wasm64" => {
33 if !target_has_feature("simd128") {
36 println
!("cargo:rustc-cfg=memchr_runtime_simd");
37 println
!("cargo:rustc-cfg=memchr_runtime_wasm128");
43 // This adds a `memchr_libc` cfg if and only if libc can be used, if no other
44 // better option is available.
46 // This could be performed in the source code, but it's simpler to do it once
47 // here and consolidate it into one cfg knob.
49 // Basically, we use libc only if its enabled and if we aren't targeting a
50 // known bad platform. For example, wasm32 doesn't have a libc and the
51 // performance of memchr on Windows is seemingly worse than the fallback
54 const NO_ARCH
: &'
static [&'
static str] = &["wasm32", "windows"];
55 const NO_ENV
: &'
static [&'
static str] = &["sgx"];
57 if !is_feature_set("LIBC") {
61 let arch
= match env
::var("CARGO_CFG_TARGET_ARCH") {
65 let env
= match env
::var("CARGO_CFG_TARGET_ENV") {
69 if NO_ARCH
.contains(&&*arch
) || NO_ENV
.contains(&&*env
) {
73 println
!("cargo:rustc-cfg=memchr_libc");
76 fn is_feature_set(name
: &str) -> bool
{
77 is_env_set(&format
!("CARGO_FEATURE_{}", name
))
80 fn is_env_set(name
: &str) -> bool
{
81 env
::var_os(name
).is_some()
84 fn target_has_feature(feature
: &str) -> bool
{
85 env
::var("CARGO_CFG_TARGET_FEATURE")
86 .map(|features
| features
.contains(feature
))