4
0

build.rs 1.3 KB

123456789101112131415161718192021222324252627282930
  1. use std::env;
  2. use which::which;
  3. use xtask::AYA_BUILD_INTEGRATION_BPF;
  4. /// Building this crate has an undeclared dependency on the `bpf-linker` binary. This would be
  5. /// better expressed by [artifact-dependencies][bindeps] but issues such as
  6. /// https://github.com/rust-lang/cargo/issues/12385 make their use impractical for the time being.
  7. ///
  8. /// This file implements an imperfect solution: it causes cargo to rebuild the crate whenever the
  9. /// mtime of `which bpf-linker` changes. Note that possibility that a new bpf-linker is added to
  10. /// $PATH ahead of the one used as the cache key still exists. Solving this in the general case
  11. /// would require rebuild-if-changed-env=PATH *and* rebuild-if-changed={every-directory-in-PATH}
  12. /// which would likely mean far too much cache invalidation.
  13. ///
  14. /// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
  15. fn main() {
  16. println!("cargo:rerun-if-env-changed={}", AYA_BUILD_INTEGRATION_BPF);
  17. let build_integration_bpf = env::var(AYA_BUILD_INTEGRATION_BPF)
  18. .as_deref()
  19. .map(str::parse)
  20. .map(Result::unwrap)
  21. .unwrap_or_default();
  22. if build_integration_bpf {
  23. let bpf_linker = which("bpf-linker").unwrap();
  24. println!("cargo:rerun-if-changed={}", bpf_linker.to_str().unwrap());
  25. }
  26. }