A backend for the p≡p Engine built on Sequoia.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

  1. use std::env;
  2. use std::fs::File;
  3. use std::io::{Read, Write};
  4. use std::path::PathBuf;
  5. fn main() -> Result<(), std::io::Error> {
  6. // Generate
  7. // ${CARGO_TARGET_DIR}/${PROFILE}/pep_engine_sequoia_backend.pc from
  8. // ${SRC}/pep_engine_sequoia_backend.pc.in.
  9. // Location of pep_engine_sequoia_backend.pc.in.
  10. let src = env::current_dir()?;
  11. let mut pc_in = PathBuf::from(&src);
  12. pc_in.push("pep_engine_sequoia_backend.pc.in");
  13. // Location of the build directory (e.g.,
  14. // `/tmp/pep_engine_sequoia_backend/debug`).
  15. let mut build_dir = PathBuf::from(&src);
  16. if let Some(target_dir) = env::var_os("CARGO_TARGET_DIR") {
  17. // If CARGO_TARGET_DIR is absolute, this will first clear pc.
  18. build_dir.push(target_dir);
  19. }
  20. let profile = env::var_os("PROFILE")
  21. .expect("PROFILE not set");
  22. build_dir.push(&profile);
  23. // Location of pep_engine_sequoia_backend.pc.
  24. let mut pc = build_dir.clone();
  25. pc.push("pep_engine_sequoia_backend.pc");
  26. // Read the .pc.in file, do the substitutions, and generate the
  27. // .pc file.
  28. let mut pc_in = File::open(pc_in)?;
  29. let mut content = Vec::new();
  30. pc_in.read_to_end(&mut content)?;
  31. // This is set to allow the use of the library from the build
  32. // directory.
  33. let content = String::from_utf8(content).unwrap()
  34. .replace("LIBDIR",
  35. &build_dir
  36. .to_str()
  37. .expect("build directory is not UTF-8 encoded"))
  38. .replace("VERSION",
  39. &env::var_os("CARGO_PKG_VERSION")
  40. .expect("CARGO_PKG_VERSION not set")
  41. .into_string()
  42. .expect("CARGO_PKG_VERSION is not UTF-8 encoded"));
  43. let mut pc = File::create(&pc).unwrap();
  44. pc.write_all(content.as_bytes())?;
  45. println!("cargo:rerun-if-changed=build.rs");
  46. println!("cargo:rerun-if-changed=pep_engine_sequoia_backend.pc.in");
  47. eprintln!("Generated {:?} with:\n{}\nEOF", pc, content);
  48. Ok(())
  49. }