build.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // build.rs
  2. use std::fs;
  3. use std::process::Command;
  4. fn check_solana_installation() -> Result<(), String> {
  5. match Command::new("solana").arg("--version").output() {
  6. Ok(output) => {
  7. if output.status.success() {
  8. Ok(())
  9. } else {
  10. Err("Solana CLI is available but returned an error".to_string())
  11. }
  12. }
  13. Err(e) => Err(format!("Solana CLI is not installed or not in PATH: {}", e)),
  14. }
  15. }
  16. fn main() {
  17. println!("cargo:rerun-if-changed=build.rs");
  18. // Check if Solana is installed
  19. if let Err(err) = check_solana_installation() {
  20. println!("cargo:warning=Solana check failed: {}", err);
  21. return;
  22. }
  23. // Create the fixtures directory path
  24. fs::create_dir_all("tests/fixtures").expect("Failed to create fixtures directory");
  25. let status = Command::new("solana")
  26. .args([
  27. "program",
  28. "dump",
  29. "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
  30. "tests/fixtures/token_metadata.so",
  31. ])
  32. .status()
  33. .expect("Failed to run solana program dump command");
  34. if !status.success() {
  35. panic!("Failed to dump Solana program");
  36. }
  37. }