"Fossies" - the Fresh Open Source Software Archive

Member "pngquant-2.13.1/lib/rust/build.rs" (22 Nov 2020, 2102 Bytes) of package /linux/misc/pngquant-2.13.1-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Rust source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "build.rs": 2.12.3_vs_2.12.5.

    1 //! This is a build script for Cargo https://crates.io/
    2 //! It produces a static library that can be used by C or Rust.
    3 
    4 extern crate cc;
    5 
    6 use std::env;
    7 use std::path::PathBuf;
    8 use std::fs::canonicalize;
    9 
   10 fn main() {
   11     let mut cc = cc::Build::new();
   12     let compiler = cc.get_compiler();
   13     cc.warnings(false);
   14 
   15     if env::var("PROFILE").map(|p|p != "debug").unwrap_or(true) {
   16         cc.define("NDEBUG", Some("1"));
   17     } else {
   18         cc.define("DEBUG", Some("1"));
   19     }
   20 
   21     if cfg!(feature = "openmp") {
   22         cc.flag(&env::var("DEP_OPENMP_FLAG").unwrap());
   23     }
   24 
   25     let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("Needs CARGO_CFG_TARGET_ARCH");
   26     if target_arch =="x86_64" ||
   27        (target_arch == "x86" && cfg!(feature = "sse")) {
   28         cc.flag(if compiler.is_like_msvc() {"/arch:SSE2"} else {"-msse"});
   29         cc.define("USE_SSE", Some("1"));
   30     }
   31 
   32     let outdated_c_compiler = env::var("TARGET").unwrap().contains("windows-msvc");
   33     let has_msvc_files = PathBuf::from("msvc-dist/libimagequant.c").exists();
   34 
   35     if outdated_c_compiler && has_msvc_files {
   36         println!("cargo:include={}", canonicalize("msvc-dist").unwrap().display());
   37         cc.file("msvc-dist/libimagequant.c")
   38             .file("msvc-dist/nearest.c")
   39             .file("msvc-dist/kmeans.c")
   40             .file("msvc-dist/mediancut.c")
   41             .file("msvc-dist/mempool.c")
   42             .file("msvc-dist/pam.c")
   43             .file("msvc-dist/blur.c");
   44     } else {
   45         // This is so that I don't forget to publish MSVC version as well
   46         if !has_msvc_files {
   47             println!("cargo:warning=msvc-dist/ directory not present. MSVC builds may fail");
   48         }
   49         println!("cargo:include={}", canonicalize(".").unwrap().display());
   50         if !compiler.is_like_msvc() {
   51             cc.flag("-std=c99");
   52         }
   53         cc.file("libimagequant.c")
   54             .file("nearest.c")
   55             .file("kmeans.c")
   56             .file("mediancut.c")
   57             .file("mempool.c")
   58             .file("pam.c")
   59             .file("blur.c");
   60     }
   61 
   62     cc.compile("libimagequant.a");
   63 }