-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
89 lines (70 loc) · 3.13 KB
/
build.rs
File metadata and controls
89 lines (70 loc) · 3.13 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
//! Build script for Pyroid
//!
//! This script configures the build process for Pyroid.
use std::env;
extern crate num_cpus;
use std::path::Path;
fn main() {
// Configure PyO3
pyo3_build_config::add_extension_module_link_args();
// Print cargo configuration
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=Cargo.toml");
println!("cargo:rerun-if-changed=src/");
// Set up feature-specific configurations
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join("config.rs");
let mut config = String::new();
// Add feature flags
config.push_str("/// Feature flags\n");
config.push_str("pub mod features {\n");
#[cfg(feature = "math")]
config.push_str(" pub const MATH_ENABLED: bool = true;\n");
#[cfg(not(feature = "math"))]
config.push_str(" pub const MATH_ENABLED: bool = false;\n");
#[cfg(feature = "text")]
config.push_str(" pub const TEXT_ENABLED: bool = true;\n");
#[cfg(not(feature = "text"))]
config.push_str(" pub const TEXT_ENABLED: bool = false;\n");
#[cfg(feature = "data")]
config.push_str(" pub const DATA_ENABLED: bool = true;\n");
#[cfg(not(feature = "data"))]
config.push_str(" pub const DATA_ENABLED: bool = false;\n");
#[cfg(feature = "io")]
config.push_str(" pub const IO_ENABLED: bool = true;\n");
#[cfg(not(feature = "io"))]
config.push_str(" pub const IO_ENABLED: bool = false;\n");
#[cfg(feature = "image")]
config.push_str(" pub const IMAGE_ENABLED: bool = true;\n");
#[cfg(not(feature = "image"))]
config.push_str(" pub const IMAGE_ENABLED: bool = false;\n");
#[cfg(feature = "ml")]
config.push_str(" pub const ML_ENABLED: bool = true;\n");
#[cfg(not(feature = "ml"))]
config.push_str(" pub const ML_ENABLED: bool = false;\n");
config.push_str("}\n");
// Add platform-specific configurations
config.push_str("\n/// Platform information\n");
config.push_str("pub mod platform {\n");
#[cfg(target_os = "windows")]
config.push_str(" pub const OS: &str = \"windows\";\n");
#[cfg(target_os = "macos")]
config.push_str(" pub const OS: &str = \"macos\";\n");
#[cfg(target_os = "linux")]
config.push_str(" pub const OS: &str = \"linux\";\n");
#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))]
config.push_str(" pub const OS: &str = \"unknown\";\n");
#[cfg(target_arch = "x86_64")]
config.push_str(" pub const ARCH: &str = \"x86_64\";\n");
#[cfg(target_arch = "aarch64")]
config.push_str(" pub const ARCH: &str = \"aarch64\";\n");
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
config.push_str(" pub const ARCH: &str = \"unknown\";\n");
// Add CPU information
config.push_str(" pub const NUM_CPUS: usize = ");
config.push_str(&num_cpus::get().to_string());
config.push_str(";\n");
config.push_str("}\n");
// Write the configuration file
std::fs::write(out_path, config).unwrap();
}