From 58906e218be8fc90c95974d978f7c9f997b29c5a Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Wed, 13 Mar 2019 13:41:04 +0100 Subject: [PATCH] Add basic Rust bindings --- .bumpversion.cfg | 3 +++ bindings/rust/.gitignore | 3 +++ bindings/rust/Cargo.toml | 12 ++++++++++++ bindings/rust/build.rs | 25 +++++++++++++++++++++++++ bindings/rust/evmc.h | 1 + bindings/rust/src/lib.rs | 5 +++++ 6 files changed, 49 insertions(+) create mode 100644 bindings/rust/.gitignore create mode 100644 bindings/rust/Cargo.toml create mode 100644 bindings/rust/build.rs create mode 120000 bindings/rust/evmc.h create mode 100644 bindings/rust/src/lib.rs diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 7618cbc..65d6585 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -24,3 +24,6 @@ serialize = {major} search = EVMC_ABI_VERSION = {current_version} replace = EVMC_ABI_VERSION = {new_version} +[bumpversion:file:bindings/rust/Cargo.toml] +search = version = \"{current_version}\" + diff --git a/bindings/rust/.gitignore b/bindings/rust/.gitignore new file mode 100644 index 0000000..84c47ed --- /dev/null +++ b/bindings/rust/.gitignore @@ -0,0 +1,3 @@ +/target +**/*.rs.bk +/Cargo.lock diff --git a/bindings/rust/Cargo.toml b/bindings/rust/Cargo.toml new file mode 100644 index 0000000..a5daa8e --- /dev/null +++ b/bindings/rust/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "evmc-sys" +version = "6.2.0-dev" +authors = ["Alex Beregszaszi "] +license = "Apache-2.0" +repository = "https://github.com/ethereum/evmc" +description = "Bindings to EVMC (low-level)" +categories = ["external-ffi-bindings"] +edition = "2018" + +[build-dependencies] +bindgen = "0.48.0" diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs new file mode 100644 index 0000000..3591589 --- /dev/null +++ b/bindings/rust/build.rs @@ -0,0 +1,25 @@ +extern crate bindgen; + +use std::env; +use std::path::PathBuf; + +fn gen_bindings() { + let bindings = bindgen::Builder::default() + .header("evmc.h") + // See https://github.com/rust-lang-nursery/rust-bindgen/issues/947 + .trust_clang_mangling(false) + .generate_comments(true) + // https://github.com/rust-lang-nursery/rust-bindgen/issues/947#issuecomment-327100002 + .layout_tests(false) + .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!"); +} + +fn main() { + gen_bindings(); +} diff --git a/bindings/rust/evmc.h b/bindings/rust/evmc.h new file mode 120000 index 0000000..32ffe53 --- /dev/null +++ b/bindings/rust/evmc.h @@ -0,0 +1 @@ +../../include/evmc/evmc.h \ No newline at end of file diff --git a/bindings/rust/src/lib.rs b/bindings/rust/src/lib.rs new file mode 100644 index 0000000..a38a13a --- /dev/null +++ b/bindings/rust/src/lib.rs @@ -0,0 +1,5 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] + +include!(concat!(env!("OUT_DIR"), "/bindings.rs"));