diff --git a/Cargo.toml b/Cargo.toml index 68dd41f..4b6e52e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ aya-log = { git = "https://github.com/aya-rs/aya", default-features = false } aya-log-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false } anyhow = { version = "1", default-features = false } +cargo_metadata = { version = "0.23.0", default-features = false } # `std` feature is currently required to build `clap`. # # See https://github.com/clap-rs/clap/blob/61f5ee5/clap_builder/src/lib.rs#L15. diff --git a/{{project-name}}/Cargo.toml b/{{project-name}}/Cargo.toml index 5b34957..5d99dcf 100644 --- a/{{project-name}}/Cargo.toml +++ b/{{project-name}}/Cargo.toml @@ -28,6 +28,7 @@ clap = { workspace = true, features = ["derive"] } [build-dependencies] anyhow = { workspace = true } aya-build = { workspace = true } +cargo_metadata = { workspace = true } # TODO(https://github.com/rust-lang/cargo/issues/12375): this should be an artifact dependency, but # it's not possible to tell cargo to use `-Z build-std` to build it. We cargo-in-cargo in the build # script to build this, but we want to teach cargo about the dependecy so that cache invalidation diff --git a/{{project-name}}/build.rs b/{{project-name}}/build.rs index c30640a..6f74361 100644 --- a/{{project-name}}/build.rs +++ b/{{project-name}}/build.rs @@ -1,5 +1,5 @@ use anyhow::{Context as _, anyhow}; -use aya_build::{Toolchain, cargo_metadata}; +use aya_build::Toolchain; fn main() -> anyhow::Result<()> { let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new() @@ -10,5 +10,17 @@ fn main() -> anyhow::Result<()> { .into_iter() .find(|cargo_metadata::Package { name, .. }| name.as_str() == "{{project-name}}-ebpf") .ok_or_else(|| anyhow!("{{project-name}}-ebpf package not found"))?; + let cargo_metadata::Package { + name, + manifest_path, + .. + } = ebpf_package; + let ebpf_package = aya_build::Package { + name: name.as_str(), + root_dir: manifest_path + .parent() + .ok_or_else(|| anyhow!("no parent for {manifest_path}"))? + .as_str(), + }; aya_build::build_ebpf([ebpf_package], Toolchain::default()) }