Skip to content

Commit

Permalink
evm: Enable C++ FFI (#1912)
Browse files Browse the repository at this point in the history
* Enable C++ FFI

* Rename evm_ffi to ffi_exports

* Update Makefile.am
  • Loading branch information
shohamc1 authored Apr 14, 2023
1 parent bde8e5c commit b63a29e
Showing 6 changed files with 42 additions and 28 deletions.
27 changes: 27 additions & 0 deletions lib/ain-cpp-imports/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::env;
use std::path::PathBuf;

fn main() {
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
let lib_path = &manifest_path
.parent()
.unwrap()
.parent()
.unwrap()
.join("src");

cxx_build::bridge("src/lib.rs")
.include(lib_path)
.flag_if_supported("-std=c++17")
.flag_if_supported("-Wno-unused-parameter")
.compile("ain-evm-cpp-ffi");

println!(
"cargo:rerun-if-changed={}/lib.rs",
lib_path.to_str().unwrap()
);
println!(
"cargo:rerun-if-changed={}/masternodes/ffi_exports.h",
lib_path.to_str().unwrap()
);
}
13 changes: 0 additions & 13 deletions lib/ain-cpp-imports/build.rs.disabled

This file was deleted.

24 changes: 12 additions & 12 deletions lib/ain-cpp-imports/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use std::error::Error;

// #[cxx::bridge]
// mod ffi {
// unsafe extern "C++" {
// include!("masternodes/evm_ffi.h");
#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
include!("masternodes/ffi_exports.h");

// fn getChainId() -> u64;
// fn isMining() -> bool;
// }
// }
fn getChainId() -> u64;
fn isMining() -> bool;
}
}

pub fn get_chain_id() -> Result<u64, Box<dyn Error>> {
// let chain_id = ffi::getChainId();
Ok(0)
let chain_id = ffi::getChainId();
Ok(chain_id)
}

pub fn is_mining() -> Result<bool, Box<dyn Error>> {
// let is_mining = ffi::isMining();
Ok(true)
let is_mining = ffi::isMining();
Ok(is_mining)
}
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ DEFI_CORE_H = \
masternodes/communityaccounttypes.h \
masternodes/errors.h \
masternodes/evm.h \
masternodes/evm_ffi.h \
masternodes/ffi_exports.h \
masternodes/factory.h \
masternodes/govvariables/attributes.h \
masternodes/govvariables/icx_takerfee_per_btc.h \
@@ -396,7 +396,7 @@ libdefi_server_a_SOURCES = \
masternodes/accountshistory.cpp \
masternodes/anchors.cpp \
masternodes/auctionhistory.cpp \
masternodes/evm_ffi.cpp \
masternodes/ffi_exports.cpp \
masternodes/govvariables/attributes.cpp \
masternodes/govvariables/icx_takerfee_per_btc.cpp \
masternodes/govvariables/loan_daily_reward.cpp \
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <masternodes/evm_ffi.h>
#include <masternodes/ffi_exports.h>
#include <util/system.h>

uint64_t getChainId() {
File renamed without changes.

0 comments on commit b63a29e

Please sign in to comment.