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

DRAFT: Add Wasmcov To Code Generation Pipeline #1131

Closed
wants to merge 5 commits into from
Closed
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
2 changes: 2 additions & 0 deletions near-sdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ prettyplease = { version = "0.2.15" }


[features]
wasmcov = []
abi = []
__abi-embed = ["abi"]
__abi-generate = ["abi"]

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ impl ImplItemMethodInfo {
ReturnKind::HandlesResult { .. } => self.result_return_body_tokens(),
};

let wasmcov = self.wasmcov_tokens();

quote! {
#non_bindgen_attrs
#[cfg(target_arch = "wasm32")]
Expand All @@ -45,6 +47,7 @@ impl ImplItemMethodInfo {
#callback_vec_deser
#state_check
#body
#wasmcov
}
}
}
Expand Down Expand Up @@ -247,6 +250,31 @@ impl ImplItemMethodInfo {
}
}

fn wasmcov_tokens(&self) -> TokenStream2 {
fn wasmcov() -> TokenStream2 {
quote! {
::near_sdk::env::log_str("wasmcov");

let mut coverage = vec![];
unsafe {
// Note that this function is not thread-safe! Use a lock if needed.
::near_sdk::minicov::capture_coverage(&mut coverage).unwrap();
};
let base64_string = ::near_sdk::base64::encode(coverage);
::near_sdk::env::log_str(&base64_string);
}
}

wasmcov()

// Passing feature to dependency of dependency doesn't seem to work
// if cfg!(feature = "wasmcov") {
// wasmcov()
// } else {
// quote! {}
// }
}

fn contract_ser_tokens(&self) -> TokenStream2 {
use MethodKind::*;

Expand Down
2 changes: 2 additions & 0 deletions near-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ path = "compilation_tests/all.rs"
required-features = ["abi", "unstable"]

[dependencies]
minicov = "0.3"
# Provide near_bidgen macros.
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down Expand Up @@ -66,6 +67,7 @@ default = ["wee_alloc", "unit-testing", "legacy", "abi"]
expensive-debug = []
unstable = []
legacy = []
wasmcov = ["near-sdk-macros/wasmcov"]
abi = ["borsh/unstable__schema", "near-abi", "schemars", "near-sdk-macros/abi", "near-account-id/abi", "near-gas/abi", "near-token/abi"]
unit-testing = ["near-vm-runner", "near-primitives-core", "near-primitives", "near-crypto", "near-parameters"]

Expand Down
2 changes: 2 additions & 0 deletions near-sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
pub use base64;
pub use borsh;
pub use bs58;
#[doc(hidden)]
pub use minicov;
#[cfg(feature = "abi")]
pub use schemars;
pub use serde;
Expand Down
Loading