-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up builds.rs, separate ffi impls and stub tests
- Loading branch information
1 parent
4fb2e1a
commit 464d3d8
Showing
3 changed files
with
54 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
use std::env; | ||
use std::path::PathBuf; | ||
|
||
fn main() { | ||
let pkg_name = env::var("CARGO_PKG_NAME").unwrap(); | ||
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()); | ||
let lib_path = &manifest_path | ||
.parent() | ||
.unwrap() | ||
.parent() | ||
.unwrap() | ||
.join("src"); | ||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let pkg_name = env::var("CARGO_PKG_NAME")?; | ||
let manifest_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?); | ||
|
||
cxx_build::bridge("src/lib.rs") | ||
.include(lib_path) | ||
let cpp_src_path = &manifest_path.parent() | ||
.and_then(|x| x.parent()) | ||
.and_then(|x| Some(x.join("src"))); | ||
|
||
let cpp_src_path = match cpp_src_path.as_ref() { | ||
Some(r) => Ok(r), | ||
None => Err("path err") | ||
}?; | ||
|
||
let ffi_rs_src_path = &manifest_path.join("src/bridge.rs"); | ||
let ffi_exports_h_path = &cpp_src_path.join("ffi/ffiexports.h"); | ||
|
||
cxx_build::bridge(ffi_rs_src_path) | ||
.include(&cpp_src_path) | ||
.cpp_link_stdlib("stdc++") | ||
.flag_if_supported("-std=c++17") | ||
.flag_if_supported("-Wno-unused-parameter") | ||
.compile(pkg_name.as_str()); | ||
|
||
println!( | ||
"cargo:rerun-if-changed={}/lib.rs", | ||
lib_path.to_str().unwrap() | ||
); | ||
println!( | ||
"cargo:rerun-if-changed={}/ffi/ffiexports.h", | ||
lib_path.to_str().unwrap() | ||
); | ||
println!("cargo:rerun-if-changed={}", ffi_rs_src_path.to_string_lossy()); | ||
println!("cargo:rerun-if-changed={}", &ffi_exports_h_path.to_string_lossy()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#[cxx::bridge] | ||
pub mod ffi { | ||
unsafe extern "C++" { | ||
include!("ffi/ffiexports.h"); | ||
|
||
fn getChainId() -> u64; | ||
fn isMining() -> bool; | ||
fn publishEthTransaction(data: Vec<u8>) -> bool; | ||
fn getAccounts() -> Vec<String>; | ||
fn getDatadir() -> String; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters