4
0

build.rs 1.0 KB

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