From d08ec0326e39761115ab8128b152fcf8f18e026a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stanis=C5=82aw=20Drozd?= Date: Fri, 7 May 2021 20:47:21 +0200 Subject: [PATCH] lang: Add anchor-debug feature flag for logging (#253) --- CHANGELOG.md | 1 + lang/Cargo.toml | 11 +++++++++++ lang/attribute/access-control/Cargo.toml | 3 +++ lang/attribute/account/Cargo.toml | 3 +++ lang/attribute/error/Cargo.toml | 3 +++ lang/attribute/event/Cargo.toml | 3 +++ lang/attribute/interface/Cargo.toml | 3 +++ lang/attribute/program/Cargo.toml | 3 +++ lang/attribute/state/Cargo.toml | 3 +++ lang/derive/accounts/Cargo.toml | 4 ++++ lang/syn/Cargo.toml | 1 + lang/syn/src/codegen/accounts.rs | 6 +++--- lang/syn/src/codegen/program.rs | 4 ++++ 13 files changed, 45 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 373221421..cf3a23908 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ incremented for features. ## Features * client: Adds support for state instructions ([#248](https://github.com/project-serum/anchor/pull/248)). +* lang: Add `anchor-debug` feature flag for logging ([#253](https://github.com/project-serum/anchor/pull/253)). * ts: Add support for u16 ([#255](https://github.com/project-serum/anchor/pull/255)). ## Breaking diff --git a/lang/Cargo.toml b/lang/Cargo.toml index 86831527c..a189ffd30 100644 --- a/lang/Cargo.toml +++ b/lang/Cargo.toml @@ -10,6 +10,17 @@ description = "Solana Sealevel eDSL" [features] derive = [] default = [] +anchor-debug = [ + "anchor-attribute-access-control/anchor-debug", + "anchor-attribute-account/anchor-debug", + "anchor-attribute-error/anchor-debug", + "anchor-attribute-event/anchor-debug", + "anchor-attribute-interface/anchor-debug", + "anchor-attribute-program/anchor-debug", + "anchor-attribute-program/anchor-debug", + "anchor-attribute-state/anchor-debug", + "anchor-derive-accounts/anchor-debug" +] [dependencies] anchor-attribute-access-control = { path = "./attribute/access-control", version = "0.4.5" } diff --git a/lang/attribute/access-control/Cargo.toml b/lang/attribute/access-control/Cargo.toml index f8269b86f..ab7767db5 100644 --- a/lang/attribute/access-control/Cargo.toml +++ b/lang/attribute/access-control/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/account/Cargo.toml b/lang/attribute/account/Cargo.toml index 8763d6509..ccc61ee58 100644 --- a/lang/attribute/account/Cargo.toml +++ b/lang/attribute/account/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/error/Cargo.toml b/lang/attribute/error/Cargo.toml index 3450035c0..92163aecb 100644 --- a/lang/attribute/error/Cargo.toml +++ b/lang/attribute/error/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/event/Cargo.toml b/lang/attribute/event/Cargo.toml index 589ad6dd7..c932e0df8 100644 --- a/lang/attribute/event/Cargo.toml +++ b/lang/attribute/event/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/interface/Cargo.toml b/lang/attribute/interface/Cargo.toml index 510131a58..8e0cefda3 100644 --- a/lang/attribute/interface/Cargo.toml +++ b/lang/attribute/interface/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/program/Cargo.toml b/lang/attribute/program/Cargo.toml index d2a1bde70..4a276b7e3 100644 --- a/lang/attribute/program/Cargo.toml +++ b/lang/attribute/program/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/attribute/state/Cargo.toml b/lang/attribute/state/Cargo.toml index 231d6d29d..23116bd2f 100644 --- a/lang/attribute/state/Cargo.toml +++ b/lang/attribute/state/Cargo.toml @@ -10,6 +10,9 @@ edition = "2018" [lib] proc-macro = true +[features] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/derive/accounts/Cargo.toml b/lang/derive/accounts/Cargo.toml index 117458ee0..91ed68b83 100644 --- a/lang/derive/accounts/Cargo.toml +++ b/lang/derive/accounts/Cargo.toml @@ -10,6 +10,10 @@ edition = "2018" [lib] proc-macro = true +[features] +default = [] +anchor-debug = ["anchor-syn/anchor-debug"] + [dependencies] proc-macro2 = "1.0" quote = "1.0" diff --git a/lang/syn/Cargo.toml b/lang/syn/Cargo.toml index 522e22745..3b907a2ba 100644 --- a/lang/syn/Cargo.toml +++ b/lang/syn/Cargo.toml @@ -11,6 +11,7 @@ edition = "2018" idl = [] hash = [] default = [] +anchor-debug = [] [dependencies] proc-macro2 = "1.0" diff --git a/lang/syn/src/codegen/accounts.rs b/lang/syn/src/codegen/accounts.rs index c57ce4e7d..983a53105 100644 --- a/lang/syn/src/codegen/accounts.rs +++ b/lang/syn/src/codegen/accounts.rs @@ -21,7 +21,7 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream { let name = &s.ident; let ty = &s.raw_field.ty; quote! { - #[cfg(feature = "debug-log")] + #[cfg(feature = "anchor-debug")] ::solana_program::log::sol_log(stringify!(#name)); let #name: #ty = anchor_lang::Accounts::try_accounts(program_id, accounts)?; } @@ -40,12 +40,12 @@ pub fn generate(accs: AccountsStruct) -> proc_macro2::TokenStream { let name = &f.typed_ident(); match f.is_init { false => quote! { - #[cfg(feature = "debug-log")] + #[cfg(feature = "anchor-debug")] ::solana_program::log::sol_log(stringify!(#name)); let #name = anchor_lang::Accounts::try_accounts(program_id, accounts)?; }, true => quote! { - #[cfg(feature = "debug-log")] + #[cfg(feature = "anchor-debug")] ::solana_program::log::sol_log(stringify!(#name)); let #name = anchor_lang::AccountsInit::try_accounts_init(program_id, accounts)?; }, diff --git a/lang/syn/src/codegen/program.rs b/lang/syn/src/codegen/program.rs index a2d76a3bb..b3ec1fcb1 100644 --- a/lang/syn/src/codegen/program.rs +++ b/lang/syn/src/codegen/program.rs @@ -67,6 +67,10 @@ pub fn generate(program: Program) -> proc_macro2::TokenStream { /// program, where execution begins. #[cfg(not(feature = "no-entrypoint"))] fn entry(program_id: &Pubkey, accounts: &[AccountInfo], ix_data: &[u8]) -> ProgramResult { + #[cfg(feature = "anchor-debug")] + { + msg!("anchor-debug is active"); + } if ix_data.len() < 8 { return Err(ProgramError::Custom(99)); }