Skip to content

Commit

Permalink
Merge pull request #201 from ethereum/evmc-rust
Browse files Browse the repository at this point in the history
Add basic Rust bindings
  • Loading branch information
chfast authored Mar 13, 2019
2 parents f6b1059 + 0cffdbb commit 139985d
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ serialize = {major}
search = EVMC_ABI_VERSION = {current_version}
replace = EVMC_ABI_VERSION = {new_version}

[bumpversion:file:bindings/rust/evmc-sys/Cargo.toml]
search = version = \"{current_version}\"

[bumpversion:file:bindings/rust/evmc-vm/Cargo.toml]
search = version = \"{current_version}\"

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/build
/cmake-build-*
/.idea
Cargo.lock
/target
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]
members = [
"bindings/rust/evmc-sys",
"bindings/rust/evmc-vm",
]
3 changes: 3 additions & 0 deletions bindings/rust/evmc-sys/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
/Cargo.lock
12 changes: 12 additions & 0 deletions bindings/rust/evmc-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "evmc-sys"
version = "6.2.0-dev"
authors = ["Alex Beregszaszi <[email protected]>"]
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"
25 changes: 25 additions & 0 deletions bindings/rust/evmc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions bindings/rust/evmc-sys/evmc.h
5 changes: 5 additions & 0 deletions bindings/rust/evmc-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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"));
3 changes: 3 additions & 0 deletions bindings/rust/evmc-vm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
**/*.rs.bk
/Cargo.lock
11 changes: 11 additions & 0 deletions bindings/rust/evmc-vm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "evmc-vm"
version = "6.2.0-dev"
authors = ["Alex Beregszaszi <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/ethereum/evmc"
description = "Bindings to EVMC (VM specific)"
edition = "2018"

[dependencies]
evmc-sys = { path = "../evmc-sys" }
7 changes: 7 additions & 0 deletions bindings/rust/evmc-vm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub extern crate evmc_sys;
pub use evmc_sys as ffi;

// TODO: Add helpers for host interface
// TODO: Add convenient helpers for evmc_result
// TODO: Add convenient helpers for evmc_execute
// TODO: Add a derive macro here for creating evmc_create
24 changes: 24 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,29 @@ jobs:
- image: circleci/golang:1.11
steps: *bindings-go-steps

bindings-rust:
docker:
- image: rust:1
steps:
- checkout
- run:
name: Update environment
command: |
apt update
apt -y install libclang-dev clang
rustup component add rustfmt
rustup update
- run:
name: Check formatting
command: |
rustfmt --version
cargo fmt --all -- --check
- run:
name: Build
command: cargo build
- run:
name: Test
command: cargo test

workflows:
version: 2
Expand All @@ -173,6 +196,7 @@ workflows:
- bindings-go-1.11
- bindings-go-1.10
- bindings-go-1.9
- bindings-rust
- test-docs
- upload-docs:
requires:
Expand Down

0 comments on commit 139985d

Please sign in to comment.