-
Notifications
You must be signed in to change notification settings - Fork 216
/
build.rs
87 lines (78 loc) · 3.4 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
80
81
82
83
84
85
86
87
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
use std::env;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=include/yyjson/*");
println!("cargo:rerun-if-env-changed=CC");
println!("cargo:rerun-if-env-changed=CFLAGS");
println!("cargo:rerun-if-env-changed=LDFLAGS");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_AVX512");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_SIMD");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_YYJSON");
println!("cargo:rerun-if-env-changed=RUSTFLAGS");
println!("cargo:rustc-check-cfg=cfg(intrinsics)");
println!("cargo:rustc-check-cfg=cfg(optimize)");
println!("cargo:rustc-check-cfg=cfg(Py_3_10)");
println!("cargo:rustc-check-cfg=cfg(Py_3_11)");
println!("cargo:rustc-check-cfg=cfg(Py_3_12)");
println!("cargo:rustc-check-cfg=cfg(Py_3_13)");
println!("cargo:rustc-check-cfg=cfg(Py_3_14)");
println!("cargo:rustc-check-cfg=cfg(Py_3_8)");
println!("cargo:rustc-check-cfg=cfg(Py_3_9)");
println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)");
for cfg in pyo3_build_config::get().build_script_outputs() {
println!("{cfg}");
}
if let Some(true) = version_check::supports_feature("core_intrinsics") {
println!("cargo:rustc-cfg=feature=\"intrinsics\"");
}
if let Some(true) = version_check::supports_feature("optimize_attribute") {
println!("cargo:rustc-cfg=feature=\"optimize\"");
}
if let Some(true) = version_check::supports_feature("strict_provenance") {
println!("cargo:rustc-cfg=feature=\"strict_provenance\"");
}
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
if env::var("ORJSON_DISABLE_SIMD").is_err() {
// auto build unstable SIMD on nightly
if let Some(true) = version_check::supports_feature("portable_simd") {
println!("cargo:rustc-cfg=feature=\"unstable-simd\"");
}
// auto build AVX512 on x86-64-v4 or supporting native targets
#[cfg(all(target_arch = "x86_64", target_feature = "avx512vl"))]
if let Some(true) = version_check::supports_feature("stdarch_x86_avx512") {
if env::var("ORJSON_DISABLE_AVX512").is_err() {
println!("cargo:rustc-cfg=feature=\"avx512\"");
}
}
}
#[cfg(all(
target_pointer_width = "64",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
println!("cargo:rustc-cfg=feature=\"inline_int\"");
if env::var("ORJSON_DISABLE_YYJSON").is_ok() {
if env::var("CARGO_FEATURE_YYJSON").is_ok() {
panic!("ORJSON_DISABLE_YYJSON and --features=yyjson both enabled.")
}
} else {
match cc::Build::new()
.file("include/yyjson/yyjson.c")
.include("include/yyjson")
.define("YYJSON_DISABLE_NON_STANDARD", "1")
.define("YYJSON_DISABLE_UTF8_VALIDATION", "1")
.define("YYJSON_DISABLE_UTILS", "1")
.define("YYJSON_DISABLE_WRITER", "1")
.try_compile("yyjson")
{
Ok(_) => {
println!("cargo:rustc-cfg=feature=\"yyjson\"");
}
Err(_) => {
if env::var("CARGO_FEATURE_YYJSON").is_ok() {
panic!("yyjson was enabled but the build failed. To build with a different backend do not specify the feature.")
}
}
}
}
}