Skip to content

Commit

Permalink
libsgxstep: Raw bindings for Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Danacus committed Feb 29, 2024
1 parent ce022db commit f54607f
Show file tree
Hide file tree
Showing 5 changed files with 425 additions and 0 deletions.
1 change: 1 addition & 0 deletions sgxstep-sys/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
target/
20 changes: 20 additions & 0 deletions sgxstep-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "sgxstep-sys"
version = "0.1.0"
edition = "2021"
links = "libsgxstep"
authors = ["Daan Vanoverloop", "Jo Van Bulck"]
license = "GPL-3.0"
repository = "https://github.com/jovanbulck/sgx-step/"

[features]
default = ["build"]
build = ["cc", "glob"]

[dependencies]

[build-dependencies]
cc = { version = "1.0", optional = true }
glob = { version = "0.3", optional = true }
bindgen = "0.69"

30 changes: 30 additions & 0 deletions sgxstep-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::{env, path::PathBuf};

fn main() {
#[cfg(feature = "build")]
{
cc::Build::new()
.files(
glob::glob("../libsgxstep/*.c")
.unwrap()
.filter_map(|e| e.ok()),
)
.cargo_metadata(true)
.compile("sgxstep");
}

let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!(
"-I{}",
env::var("LIBSGXSTEP").expect("missing LIBSGXSTEP environment variable")
))
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings");

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
Loading

0 comments on commit f54607f

Please sign in to comment.