-
Notifications
You must be signed in to change notification settings - Fork 432
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
Conditional compilation #1707
Conditional compilation #1707
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1707 +/- ##
==========================================
- Coverage 70.60% 70.53% -0.08%
==========================================
Files 205 205
Lines 6434 6483 +49
==========================================
+ Hits 4543 4573 +30
- Misses 1891 1910 +19
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
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.
LGTM
@@ -24,18 +24,14 @@ fn main() { | |||
use contract::Contract; | |||
use std::any::TypeId; | |||
|
|||
const ID: u32 = <Contract as ::ink::reflect::ContractDispatchableConstructors< | |||
{ <Contract as ::ink::reflect::ContractAmountDispatchables>::CONSTRUCTORS }, | |||
>>::IDS[0]; |
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.
We will need to document the breaking change that you can no longer access constructor/message info in this way by the index. But I doubt too many people are depending on that...
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.
Can you please open a separate issue for this? I guess this needs to be documented in release notes
Closes #1231
Summary
This PR introduces a native support for conditional compilation in ink! smart contracts
High level overview
It is now possible to attribute ink! elements with
#[cfg(...)]
macro attribute. You can use platform specific conditions or custom features specified inCargo.toml
file. (See integration-tests/condtional-compilation for example).Important notice: Attributing event fields is not allowed.
Low level overview
IR structures have stayed the same, no significant changes there: just added a helper function to retrieve a list of all
cfg
attributes from the element.Codegen has undergone some changes. Structures
ContractAmountDispatchables
,ContractDispatchableMessages
andContractDispatchableConstructors
have been removed due to tight dependance on syntax analysis to count the number of elements which do not work with conditional compilation.Main changes are based around
DispatchableConstructorInfo
andDispatchableMessageInfo
code generation. Earlier, the logic was based around retrieving dispatchable IDs from the constant array. As mentioned in the #1231, this logic doesn't work when some ink items are omitted at the macro expansion. Therefore, it was decided to explicitly pass dispatchable id in the codegen instead of retrieving it from the array.Other changes involve just putting bunch of
cfg
attributes around the codegen to omit associated structures and type definitions at the macro expansion stage.The feature flag only works with the release of
cargo-contract
which includes: use-ink/cargo-contract#1004Checklist
metadata-gen
template cargo-contract#1004cfg