forked from ijl/orjson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
50 lines (44 loc) · 1.81 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
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
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=RUSTFLAGS");
println!("cargo:rerun-if-env-changed=ORJSON_ENABLE_PYDICTITER");
println!("cargo:rerun-if-env-changed=ORJSON_DISABLE_YYJSON");
let py_cfg = pyo3_build_config::get();
py_cfg.emit_pyo3_cfgs();
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 std::env::var("ORJSON_ENABLE_PYDICTITER").is_ok() {
println!("cargo:rustc-cfg=feature=\"pydictiter\"");
}
if std::env::var("ORJSON_DISABLE_YYJSON").is_ok() {
if std::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_WRITER", "1")
.define("YYJSON_DISABLE_NON_STANDARD", "1")
.try_compile("yyjson")
{
Ok(_) => {
println!("cargo:rustc-cfg=feature=\"yyjson\"");
}
Err(_) => {
if std::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.")
}
}
}
}
}