-
Notifications
You must be signed in to change notification settings - Fork 303
Expand file tree
/
Copy pathbuild.rs
More file actions
90 lines (78 loc) · 3.43 KB
/
build.rs
File metadata and controls
90 lines (78 loc) · 3.43 KB
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
88
89
90
// SPDX-License-Identifier: MPL-2.0
// Copyright ijl (2021-2026)
fn main() {
let python_config = pyo3_build_config::get();
if python_config.is_free_threaded() && std::env::var("ORJSON_BUILD_FREETHREADED").is_err() {
not_supported("free-threaded Python")
}
#[allow(unused_variables)]
let is_64_bit_python = matches!(python_config.pointer_width, Some(64));
match python_config.implementation {
pyo3_build_config::PythonImplementation::CPython => {
println!("cargo:rustc-cfg=CPython");
if python_config.abi3 {
println!("cargo:rustc-cfg=Py_LIMITED_ABI");
}
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
if is_64_bit_python && !python_config.abi3 {
println!("cargo:rustc-cfg=feature=\"inline_int\"");
#[cfg(target_endian = "little")]
println!("cargo:rustc-cfg=feature=\"inline_str\"");
}
}
pyo3_build_config::PythonImplementation::GraalPy => not_supported("GraalPy"),
pyo3_build_config::PythonImplementation::PyPy => not_supported("PyPy"),
}
for cfg in python_config.build_script_outputs() {
println!("{cfg}");
}
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_BUILD_FREETHREADED");
println!("cargo:rerun-if-env-changed=RUSTFLAGS");
println!("cargo:rustc-check-cfg=cfg(cold_path)");
println!("cargo:rustc-check-cfg=cfg(CPython)");
println!("cargo:rustc-check-cfg=cfg(GraalPy)");
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_15)");
println!("cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)");
println!("cargo:rustc-check-cfg=cfg(Py_LIMITED_ABI)");
println!("cargo:rustc-check-cfg=cfg(PyPy)");
#[cfg(all(target_arch = "x86_64", not(target_os = "macos")))]
if is_64_bit_python {
println!("cargo:rustc-cfg=feature=\"avx512\"");
}
#[cfg(target_arch = "aarch64")]
if version_check::supports_feature("portable_simd").unwrap_or(false) {
println!("cargo:rustc-cfg=feature=\"generic_simd\"");
}
if version_check::is_min_version("1.95.0")
.unwrap_or(version_check::supports_feature("cold_path").unwrap_or(false))
{
println!("cargo:rustc-cfg=feature=\"cold_path\"");
}
if version_check::supports_feature("optimize_attribute").unwrap_or(false) {
println!("cargo:rustc-cfg=feature=\"optimize\"");
}
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")
.compile("yyjson")
}
fn not_supported(flavor: &str) {
let version = env!("CARGO_PKG_VERSION");
eprintln!("\n\n\norjson v{version} does not support {flavor}\n\n\n");
std::process::exit(1);
}