- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
          Support for cfg attributes in host functions definitions
          #14189
        
      Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A test with a feature that doesn't exist and thus, doesn't gets activated would be nice. (There is a testing crate for this stuff)
| 
           Required by #13974  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to have the example of usage in: primitives/runtime-interface/README.md.
| method.sig.ident, | ||
| ); | ||
| let return_value = &method.sig.output; | ||
| let cfg_attrs = method.attrs.iter().filter(|a| a.path().is_ident("cfg")); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this filtering is repeated multiple times, maybe it is worth putting it to some shared util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
        
          
                primitives/runtime-interface/proc-macro/src/runtime_interface/host_function_interface.rs
              
                Outdated
          
            Show resolved
            Hide resolved
        
      
          
 Please add it to the crate docs as well (or only the crate docs), but never the README exclusively. Most of these readmes were generated from the crate docs.  | 
    
Co-authored-by: Koute <[email protected]>
* Support cfg attribute in host functions definitions * Added test to check feature gated methods are not included * Versioned conditional compiled host function are forbidden * Improve runtime-interface macro docs * Fix doc * Apply review suggestion Co-authored-by: Koute <[email protected]> * Better error message * Rust fmt * More refinements to the docs --------- Co-authored-by: Koute <[email protected]>
…h#14189) * Support cfg attribute in host functions definitions * Added test to check feature gated methods are not included * Versioned conditional compiled host function are forbidden * Improve runtime-interface macro docs * Fix doc * Apply review suggestion Co-authored-by: Koute <[email protected]> * Better error message * Rust fmt * More refinements to the docs --------- Co-authored-by: Koute <[email protected]>
As per title...
If I'm not terribly wrong, before this PR was not possible to define a host function gated by some
#[cfg(feature = ...)]. A similar technique has been used byframe.Usage scenario: we require to early integrate and experiment with an host function that is still in "beta" phase as this one:
https://github.com/davxy/substrate/blob/5d2e2bbf17bb7f375d6d24bfe696be2c6e54aa2a/primitives/io/src/lib.rs#L1146-L1159
I'm not a rust macro wizard 🧙 so please carefully check