build.rs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. fn main() {
  2. // cant have both whois features at the same time
  3. if cfg!(feature = "system-whois") && cfg!(feature = "builtin-whois") {
  4. panic!("Cannot enable both 'system-whois' and 'builtin-whois' features at the same time");
  5. }
  6. let manifest = std::fs::read_to_string("Cargo.toml").expect("Could not read Cargo.toml");
  7. let mut whois_cmd = "whois".to_string();
  8. let mut whois_flags = String::new();
  9. let mut rdap_bootstrap_url = "https://data.iana.org/rdap/dns.json".to_string();
  10. let mut in_metadata = false;
  11. for line in manifest.lines() {
  12. if line.trim() == "[package.metadata.hoardom]" {
  13. in_metadata = true;
  14. continue;
  15. }
  16. if line.starts_with('[') {
  17. in_metadata = false;
  18. continue;
  19. }
  20. if in_metadata {
  21. if let Some(val) = line.strip_prefix("whois-command") {
  22. if let Some(val) = val.trim().strip_prefix('=') {
  23. whois_cmd = val.trim().trim_matches('"').to_string();
  24. }
  25. }
  26. if let Some(val) = line.strip_prefix("whois-flags") {
  27. if let Some(val) = val.trim().strip_prefix('=') {
  28. whois_flags = val.trim().trim_matches('"').to_string();
  29. }
  30. }
  31. if let Some(val) = line.strip_prefix("rdap-bootstrap-url") {
  32. if let Some(val) = val.trim().strip_prefix('=') {
  33. rdap_bootstrap_url = val.trim().trim_matches('"').to_string();
  34. }
  35. }
  36. }
  37. }
  38. println!("cargo:rustc-env=HOARDOM_WHOIS_CMD={}", whois_cmd);
  39. println!("cargo:rustc-env=HOARDOM_WHOIS_FLAGS={}", whois_flags);
  40. println!(
  41. "cargo:rustc-env=HOARDOM_RDAP_BOOTSTRAP_URL={}",
  42. rdap_bootstrap_url
  43. );
  44. // Extract list names from Lists.toml (keys that have array values)
  45. let lists_toml = std::fs::read_to_string("Lists.toml").expect("Could not read Lists.toml");
  46. let mut list_names = Vec::new();
  47. for line in lists_toml.lines() {
  48. let trimmed = line.trim();
  49. // Match lines like `standard = [` or `all = [`
  50. if let Some(eq_pos) = trimmed.find(" = [") {
  51. let name = trimmed[..eq_pos].trim();
  52. if !name.is_empty() && !name.starts_with('#') {
  53. list_names.push(name.to_string());
  54. }
  55. }
  56. }
  57. println!(
  58. "cargo:rustc-env=HOARDOM_LIST_NAMES={}",
  59. list_names.join(",")
  60. );
  61. // rerun if Cargo.toml or Lists.toml changes
  62. println!("cargo:rerun-if-changed=Cargo.toml");
  63. println!("cargo:rerun-if-changed=Lists.toml");
  64. }