File: mod.rs

package info (click to toggle)
rust-fast-image-resize 5.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,772 kB
  • sloc: makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,291 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use std::env;
use std::path::PathBuf;
use std::process::Command;

pub use bencher::*;
pub use resize_functions::*;
pub use results::*;
use serde::Deserialize;

mod bencher;
mod resize_functions;
mod results;
pub mod testing;

const fn get_arch_id_and_name() -> (&'static str, &'static str) {
    #[cfg(target_arch = "x86_64")]
    return ("x86_64", "x86_64");
    #[cfg(target_arch = "aarch64")]
    return ("arm64", "arm64");
    #[cfg(target_arch = "wasm32")]
    return ("wasm32", "Wasm32");
    #[cfg(not(any(
        target_arch = "x86_64",
        target_arch = "aarch64",
        target_arch = "wasm32"
    )))]
    return ("unknown", "Unknown");
}

/// Returns the Cargo target directory, possibly calling `cargo metadata` to
/// figure it out.
fn cargo_target_directory() -> Option<PathBuf> {
    #[derive(Deserialize)]
    struct Metadata {
        target_directory: PathBuf,
    }

    env::var_os("CARGO_TARGET_DIR")
        .map(PathBuf::from)
        .or_else(|| {
            let output = Command::new(env::var_os("CARGO")?)
                .args(["metadata", "--format-version", "1"])
                .output()
                .ok()?;
            let metadata: Metadata = serde_json::from_slice(&output.stdout).ok()?;
            Some(metadata.target_directory)
        })
}