Added MIPS bindings

1. Updated xtask scripts to generated bindings for MIPS
alongside other architectures.
2. Updated `aya-obj/src/generated/mod.rs` and `bpf/aya-bpf-bindings/src/lib.rs` to
use the mips bindings.
3. Update `write_to_file` method to create parent directories if they
   don't exist already.
pull/482/head
Ishan Jain 2 years ago
parent 4cc0ea09e0
commit c0f82ef9d3
No known key found for this signature in database
GPG Key ID: 0506DB2A1CC75C27

@ -13,6 +13,8 @@ mod btf_internal_bindings;
mod linux_bindings_aarch64; mod linux_bindings_aarch64;
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
mod linux_bindings_armv7; mod linux_bindings_armv7;
#[cfg(target_arch = "mips")]
mod linux_bindings_mips;
#[cfg(target_arch = "riscv64")] #[cfg(target_arch = "riscv64")]
mod linux_bindings_riscv64; mod linux_bindings_riscv64;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
@ -31,3 +33,6 @@ pub use linux_bindings_aarch64::*;
#[cfg(target_arch = "riscv64")] #[cfg(target_arch = "riscv64")]
pub use linux_bindings_riscv64::*; pub use linux_bindings_riscv64::*;
#[cfg(target_arch = "mips")]
pub use linux_bindings_mips::*;

@ -1,5 +1,5 @@
use std::{ use std::{
fs::File, fs::{create_dir_all, File},
io::{self, Write}, io::{self, Write},
path::Path, path::Path,
}; };
@ -11,6 +11,13 @@ pub mod rustfmt;
pub use generate::{generate, InputFile}; pub use generate::{generate, InputFile};
pub fn write_to_file<T: AsRef<Path>>(path: T, code: &str) -> Result<(), io::Error> { pub fn write_to_file<T: AsRef<Path>>(path: T, code: &str) -> Result<(), io::Error> {
// Create parent directories if they don't exist already
if let Some(parent) = path.as_ref().parent() {
if !parent.exists() {
create_dir_all(parent)?;
}
}
let mut file = File::create(path)?; let mut file = File::create(path)?;
file.write_all(code.as_bytes()) file.write_all(code.as_bytes())
} }

