build.rs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. use {
  2. regex::Regex,
  3. std::{
  4. fs::File,
  5. io::{prelude::*, BufWriter},
  6. path::PathBuf,
  7. str,
  8. },
  9. };
  10. /**
  11. * Extract a list of registered syscall names and save it in a file
  12. * for distribution with the SDK. This file is read by cargo-build-sbf
  13. * to verify undefined symbols in a .so module that cargo-build-sbf has built.
  14. */
  15. fn main() {
  16. let syscalls_rs_path = PathBuf::from("../src/syscalls/mod.rs");
  17. let syscalls_txt_path = PathBuf::from("../../../platform-tools-sdk/sbf/syscalls.txt");
  18. println!(
  19. "cargo:warning=(not a warning) Generating {1} from {0}",
  20. syscalls_rs_path.display(),
  21. syscalls_txt_path.display()
  22. );
  23. let mut file = match File::open(&syscalls_rs_path) {
  24. Ok(x) => x,
  25. Err(err) => panic!("Failed to open {}: {}", syscalls_rs_path.display(), err),
  26. };
  27. let mut text = vec![];
  28. file.read_to_end(&mut text).unwrap();
  29. let text = str::from_utf8(&text).unwrap();
  30. let file = match File::create(&syscalls_txt_path) {
  31. Ok(x) => x,
  32. Err(err) => panic!("Failed to create {}: {}", syscalls_txt_path.display(), err),
  33. };
  34. let mut out = BufWriter::new(file);
  35. let sysc_re = Regex::new(r#"register_syscall_by_name\([[:space:]]*b"([^"]+)","#).unwrap();
  36. for caps in sysc_re.captures_iter(text) {
  37. let name = caps[1].to_string();
  38. writeln!(out, "{name}").unwrap();
  39. }
  40. }