This repository was archived by the owner on Apr 8, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
bindings/rust/evmc-loader Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,5 +4,6 @@ members = [
44 " bindings/rust/evmc-vm" ,
55 " bindings/rust/evmc-declare" ,
66 " bindings/rust/evmc-declare-tests" ,
7+ " bindings/rust/evmc-loader" ,
78 " examples/example-rust-vm"
89]
Original file line number Diff line number Diff line change 1+ /target
2+ ** /* .rs.bk
3+ /Cargo.lock
Original file line number Diff line number Diff line change 1+ # EVMC: Ethereum Client-VM Connector API.
2+ # Copyright 2019 The EVMC Authors.
3+ # Licensed under the Apache License, Version 2.0.
4+
5+ [package ]
6+ name = " evmc-loader"
7+ version = " 10.0.0-alpha.5"
8+ authors = [" Alex Beregszaszi <alex@rtfs.hu>" ]
9+ license = " Apache-2.0"
10+ repository = " https://github.com/ethereum/evmc"
11+ description = " Bindings to EVMC (Loader bindings)"
12+ edition = " 2018"
13+
14+ [build-dependencies ]
15+ bindgen = " 0.59"
16+ cmake = " 0.1"
Original file line number Diff line number Diff line change 1+ # evmc-vm
2+
3+ This is a Rust interface to [ EVMC] ( https://github.com/ethereum/evmc ) .
4+
5+ This crate contains the implementation helpers for the VM-side.
Original file line number Diff line number Diff line change 1+ // EVMC: Ethereum Client-VM Connector API.
2+ // Copyright 2019 The EVMC Authors.
3+ // Licensed under the Apache License, Version 2.0.
4+
5+ extern crate bindgen;
6+ extern crate cmake;
7+
8+ use cmake:: Config ;
9+ use std:: env;
10+ use std:: path:: { Path , PathBuf } ;
11+
12+ fn gen_bindings ( ) {
13+ let bindings = bindgen:: Builder :: default ( )
14+ . header ( "loader.h" )
15+ . generate_comments ( false )
16+ // do not generate an empty enum for EVMC_ABI_VERSION
17+ . constified_enum ( "" )
18+ // generate Rust enums for each evmc enum
19+ . rustified_enum ( "*" )
20+ // force deriving the Hash trait on basic types (address, bytes32)
21+ . derive_hash ( true )
22+ // force deriving the PratialEq trait on basic types (address, bytes32)
23+ . derive_partialeq ( true )
24+ . allowlist_type ( "evmc_.*" )
25+ . allowlist_function ( "evmc_.*" )
26+ // TODO: consider removing this
27+ . size_t_is_usize ( true )
28+ . generate ( )
29+ . expect ( "Unable to generate bindings" ) ;
30+
31+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
32+ bindings
33+ . write_to_file ( out_path. join ( "bindings.rs" ) )
34+ . expect ( "Couldn't write bindings!" ) ;
35+ }
36+
37+ fn gen_loader ( ) {
38+ let build_dir = Config :: new ( "../../../" ) . build ( ) ;
39+ let loader_path = Path :: new ( & build_dir) . join ( "build/lib/loader" ) ;
40+ println ! ( "cargo:rustc-link-search=native={}" , loader_path. display( ) ) ;
41+ println ! ( "cargo:rustc-link-lib=static=evmc-loader" ) ;
42+ }
43+
44+ fn main ( ) {
45+ gen_loader ( ) ;
46+ gen_bindings ( ) ;
47+ }
Original file line number Diff line number Diff line change 1+ ../../../include /evmc /loader .h
Original file line number Diff line number Diff line change 1+ // EVMC: Ethereum Client-VM Connector API.
2+ // Copyright 2019 The EVMC Authors.
3+ // Licensed under the Apache License, Version 2.0.
4+
5+ mod sys;
6+
7+ #[ cfg( test) ]
8+ mod tests {
9+ use std:: ffi:: CString ;
10+ use std:: os:: raw:: c_char;
11+
12+ use super :: * ;
13+
14+ #[ test]
15+ fn load_fail ( ) {
16+ let c_str = CString :: new ( "test.so" ) . unwrap ( ) ;
17+ unsafe {
18+ let mut error_code = sys:: evmc_loader_error_code:: EVMC_LOADER_UNSPECIFIED_ERROR ;
19+ let instance = sys:: evmc_load_and_create ( c_str. as_ptr ( ) as * const c_char , & mut error_code) ;
20+ println ! ( "{:?}" , error_code) ;
21+ }
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ // EVMC: Ethereum Client-VM Connector API.
2+ // Copyright 2019 The EVMC Authors.
3+ // Licensed under the Apache License, Version 2.0.
4+
5+ #![ allow( non_upper_case_globals) ]
6+ #![ allow( non_camel_case_types) ]
7+ #![ allow( non_snake_case) ]
8+
9+ include ! ( concat!( env!( "OUT_DIR" ) , "/bindings.rs" ) ) ;
10+
11+ #[ cfg( test) ]
12+ mod tests {
13+ use std:: ffi:: CString ;
14+ use std:: os:: raw:: c_char;
15+
16+ use super :: * ;
17+
18+ #[ test]
19+ fn load_fail ( ) {
20+ let c_str = CString :: new ( "test.so" ) . unwrap ( ) ;
21+ unsafe {
22+ let mut error_code = evmc_loader_error_code:: EVMC_LOADER_UNSPECIFIED_ERROR ;
23+ let instance = evmc_load_and_create ( c_str. as_ptr ( ) as * const c_char , & mut error_code) ;
24+ println ! ( "{:?}" , error_code) ;
25+ }
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments