-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.rs
79 lines (63 loc) · 1.85 KB
/
build.rs
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
extern crate cc;
extern crate rustc_version;
use rustc_version::{version, Version};
use std::{env, fmt};
fn main() {
println!("cargo:rerun-if-env-changed=CUPID_PRETEND_CPUID_NOT_AVAILABLE");
println!("cargo:rerun-if-env-changed=CUPID_FORCE_ENGINE");
if env::var_os("CUPID_PRETEND_CPUID_NOT_AVAILABLE").is_some() {
return;
}
let target = env::var("TARGET")
.expect("TARGET environment variable must be set");
// not supported on non-x86 platforms
if !target.starts_with("x86_64") &&
!target.starts_with("i686") &&
!target.starts_with("i586") {
return
}
println!("cargo:rustc-cfg=cpuid_available");
let engine = Engine::detect();
if engine == Engine::C {
build_c_shim(&target);
}
println!("cargo:rustc-cfg={}", engine);
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
enum Engine {
C,
Std,
}
impl fmt::Display for Engine {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Engine::C => "engine_c",
Engine::Std => "engine_std",
}.fmt(f)
}
}
impl Engine {
fn detect() -> Self {
match env::var("CUPID_FORCE_ENGINE").as_ref().map(|x| &**x) {
Ok("c") => return Engine::C,
Ok("std") => return Engine::Std,
_ => {}
};
let vers = version().expect("Could not determine Rust version");
let std_simd_vers = Version::parse("1.27.0-beta.0").expect("Invalid base version");
if vers >= std_simd_vers {
Engine::Std
} else {
Engine::C
}
}
}
fn build_c_shim(target: &str) {
let mut cfg = cc::Build::new();
if target.contains("msvc") {
cfg.define("MSVC", None);
}
cfg.file("src/arch/shim.c");
cfg.compile("libcupid.a");
println!("cargo:rerun-if-changed=src/arch/shim.c");
}