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
lang: add anchor-zero-copy-repr-packed feature flag #1199
lang: add anchor-zero-copy-repr-packed feature flag #1199
Conversation
…ndent on repr(packed) for zero-copy
lang/attribute/account/src/lib.rs
Outdated
@@ -289,7 +289,8 @@ pub fn zero_copy( | |||
|
|||
proc_macro::TokenStream::from(quote! { | |||
#[derive(anchor_lang::__private::ZeroCopyAccessor, Copy, Clone)] | |||
#[repr(C)] | |||
#[cfg_attr(not(feature = "anchor-zero-copy-repr-packed"), repr(C))] |
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 we pass this in as an argument instead?
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.
discussed elsewhere: instead of argument, would be even better to give the user the choice to add a repr
if they add one, do nothing.
If they don't. Add repr(C)
What do you think about an argument instead of a feature flag. E.g. |
Yeah I think that's probably nicer! Haven't worked in this part of the anchor code before, if you could link me to an example commit that does something similar, it might help me out |
@crispheaney you can check if the repr attribute is on the See https://docs.rs/syn/1.0.85/syn/. Specifically the |
This is supporting I see @paul-schaaf suggested we support |
@@ -79,6 +80,8 @@ pub fn account( | |||
.collect(); | |||
if ns == "zero_copy" { | |||
is_zero_copy = true; | |||
} else if ns == "packed" { |
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.
The account
attribute only takes two args but it can't take a namespace so I think this is ok?
@crispheaney
X being your desired alignment config you can still do that in the function of the account macro attribute |
Implemented the repr override here #1273 |
we have the override now so Im closing this |
Addresses #1198.
Not sure the best way to write a test for this! If you have a suggestion I can add that as well
I tested locally by running the following in
tests/chat/programs
:cargo expand
cargo expand --features anchor-zero-copy-repr-packed