Skip to content

Commit

Permalink
lang: Add anchor-debug feature flag for logging (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
drozdziak1 authored May 7, 2021
1 parent 5d8cad6 commit d08ec03
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/access-control/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/error/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/event/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions lang/attribute/state/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions lang/derive/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions lang/syn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2018"
idl = []
hash = []
default = []
anchor-debug = []

[dependencies]
proc-macro2 = "1.0"
Expand Down
6 changes: 3 additions & 3 deletions lang/syn/src/codegen/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand All @@ -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)?;
},
Expand Down
4 changes: 4 additions & 0 deletions lang/syn/src/codegen/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit d08ec03

Please sign in to comment.