Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
make it compile without doc attr passed to macro
  • Loading branch information
agryaznov committed Jan 3, 2023
commit ce9031b18f94c6527cf642180e3988f093485cd1
38 changes: 22 additions & 16 deletions frame/contracts/proc-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,10 @@ fn expand_docs(def: &mut EnvDef) -> TokenStream2 {
});

let module = Ident::new(m, Span::call_site());
let module_doc = format!("Documentation of the API available to contracts by importing `{}` module.", module);
let module_doc = format!(
"Documentation of the API available to contracts by importing `{}` module.",
module
);

quote! {
#[doc = #module_doc]
Expand All @@ -435,17 +438,7 @@ fn expand_docs(def: &mut EnvDef) -> TokenStream2 {
}
});
quote! {
pub use docs as api_doc;
/// Contains the documentation of the API available to contracts.
///
/// This module is not meant to be used by code. It is meant to be consumed by humans through rustdoc.
///
/// Every function described in this module's sub module's traits uses this sub module's identifier
/// as its imported module name. The identifier of the function is the function's imported name.
/// According to the [WASM spec of imports](https://webassembly.github.io/spec/core/text/modules.html#text-import).
pub mod docs {
#( #docs )*
}
}
}

Expand All @@ -460,7 +453,20 @@ fn expand_env(def: &mut EnvDef, docs: bool) -> TokenStream2 {
quote! {
pub struct Env;
#impls
#docs
pub use docs as api_doc;
/// Contains the documentation of the API available to contracts.
///
/// In order to generate this documentation, pass `doc` attribute to the [`#[define_env]`][`macro@define_env`] macro:
/// `#[define_env(doc)]`, and then run `cargo doc --no-deps`.
///
/// This module is not meant to be used by any code. Rather, it is meant to be consumed by humans through rustdoc.
///
/// Every function described in this module's sub module's traits uses this sub module's identifier
/// as its imported module name. The identifier of the function is the function's imported name.
/// According to the [WASM spec of imports](https://webassembly.github.io/spec/core/text/modules.html#text-import).
pub mod docs {
#docs
}
}
}

Expand Down Expand Up @@ -651,14 +657,14 @@ fn expand_functions(
/// # Generating Documentation
///
/// Passing `doc` attribute to the macro (like `#[define_env(doc)]`) will make it also expand
/// additional `pallet_contracts::wasm::runtime::seal0`, `pallet_contracts::wasm::runtime::seal1`,
/// `...` modules each having its `Doc` trait containing methods holding documentation for every
/// defined host function.
/// additional `pallet_contracts::api_doc::seal0`, `pallet_contracts::api_doc::seal1`,
/// `...` modules each having its `Api` trait containing functions holding documentation for every
/// host function defined by the macro.
///
/// To build up these docs, run:
///
/// ```nocompile
/// cargo doc --no-deps --document-private-items
/// cargo doc --no-deps
/// ```
#[proc_macro_attribute]
pub fn define_env(attr: TokenStream, item: TokenStream) -> TokenStream {
Expand Down
3 changes: 1 addition & 2 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ mod runtime;
pub use crate::wasm::code_cache::reinstrument;
pub use crate::wasm::{
prepare::TryInstantiate,
runtime::{CallFlags, Environment, ReturnCode, Runtime, RuntimeCosts},
runtime::{api_doc, CallFlags, Environment, ReturnCode, Runtime, RuntimeCosts},
};
pub use crate::wasm::runtime::api_doc;

use crate::{
exec::{ExecResult, Executable, ExportedFunction, Ext},
Expand Down
2 changes: 1 addition & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
// Any input that leads to a out of bound error (reading or writing) or failing to decode
// data passed to the supervisor will lead to a trap. This is not documented explicitly
// for every function.
#[define_env(doc)]
#[define_env]
pub mod env {
/// Account for used gas. Traps if gas used is greater than gas limit.
///
Expand Down