Build the StringZilla C library with dynamic SIMD dispatching and returns a dictionary of enabled compilation flags to be reused for parallel backends (e.g., StringZillas).
()
| 18 | /// and returns a dictionary of enabled compilation flags to be reused for |
| 19 | /// parallel backends (e.g., StringZillas). |
| 20 | fn build_stringzilla() -> HashMap<String, bool> { |
| 21 | let mut flags = HashMap::<String, bool>::new(); |
| 22 | let mut build = cc::Build::new(); |
| 23 | build |
| 24 | .file("c/stringzilla.c") |
| 25 | .include("include") |
| 26 | .warnings(false) |
| 27 | .define("SZ_DYNAMIC_DISPATCH", "1") |
| 28 | .define("SZ_AVOID_LIBC", "0") |
| 29 | .define("SZ_DEBUG", "0") |
| 30 | .flag("-O2") |
| 31 | .flag("-std=c99") // Enforce C99 standard |
| 32 | .flag_if_supported("-fdiagnostics-color=always") |
| 33 | .flag_if_supported("-fPIC"); |
| 34 | |
| 35 | // Cargo will set different environment variables that we can use to properly configure the build. |
| 36 | // https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts |
| 37 | // https://doc.rust-lang.org/reference/conditional-compilation.html#r-cfg.target_endian |
| 38 | let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default(); |
| 39 | let target_endian = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap_or_default(); |
| 40 | let target_bits = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap_or_default(); |
| 41 | |
| 42 | // Set endian-specific macro |
| 43 | if target_endian == "big" { |
| 44 | build.define("SZ_IS_BIG_ENDIAN_", "1"); |
| 45 | flags.insert("SZ_IS_BIG_ENDIAN_".to_string(), true); |
| 46 | } else { |
| 47 | build.define("SZ_IS_BIG_ENDIAN_", "0"); |
| 48 | flags.insert("SZ_IS_BIG_ENDIAN_".to_string(), false); |
| 49 | } |
| 50 | |
| 51 | if target_arch == "x86_64" && target_bits == "64" { |
| 52 | build.define("SZ_IS_64BIT_X86_", "1"); |
| 53 | build.define("SZ_IS_64BIT_ARM_", "0"); |
| 54 | flags.insert("SZ_IS_64BIT_X86_".to_string(), true); |
| 55 | flags.insert("SZ_IS_64BIT_ARM_".to_string(), false); |
| 56 | } else if target_arch == "aarch64" && target_bits == "64" { |
| 57 | build.define("SZ_IS_64BIT_X86_", "0"); |
| 58 | build.define("SZ_IS_64BIT_ARM_", "1"); |
| 59 | flags.insert("SZ_IS_64BIT_X86_".to_string(), false); |
| 60 | flags.insert("SZ_IS_64BIT_ARM_".to_string(), true); |
| 61 | } else { |
| 62 | build.define("SZ_IS_64BIT_X86_", "0"); |
| 63 | build.define("SZ_IS_64BIT_ARM_", "0"); |
| 64 | flags.insert("SZ_IS_64BIT_X86_".to_string(), false); |
| 65 | flags.insert("SZ_IS_64BIT_ARM_".to_string(), false); |
| 66 | } |
| 67 | |
| 68 | // At start we will try compiling with all SIMD backends enabled |
| 69 | // https://doc.rust-lang.org/reference/conditional-compilation.html#target_arch |
| 70 | let flags_to_try = match target_arch.as_str() { |
| 71 | "arm" | "aarch64" => vec![ |
| 72 | // |
| 73 | "SZ_USE_SVE2_AES", |
| 74 | "SZ_USE_SVE2", |
| 75 | "SZ_USE_SVE", |
| 76 | "SZ_USE_NEON_SHA", |
| 77 | "SZ_USE_NEON_AES", |