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

lang: add anchor_lang::pubkey macro for declaring const Pubkey values #3021

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Jun 13, 2024

anchor_lang::solana_program::pubkey macro doesn’t work because it
expands to code using ::solana_program::pubkey::Pubkey type (note
leading ::). Since programs using anchor-lang crate usually don’t
include solana-program dependency, that symbol ends up unresolved.

Introduce anchor_lang::pubkey macro which accesses solana_program via
anchor_lang instead. This is analogous to declare_id macro which also
had to be repeated in anchor-lang.

anchor_lang::solana_program::pubkey macro doesn’t work because it
expands to code using ::solana_program::pubkey::Pubkey type (note
leading ::).  Since programs using anchor-lang crate usually don’t
include solana-program dependency, that symbol ends up unresolved.

Introduce anchor_lang::pubkey macro which accesses solana_program
via anchor_lang instead.  This is analogous to declare_id macro which
also had to be repeated in anchor-lang.
Copy link

vercel bot commented Jun 13, 2024

@mina86 is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is actually a very old issue about this here: solana-labs/solana#24303

I think this could get fixed upstream + us exporting solana_program from prelude, but I also don't see any problem getting this in to Anchor.

Before we merge, could you note this feature in the CHANGELOG?

@mina86
Copy link
Contributor Author

mina86 commented Jun 13, 2024

Done.

Yes, if Solana dropped :: prefix, this as well as declare_id definitions wouldn’t be necessary in Anchor. Looks like they don’t have appetite for that though.

Copy link
Collaborator

@acheroncrypto acheroncrypto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare_id would still be necessary as we override it for idl-build feature:

#[cfg(feature = "idl-build")]
{
let idl_print = anchor_syn::idl::gen_idl_print_fn_address(address);
return proc_macro::TokenStream::from(quote! {
#ret
#idl_print
});
}

Thanks!

@acheroncrypto acheroncrypto merged commit 81c2519 into coral-xyz:master Jun 14, 2024
48 of 49 checks passed
mina86 added a commit to mina86/anchor that referenced this pull request Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants