build.rs 900 B

12345678910111213141516171819202122232425262728293031
  1. use std::env;
  2. fn main() {
  3. println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH");
  4. if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") {
  5. println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
  6. } else {
  7. let arch = env::var("HOST").unwrap();
  8. let mut arch = arch.split_once('-').map_or(&*arch, |x| x.0);
  9. if arch.starts_with("riscv64") {
  10. arch = "riscv64";
  11. }
  12. println!("cargo:rustc-cfg=bpf_target_arch=\"{arch}\"");
  13. }
  14. print!("cargo::rustc-check-cfg=cfg(bpf_target_arch, values(");
  15. for arch in [
  16. "aarch64",
  17. "arm",
  18. "loongarch64",
  19. "mips",
  20. "powerpc64",
  21. "riscv64",
  22. "s390x",
  23. "x86_64",
  24. ] {
  25. print!("\"{arch}\",");
  26. }
  27. println!("))");
  28. println!("cargo::rustc-check-cfg=cfg(target_arch, values(\"asmjs\",\"nvptx\",\"xtensa\"))");
  29. }