1use std::fs;
2use std::collections::HashSet;
3
4pub fn run() {
5 println!("cargo:rerun-if-changed=Cargo.toml");
7
8 let mut detected_packages = HashSet::new();
9
10 let mut in_dependencies_section = false;
11
12 if let Ok(toml_content) = fs::read_to_string("Cargo.toml") {
13 for line in toml_content.lines() {
14 let line = line.trim();
15 if line.starts_with('#') {
17 continue;
18 }
19
20 if line.starts_with('[') && line.ends_with(']') {
22 let section = &line[1..line.len() - 1];
23 in_dependencies_section = section == "dependencies"
24 || section.starts_with("dependencies.")
25 || section == "dev-dependencies"
26 || section == "build-dependencies";
27 continue;
28 }
29
30 if !in_dependencies_section {
31 continue;
32 }
33
34 if let Some(pos) = line.find("rustbasic-") {
35 let start_idx = pos + "rustbasic-".len();
36 let mut end_idx = start_idx;
37 let chars: Vec<char> = line.chars().collect();
38 while end_idx < chars.len() {
39 let c = chars[end_idx];
40 if c.is_alphanumeric() || c == '_' || c == '-' {
41 end_idx += 1;
42 } else {
43 break;
44 }
45 }
46
47 if end_idx > start_idx {
48 let suffix: String = chars[start_idx..end_idx].iter().collect();
49 if suffix != "core" && suffix != "cli" && !suffix.is_empty() {
51 detected_packages.insert(suffix);
52 }
53 }
54 }
55 }
56 }
57
58 for suffix in &detected_packages {
60 println!("cargo:rustc-check-cfg=cfg({})", suffix);
61 println!("cargo:rustc-cfg={}", suffix);
62 }
63
64 if !detected_packages.contains("breeze") {
66 println!("cargo:rustc-check-cfg=cfg(breeze)");
67 }
68
69 if let Ok(target) = std::env::var("TARGET") && target.contains("android") {
70 let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
71 println!("cargo:rustc-link-search=native={}/target/{}/sqlite", manifest_dir, target);
72 }
73}