From 4fe920f761212a26c1d78a3dc2a3a1a2e19534e7 Mon Sep 17 00:00:00 2001 From: Xiaobo Liu Date: Tue, 19 Aug 2025 20:56:23 +0800 Subject: [PATCH] xtask: add the target method to Architecture Signed-off-by: Xiaobo Liu --- xtask/src/codegen/aya.rs | 11 +---------- xtask/src/codegen/aya_ebpf_bindings.rs | 11 +---------- xtask/src/codegen/mod.rs | 13 +++++++++++++ 3 files changed, 15 insertions(+), 20 deletions(-) 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 {