diff --git a/Cargo.toml b/Cargo.toml index 3ff553bc..16825e1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,7 +67,7 @@ base64 = { version = "0.22.1", default-features = false } bindgen = { version = "0.72", default-features = false } bitflags = { version = "2.2.1", default-features = false } bytes = { version = "1", default-features = false } -cargo_metadata = { version = "0.21.0", default-features = false } +cargo_metadata = { version = "0.22.0", default-features = false } clap = { version = "4", default-features = false } const-assert = { version = "1.0.1", default-features = false } dialoguer = { version = "0.11", default-features = false } diff --git a/xtask/src/codegen/aya.rs b/xtask/src/codegen/aya.rs index 381d8b6d..c1d1f377 100644 --- a/xtask/src/codegen/aya.rs +++ b/xtask/src/codegen/aya.rs @@ -182,16 +182,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { // Set target triple. This will set the right flags (which you can see // running clang -target=X -E - -dM "aarch64-unknown-linux-gnu", - Architecture::ARMv7 => "armv7-unknown-linux-gnu", - Architecture::LoongArch64 => "loongarch64-unknown-linux-gnu", - Architecture::Mips => "mips-unknown-linux-gnu", - Architecture::PowerPC64 => "powerpc64le-unknown-linux-gnu", - Architecture::RISCV64 => "riscv64-unknown-linux-gnu", - Architecture::S390X => "s390x-unknown-linux-gnu", - Architecture::X86_64 => "x86_64-unknown-linux-gnu", - }; + let target = arch.target(); bindgen = bindgen.clang_args(&["-target", target]); // Set the sysroot. This is needed to ensure that the correct arch diff --git a/xtask/src/codegen/aya_ebpf_bindings.rs b/xtask/src/codegen/aya_ebpf_bindings.rs index d9ec9a61..a44757fe 100644 --- a/xtask/src/codegen/aya_ebpf_bindings.rs +++ b/xtask/src/codegen/aya_ebpf_bindings.rs @@ -93,16 +93,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<()> { // Set target triple. This will set the right flags (which you can see // running clang -target=X -E - -dM "aarch64-unknown-linux-gnu", - Architecture::ARMv7 => "armv7-unknown-linux-gnu", - Architecture::LoongArch64 => "loongarch64-unknown-linux-gnu", - Architecture::Mips => "mips-unknown-linux-gnu", - Architecture::PowerPC64 => "powerpc64le-unknown-linux-gnu", - Architecture::RISCV64 => "riscv64-unknown-linux-gnu", - Architecture::S390X => "s390x-unknown-linux-gnu", - Architecture::X86_64 => "x86_64-unknown-linux-gnu", - }; + let target = arch.target(); bindgen = bindgen.clang_args(["-target", target]); // Set the sysroot. This is needed to ensure that the correct arch diff --git a/xtask/src/codegen/mod.rs b/xtask/src/codegen/mod.rs index 6b3f0f55..85442fc2 100644 --- a/xtask/src/codegen/mod.rs +++ b/xtask/src/codegen/mod.rs @@ -34,6 +34,19 @@ impl Architecture { pub fn supported() -> &'static [Architecture] { SUPPORTED_ARCHS } + + pub fn target(&self) -> &'static str { + match self { + Architecture::AArch64 => "aarch64-unknown-linux-gnu", + Architecture::ARMv7 => "armv7-unknown-linux-gnu", + Architecture::LoongArch64 => "loongarch64-unknown-linux-gnu", + Architecture::Mips => "mips-unknown-linux-gnu", + Architecture::PowerPC64 => "powerpc64le-unknown-linux-gnu", + Architecture::RISCV64 => "riscv64-unknown-linux-gnu", + Architecture::S390X => "s390x-unknown-linux-gnu", + Architecture::X86_64 => "x86_64-unknown-linux-gnu", + } + } } impl std::str::FromStr for Architecture {