Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unikraft system binding generation #2

Merged
merged 1 commit into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions unikraft-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "unikraft-sys"
version = "0.1.0"
edition = "2021"

[dependencies]

[build-dependencies]
bindgen = {version= "0.59", default-features = false}
42 changes: 42 additions & 0 deletions unikraft-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
extern crate bindgen;

use std::env;
use std::path::PathBuf;

fn main() {
// Tell cargo to invalidate the built crate whenever the wrapper changes
println!("cargo:rerun-if-changed=wrapper.h");

println!("current dir:{}", env::current_dir().unwrap().display());
let uk_includes = env::var("UK_CINCLUDES").unwrap();
println!(
"UK_CINCLUDES:{}",
env::var("UK_CINCLUDES")
.expect("Env Var UK_CINCLUDES is not present, but necessary for binding generation")
);

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.use_core()
.ctypes_prefix("ffi")
.header("wrapper.h")
.clang_args(uk_includes.split(' '))
.clang_arg("-nobuiltininc")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");

// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
37 changes: 37 additions & 0 deletions unikraft-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#![no_std]
#![allow(unused_unsafe)]
#![allow(non_camel_case_types)]
pub mod sys;

pub use sys::*;

#[cfg(any(target_arch = "x86_64", target_arch = "arm64"))]
pub mod ffi {
pub type c_char = i8;
pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_long = i64;
pub type c_ulong = u64;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type c_void = usize;
}
#[cfg(any(target_arch = "x86", target_arch = "arm"))]
pub mod ffi {
pub type c_char = i8;
pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
pub type c_ushort = u16;
pub type c_int = i32;
pub type c_uint = u32;
pub type c_long = i32;
pub type c_ulong = u32;
pub type c_longlong = i64;
pub type c_ulonglong = u64;
pub type c_void = usize;
}
6 changes: 6 additions & 0 deletions unikraft-sys/src/sys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
pub use crate::ffi;

include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
15 changes: 15 additions & 0 deletions unikraft-sys/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define NULL 0

#include <uk/alloc.h>
#include <uk/alloc_impl.h>
#include <stdlib.h>
#include <string.h>

#include <uk/print.h>
#include <uk/plat/console.h>
#include <uk/init.h>

#include <uk/list.h>
#include <vfscore/dentry.h>
#include <vfscore/vnode.h>
#include <uk/mutex.h>