Skip to content

Commit

Permalink
chore(xtask): Add mips to codegen
Browse files Browse the repository at this point in the history
This will generate bindings for mips the next time that the codegen job
is run.

Signed-off-by: Ishan Jain <[email protected]>
Co-authored-by: Dave Tucker <[email protected]>
  • Loading branch information
ishanjain28 and dave-tucker committed Jan 31, 2025
1 parent 0429ed2 commit 91fb730
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion aya-tool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
fs::File,
fs::{create_dir_all, File},
io::{self, Write},
path::Path,
};
Expand All @@ -11,6 +11,13 @@ pub mod rustfmt;
pub use generate::{generate, InputFile};

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)?;
file.write_all(code.as_bytes())
}
Expand Down
3 changes: 3 additions & 0 deletions xtask/src/codegen/aya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh
riscv64_sysroot,
powerpc64_sysroot,
s390x_sysroot,
mips_sysroot,
} = opts;
let types = [
// BPF
Expand Down Expand Up @@ -191,6 +192,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh
Architecture::RISCV64 => "riscv64-unknown-linux-gnu",
Architecture::PowerPC64 => "powerpc64le-unknown-linux-gnu",
Architecture::S390X => "s390x-unknown-linux-gnu",
Architecture::Mips => "mips-unknown-linux-gnu",
};
bindgen = bindgen.clang_args(&["-target", target]);

Expand All @@ -203,6 +205,7 @@ fn codegen_bindings(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyh
Architecture::RISCV64 => riscv64_sysroot,
Architecture::PowerPC64 => powerpc64_sysroot,
Architecture::S390X => s390x_sysroot,
Architecture::Mips => mips_sysroot,
};
bindgen = bindgen.clang_args(&["-I", &*sysroot.to_string_lossy()]);

Expand Down
4 changes: 4 additions & 0 deletions xtask/src/codegen/aya_ebpf_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
riscv64_sysroot,
powerpc64_sysroot,
s390x_sysroot,
mips_sysroot,
} = opts;

let dir = PathBuf::from("ebpf/aya-ebpf-bindings");
Expand Down Expand Up @@ -88,6 +89,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
Architecture::RISCV64 => "riscv64-unknown-linux-gnu",
Architecture::PowerPC64 => "powerpc64le-unknown-linux-gnu",
Architecture::S390X => "s390x-unknown-linux-gnu",
Architecture::Mips => "mips-unknown-linux-gnu",
};
bindgen = bindgen.clang_args(&["-target", target]);

Expand All @@ -100,6 +102,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
Architecture::RISCV64 => riscv64_sysroot,
Architecture::PowerPC64 => powerpc64_sysroot,
Architecture::S390X => s390x_sysroot,
Architecture::Mips => mips_sysroot,
};
bindgen = bindgen.clang_args(&["-I", &*sysroot.to_string_lossy()]);

Expand All @@ -109,6 +112,7 @@ pub fn codegen(opts: &SysrootOptions, libbpf_dir: &Path) -> Result<(), anyhow::E
.to_string();

let mut tree = parse_str::<syn::File>(&bindings).unwrap();

let (indexes, helpers) = extract_helpers(&tree.items);
let helpers = expand_helpers(&helpers);
for index in indexes {
Expand Down
7 changes: 7 additions & 0 deletions xtask/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
use clap::Parser;

const SUPPORTED_ARCHS: &[Architecture] = &[
Architecture::Mips,
Architecture::X86_64,
Architecture::ARMv7,
Architecture::AArch64,
Expand All @@ -23,6 +24,7 @@ pub enum Architecture {
RISCV64,
PowerPC64,
S390X,
Mips,
}

impl Architecture {
Expand All @@ -36,6 +38,7 @@ impl std::str::FromStr for Architecture {

fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(match s {
"mips" => Architecture::Mips,
"x86_64" => Architecture::X86_64,
"armv7" => Architecture::ARMv7,
"aarch64" => Architecture::AArch64,
Expand All @@ -50,6 +53,7 @@ impl std::str::FromStr for Architecture {
impl std::fmt::Display for Architecture {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Architecture::Mips => "mips",
Architecture::X86_64 => "x86_64",
Architecture::ARMv7 => "armv7",
Architecture::AArch64 => "aarch64",
Expand Down Expand Up @@ -81,6 +85,9 @@ pub struct SysrootOptions {

#[arg(long, default_value = "/usr/s390x-linux-gnu/include", action)]
s390x_sysroot: PathBuf,

#[arg(long, default_value = "/usr/mips-linux-gnu/include", action)]
mips_sysroot: PathBuf,
}

#[derive(Parser)]
Expand Down

0 comments on commit 91fb730

Please sign in to comment.