xtask: add the target method to Architecture

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
main
Xiaobo Liu 4 days ago committed by Tamir Duberstein
parent 2869cb884c
commit 4fe920f761

@ -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 { let target = arch.target();
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",
};
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

@ -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 { let target = arch.target();
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",
};
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

@ -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 {

Loading…
Cancel
Save