@ -13,6 +13,9 @@ mod aarch64;
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
mod riscv64; mod riscv64;
#[cfg(bpf_target_arch = "mips")]
mod mips;
mod gen { mod gen {
#[cfg(bpf_target_arch = "x86_64")] #[cfg(bpf_target_arch = "x86_64")]
pub use super::x86_64::*; pub use super::x86_64::*;
@ -25,6 +28,9 @@ mod gen {
#[cfg(bpf_target_arch = "riscv64")] #[cfg(bpf_target_arch = "riscv64")]
pub use super::riscv64::*; pub use super::riscv64::*;
#[cfg(bpf_target_arch = "mips")]
pub use super::mips::*;
} }
pub use gen::helpers; pub use gen::helpers;

@ -173,6 +173,7 @@ fn codegen_bindings(opts: &Options) -> Result<(), anyhow::Error> {
// 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 = match arch {
Architecture::Mips => "mips-unknown-linux-gnu",
Architecture::X86_64 => "x86_64-unknown-linux-gnu", Architecture::X86_64 => "x86_64-unknown-linux-gnu",
Architecture::ARMv7 => "armv7-unknown-linux-gnu", Architecture::ARMv7 => "armv7-unknown-linux-gnu",
Architecture::AArch64 => "aarch64-unknown-linux-gnu", Architecture::AArch64 => "aarch64-unknown-linux-gnu",
@ -183,6 +184,7 @@ fn codegen_bindings(opts: &Options) -> Result<(), anyhow::Error> {
// Set the sysroot. This is needed to ensure that the correct arch // Set the sysroot. This is needed to ensure that the correct arch
// specific headers are imported. // specific headers are imported.
let sysroot = match arch { let sysroot = match arch {
Architecture::Mips => &opts.mips_sysroot,
Architecture::X86_64 => &opts.x86_64_sysroot, Architecture::X86_64 => &opts.x86_64_sysroot,
Architecture::ARMv7 => &opts.armv7_sysroot, Architecture::ARMv7 => &opts.armv7_sysroot,
Architecture::AArch64 => &opts.aarch64_sysroot, Architecture::AArch64 => &opts.aarch64_sysroot,

@ -71,6 +71,7 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
// 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 = match arch {
Architecture::Mips => "mips-unknown-linux-gnu",
Architecture::X86_64 => "x86_64-unknown-linux-gnu", Architecture::X86_64 => "x86_64-unknown-linux-gnu",
Architecture::ARMv7 => "armv7-unknown-linux-gnu", Architecture::ARMv7 => "armv7-unknown-linux-gnu",
Architecture::AArch64 => "aarch64-unknown-linux-gnu", Architecture::AArch64 => "aarch64-unknown-linux-gnu",
@ -81,6 +82,7 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
// Set the sysroot. This is needed to ensure that the correct arch // Set the sysroot. This is needed to ensure that the correct arch
// specific headers are imported. // specific headers are imported.
let sysroot = match arch { let sysroot = match arch {
Architecture::Mips => &opts.mips_sysroot,
Architecture::X86_64 => &opts.x86_64_sysroot, Architecture::X86_64 => &opts.x86_64_sysroot,
Architecture::ARMv7 => &opts.armv7_sysroot, Architecture::ARMv7 => &opts.armv7_sysroot,
Architecture::AArch64 => &opts.aarch64_sysroot, Architecture::AArch64 => &opts.aarch64_sysroot,
@ -94,6 +96,7 @@ pub fn codegen(opts: &Options) -> Result<(), anyhow::Error> {
.to_string(); .to_string();
let mut tree = parse_str::<syn::File>(&bindings).unwrap(); let mut tree = parse_str::<syn::File>(&bindings).unwrap();
let (indexes, helpers) = extract_helpers(&tree.items); let (indexes, helpers) = extract_helpers(&tree.items);
let helpers = expand_helpers(&helpers); let helpers = expand_helpers(&helpers);
for index in indexes { for index in indexes {

@ -7,6 +7,7 @@ use std::path::PathBuf;
use clap::Parser; use clap::Parser;
const SUPPORTED_ARCHS: &[Architecture] = &[ const SUPPORTED_ARCHS: &[Architecture] = &[
Architecture::Mips,
Architecture::X86_64, Architecture::X86_64,
Architecture::ARMv7, Architecture::ARMv7,
Architecture::AArch64, Architecture::AArch64,
@ -19,6 +20,7 @@ pub enum Architecture {
ARMv7, ARMv7,
AArch64, AArch64,
RISCV64, RISCV64,
Mips,
} }
impl Architecture { impl Architecture {
@ -32,6 +34,7 @@ impl std::str::FromStr for Architecture {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s { Ok(match s {
"mips" => Architecture::Mips,
"x86_64" => Architecture::X86_64, "x86_64" => Architecture::X86_64,
"armv7" => Architecture::ARMv7, "armv7" => Architecture::ARMv7,
"aarch64" => Architecture::AArch64, "aarch64" => Architecture::AArch64,
@ -44,6 +47,7 @@ impl std::str::FromStr for Architecture {
impl std::fmt::Display for Architecture { impl std::fmt::Display for Architecture {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self { f.write_str(match self {
Architecture::Mips => "mips",
Architecture::X86_64 => "x86_64", Architecture::X86_64 => "x86_64",
Architecture::ARMv7 => "armv7", Architecture::ARMv7 => "armv7",
Architecture::AArch64 => "aarch64", Architecture::AArch64 => "aarch64",
@ -71,6 +75,9 @@ pub struct Options {
#[arg(long, default_value = "/usr/riscv64-linux-gnu/include", action)] #[arg(long, default_value = "/usr/riscv64-linux-gnu/include", action)]
riscv64_sysroot: PathBuf, riscv64_sysroot: PathBuf,
#[arg(long, default_value = "/usr/mips-linux-gnu/include", action)]
mips_sysroot: PathBuf,
#[command(subcommand)] #[command(subcommand)]
command: Option<Command>, command: Option<Command>,
} }

Loading…
Cancel
Save