|
@@ -1,5 +1,4 @@
|
|
|
use std::{
|
|
|
- collections::{HashMap, HashSet},
|
|
|
env,
|
|
|
ffi::OsString,
|
|
|
fmt::Write as _,
|
|
@@ -10,34 +9,24 @@ use std::{
|
|
|
};
|
|
|
|
|
|
use cargo_metadata::{
|
|
|
- Artifact, CompilerMessage, Dependency, Message, Metadata, MetadataCommand, Package, Target,
|
|
|
+ Artifact, CompilerMessage, Message, Metadata, MetadataCommand, Package, Target,
|
|
|
};
|
|
|
-use which::which;
|
|
|
-use xtask::{exec, LIBBPF_DIR};
|
|
|
+use xtask::{exec, AYA_BUILD_INTEGRATION_BPF, LIBBPF_DIR};
|
|
|
|
|
|
fn main() {
|
|
|
- const AYA_BUILD_INTEGRATION_BPF: &str = "AYA_BUILD_INTEGRATION_BPF";
|
|
|
-
|
|
|
println!("cargo:rerun-if-env-changed={}", AYA_BUILD_INTEGRATION_BPF);
|
|
|
|
|
|
- let build_integration_bpf = match env::var_os(AYA_BUILD_INTEGRATION_BPF) {
|
|
|
- None => false,
|
|
|
- Some(s) => {
|
|
|
- let s = s.to_str().unwrap();
|
|
|
- s.parse::<bool>().unwrap()
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- const INTEGRATION_EBPF_PACKAGE: &str = "integration-ebpf";
|
|
|
+ let build_integration_bpf = env::var(AYA_BUILD_INTEGRATION_BPF)
|
|
|
+ .as_deref()
|
|
|
+ .map(str::parse)
|
|
|
+ .map(Result::unwrap)
|
|
|
+ .unwrap_or_default();
|
|
|
|
|
|
let Metadata { packages, .. } = MetadataCommand::new().no_deps().exec().unwrap();
|
|
|
- let packages: HashMap<String, _> = packages
|
|
|
+ let integration_ebpf_package = packages
|
|
|
.into_iter()
|
|
|
- .map(|package| {
|
|
|
- let Package { name, .. } = &package;
|
|
|
- (name.clone(), package)
|
|
|
- })
|
|
|
- .collect();
|
|
|
+ .find(|Package { name, .. }| name == "integration-ebpf")
|
|
|
+ .unwrap();
|
|
|
|
|
|
let manifest_dir = env::var_os("CARGO_MANIFEST_DIR").unwrap();
|
|
|
let manifest_dir = PathBuf::from(manifest_dir);
|
|
@@ -121,44 +110,8 @@ fn main() {
|
|
|
|
|
|
let target = format!("{target}-unknown-none");
|
|
|
|
|
|
- // Teach cargo about our dependencies.
|
|
|
- let mut visited = HashSet::new();
|
|
|
- let mut frontier = vec![INTEGRATION_EBPF_PACKAGE];
|
|
|
- while let Some(package) = frontier.pop() {
|
|
|
- if !visited.insert(package) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- let Package { dependencies, .. } = packages.get(package).unwrap();
|
|
|
- for Dependency { name, path, .. } in dependencies {
|
|
|
- if let Some(path) = path {
|
|
|
- println!("cargo:rerun-if-changed={}", path.as_str());
|
|
|
- frontier.push(name);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // Create a symlink in the out directory to work around the fact that cargo ignores anything
|
|
|
- // in `$CARGO_HOME`, which is also where `cargo install` likes to place binaries. Cargo will
|
|
|
- // stat through the symlink and discover that bpf-linker has changed.
|
|
|
- //
|
|
|
- // This was introduced in https://github.com/rust-lang/cargo/commit/99f841c.
|
|
|
- {
|
|
|
- let bpf_linker = which("bpf-linker").unwrap();
|
|
|
- let bpf_linker_symlink = out_dir.join("bpf-linker");
|
|
|
- match fs::remove_file(&bpf_linker_symlink) {
|
|
|
- Ok(()) => {}
|
|
|
- Err(err) => {
|
|
|
- if err.kind() != std::io::ErrorKind::NotFound {
|
|
|
- panic!("failed to remove symlink: {err}")
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- std::os::unix::fs::symlink(&bpf_linker, &bpf_linker_symlink).unwrap();
|
|
|
- println!(
|
|
|
- "cargo:rerun-if-changed={}",
|
|
|
- bpf_linker_symlink.to_str().unwrap()
|
|
|
- );
|
|
|
- }
|
|
|
+ let Package { manifest_path, .. } = integration_ebpf_package;
|
|
|
+ let integration_ebpf_dir = manifest_path.parent().unwrap();
|
|
|
|
|
|
let mut cmd = Command::new("cargo");
|
|
|
cmd.args([
|
|
@@ -172,8 +125,6 @@ fn main() {
|
|
|
]);
|
|
|
|
|
|
// Workaround to make sure that the rust-toolchain.toml is respected.
|
|
|
- let Package { manifest_path, .. } = packages.get(INTEGRATION_EBPF_PACKAGE).unwrap();
|
|
|
- let integration_ebpf_dir = manifest_path.parent().unwrap();
|
|
|
cmd.env_remove("RUSTUP_TOOLCHAIN")
|
|
|
.current_dir(integration_ebpf_dir);
|
|
|
|
|
@@ -231,7 +182,7 @@ fn main() {
|
|
|
fs::write(&dst, []).unwrap_or_else(|err| panic!("failed to create {dst:?}: {err}"));
|
|
|
}
|
|
|
|
|
|
- let Package { targets, .. } = packages.get(INTEGRATION_EBPF_PACKAGE).unwrap();
|
|
|
+ let Package { targets, .. } = integration_ebpf_package;
|
|
|
for Target { name, kind, .. } in targets {
|
|
|
if *kind != ["bin"] {
|
|
|
continue;
|