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

evm: Enable C++ FFI #1912

Merged
merged 3 commits into from
Apr 14, 2023
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
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");
prasannavl marked this conversation as resolved.
Show resolved Hide resolved

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
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
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() {
Expand Down
File renamed without changes.