build.rs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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!("cargo:rustc-env=HOARDOM_RDAP_BOOTSTRAP_URL={}", rdap_bootstrap_url);
  41. // Extract list names from Lists.toml (keys that have array values)
  42. let lists_toml = std::fs::read_to_string("Lists.toml").expect("Could not read Lists.toml");
  43. let mut list_names = Vec::new();
  44. for line in lists_toml.lines() {
  45. let trimmed = line.trim();
  46. // Match lines like `standard = [` or `all = [`
  47. if let Some(eq_pos) = trimmed.find(" = [") {
  48. let name = trimmed[..eq_pos].trim();
  49. if !name.is_empty() && !name.starts_with('#') {
  50. list_names.push(name.to_string());
  51. }
  52. }
  53. }
  54. println!("cargo:rustc-env=HOARDOM_LIST_NAMES={}", list_names.join(","));
  55. // rerun if Cargo.toml or Lists.toml changes
  56. println!("cargo:rerun-if-changed=Cargo.toml");
  57. println!("cargo:rerun-if-changed=Lists.toml");
  58. }