4
0

build.rs 1.5 KB

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