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 basic Rust bindings #201

Merged
merged 5 commits into from
Mar 13, 2019
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
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]
axic marked this conversation as resolved.
Show resolved Hide resolved
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
axic marked this conversation as resolved.
Show resolved Hide resolved
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"
axic marked this conversation as resolved.
Show resolved Hide resolved

[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"
axic marked this conversation as resolved.
Show resolved Hide resolved

[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