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

Conditional compilation #1707

Merged
merged 28 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Basic support for `dyn Trait` to allow cross-contract calls only with trait - [#1673](https://github.com/paritytech/ink/pull/1673)
- E2E: auto detect contracts to be built - [#1691](https://github.com/paritytech/ink/pull/1691)
- Add `set_code_hash` to `EnvAccess` - [#1698](https://github.com/paritytech/ink/pull/1698)
- Support conditional compilation - [#1707](https://github.com/paritytech/ink/pull/1707)
SkymanOne marked this conversation as resolved.
Show resolved Hide resolved

## Version 4.0.1

Expand Down
10 changes: 10 additions & 0 deletions crates/ink/codegen/src/generator/as_dependency/call_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ impl CallBuilder<'_> {
let span = message.span();
let message_ident = message.ident();
let output_ident = generator::output_ident(message_ident);
let cfg_tokens = message.get_cfg_tokens();
let cfg_attrs: Vec<TokenStream2> = cfg_tokens
.iter()
.map(|token| {
quote_spanned!(span=>
#[cfg #token])
})
.collect();
SkymanOne marked this conversation as resolved.
Show resolved Hide resolved
let trait_info_id = generator::generate_reference_to_trait_info(span, trait_path);
let (input_bindings, input_types): (Vec<_>, Vec<_>) = message
.callable()
Expand All @@ -295,13 +303,15 @@ impl CallBuilder<'_> {
.whitelisted_attributes()
.filter_attr(message.attrs().to_vec());
quote_spanned!(span=>
#( #cfg_attrs )*
type #output_ident = <<<
Self
as ::ink::codegen::TraitCallForwarderFor<{#trait_info_id}>>::Forwarder
as ::ink::codegen::TraitCallBuilder>::Builder
as #trait_path>::#output_ident;

#[inline]
#( #cfg_attrs )*
SkymanOne marked this conversation as resolved.
Show resolved Hide resolved
#( #attrs )*
fn #message_ident(
& #mut_token self
Expand Down
10 changes: 10 additions & 0 deletions crates/ink/codegen/src/generator/as_dependency/contract_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,21 @@ impl ContractRef<'_> {
let mut_token = message.receiver().is_ref_mut().then(|| quote! { mut });
let input_bindings = message.inputs().map(|input| &input.pat).collect::<Vec<_>>();
let input_types = message.inputs().map(|input| &input.ty).collect::<Vec<_>>();
let cfg_tokens = message.get_cfg_tokens();
let cfg_attrs: Vec<TokenStream2> = cfg_tokens
.iter()
.map(|token| {
quote_spanned!(span=>
#[cfg #token])
})
.collect();
quote_spanned!(span=>
#( #cfg_attrs )*
type #output_ident =
<<Self::__ink_TraitInfo as ::ink::codegen::TraitCallForwarder>::Forwarder as #trait_path>::#output_ident;

#[inline]
#( #cfg_attrs )*
fn #message_ident(
& #mut_token self
#( , #input_bindings : #input_types )*
Expand Down
Loading