Browse Source

xtask: add the target method to Architecture

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
Xiaobo Liu 4 days ago
parent
commit
4fe920f761
3 changed files with 15 additions and 20 deletions
  1. 1 10
      xtask/src/codegen/aya.rs
  2. 1 10
      xtask/src/codegen/aya_ebpf_bindings.rs
  3. 13 0
      xtask/src/codegen/mod.rs

+ 1 - 10
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
         // Set target triple. This will set the right flags (which you can see
         // running clang -target=X  -E - -dM </dev/null)
         // running clang -target=X  -E - -dM </dev/null)
-        let target = match arch {
-            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",
-        };
+        let target = arch.target();
         bindgen = bindgen.clang_args(&["-target", target]);
         bindgen = bindgen.clang_args(&["-target", target]);
 
 
         // Set the sysroot. This is needed to ensure that the correct arch
         // Set the sysroot. This is needed to ensure that the correct arch

+ 1 - 10
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
         // Set target triple. This will set the right flags (which you can see
         // running clang -target=X  -E - -dM </dev/null)
         // running clang -target=X  -E - -dM </dev/null)
-        let target = match arch {
-            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",
-        };
+        let target = arch.target();
         bindgen = bindgen.clang_args(["-target", target]);
         bindgen = bindgen.clang_args(["-target", target]);
 
 
         // Set the sysroot. This is needed to ensure that the correct arch
         // Set the sysroot. This is needed to ensure that the correct arch

+ 13 - 0
xtask/src/codegen/mod.rs

@@ -34,6 +34,19 @@ impl Architecture {
     pub fn supported() -> &'static [Architecture] {
     pub fn supported() -> &'static [Architecture] {
         SUPPORTED_ARCHS
         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 {
 impl std::str::FromStr for Architecture {