Add cargo_metadata build dependency

cargo_metadata is no longer exported from aya-build.
pull/163/head
Tamir Duberstein 3 days ago
parent 608b6910e2
commit f6e04be74e
No known key found for this signature in database

@ -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 } aya-log-ebpf = { git = "https://github.com/aya-rs/aya", default-features = false }
anyhow = { version = "1", 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`. # `std` feature is currently required to build `clap`.
# #
# See https://github.com/clap-rs/clap/blob/61f5ee5/clap_builder/src/lib.rs#L15. # See https://github.com/clap-rs/clap/blob/61f5ee5/clap_builder/src/lib.rs#L15.

@ -28,6 +28,7 @@ clap = { workspace = true, features = ["derive"] }
[build-dependencies] [build-dependencies]
anyhow = { workspace = true } anyhow = { workspace = true }
aya-build = { 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 # 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 # 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 # script to build this, but we want to teach cargo about the dependecy so that cache invalidation

@ -1,5 +1,5 @@
use anyhow::{Context as _, anyhow}; use anyhow::{Context as _, anyhow};
use aya_build::{Toolchain, cargo_metadata}; use aya_build::Toolchain;
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new() let cargo_metadata::Metadata { packages, .. } = cargo_metadata::MetadataCommand::new()
@ -10,5 +10,17 @@ fn main() -> anyhow::Result<()> {
.into_iter() .into_iter()
.find(|cargo_metadata::Package { name, .. }| name.as_str() == "{{project-name}}-ebpf") .find(|cargo_metadata::Package { name, .. }| name.as_str() == "{{project-name}}-ebpf")
.ok_or_else(|| anyhow!("{{project-name}}-ebpf package not found"))?; .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()) aya_build::build_ebpf([ebpf_package], Toolchain::default())
} }

Loading…
Cancel
Save