summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--Cargo.toml10
-rw-r--r--build.rs41
-rw-r--r--src/lib.rs22
-rw-r--r--wrapper.h1
5 files changed, 77 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6aa1064
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
1/target/
2**/*.rs.bk
3Cargo.lock
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644
index 0000000..8477c61
--- /dev/null
+++ b/Cargo.toml
@@ -0,0 +1,10 @@
1[package]
2name = "rust"
3version = "0.1.0"
4authors = ["Andy Williams <andy@andywilliams.me>"]
5build = "build.rs"
6
7[dependencies]
8
9[build-dependencies]
10bindgen = "0.20.0"
diff --git a/build.rs b/build.rs
new file mode 100644
index 0000000..0ac75d2
--- /dev/null
+++ b/build.rs
@@ -0,0 +1,41 @@
1extern crate bindgen;
2
3use std::env;
4use std::path::PathBuf;
5
6fn main() {
7 // Tell cargo to tell rustc to link the system bzip2
8 // shared library.
9 println!("cargo:rustc-link-lib=eina");
10 println!("cargo:rustc-link-search=native=/opt/efler/lib");
11
12 // The bindgen::Builder is the main entry point
13 // to bindgen, and lets you build up options for
14 // the resulting bindings.
15 let bindings = bindgen::Builder::default()
16 // Do not generate unstable Rust code that
17 // requires a nightly rustc and enabling
18 // unstable features.
19 .no_unstable_rust()
20 // The input header we would like to generate
21 // bindings for.
22 .header("wrapper.h")
23
24 .clang_arg("-I/opt/efler/include/efl-1")
25 .clang_arg("-I/opt/efler/include/efl-1/efl")
26 .clang_arg("-I/opt/efler/include/eo-1")
27 .clang_arg("-I/opt/efler/include/eo-1/eo")
28 .clang_arg("-I/opt/efler/include/eina-1")
29 .clang_arg("-I/opt/efler/include/eina-1/eina")
30
31 // Finish the builder and generate the bindings.
32 .generate()
33 // Unwrap the Result and panic on failure.
34 .expect("Unable to generate bindings");
35
36 // Write the bindings to the $OUT_DIR/bindings.rs file.
37 let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
38 bindings
39 .write_to_file(out_path.join("bindings.rs"))
40 .expect("Couldn't write bindings!");
41}
diff --git a/src/lib.rs b/src/lib.rs
new file mode 100644
index 0000000..e6333fe
--- /dev/null
+++ b/src/lib.rs
@@ -0,0 +1,22 @@
1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6
7#[cfg(test)]
8mod tests {
9 use super::*;
10 use std::ffi::CString;
11
12 #[test]
13 fn init_lib_eina() {
14 let cstr = CString::new("Hello World").unwrap();
15
16 unsafe {
17 let status = eina_init();
18 let share = eina_stringshare_add(cstr.as_ptr());
19 eina_shutdown();
20 }
21 }
22}
diff --git a/wrapper.h b/wrapper.h
new file mode 100644
index 0000000..6184bb5
--- /dev/null
+++ b/wrapper.h
@@ -0,0 +1 @@
#include <Efl.h>