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

declare_program! macro panic with derive may only be applied to structs, enums and unions #3490

Open
yubin-prestolabs opened this issue Jan 15, 2025 · 0 comments

Comments

@yubin-prestolabs
Copy link

Problem

When using the declare_program!() to generate client sdk from idl file, I see the following error:

error[E0774]: `derive` may only be applied to `struct`s, `enum`s and `union`s
 --> src/trydeclare.rs:5:1
  |
5 | declare_program!(ammv3);
  | ^^^^^^^^^^^^^^^^^^^^^^^
  | |
  | not applicable here
  | not a `struct`, `enum` or `union`
  |
  = note: this error originates in the macro `declare_program` (in Nightly builds, run with -Z macro-backtrace for more info)

Specifically, I am using the idl file from raydium-clmm program, https://github.com/raydium-io/raydium-idl/blob/master/raydium_clmm/amm_v3.json

anchor version, rust version, etc

  1. rustup active toolchain: stable-x86_64-unknown-linux-gnu (default)
  2. rustc version: rustc 1.84.0 (9fc6b4312 2025-01-07)
  3. anchor_lang version from (Cargo.lock):
[[package]]                                                                                         
name = "anchor-lang"                                                                                
version = "0.30.1"                                                                                  
source = "registry+https://github.com/rust-lang/crates.io-index"                                    
checksum = "6620c9486d9d36a4389cab5e37dc34a42ed0bfaa62e6a75a2999ce98f8f2e373"                       
dependencies = [                                                                                    
 "anchor-attribute-access-control",                                                                 
 "anchor-attribute-account",                                                                        
 "anchor-attribute-constant",                                                                       
 "anchor-attribute-error",                                                                          
 "anchor-attribute-event",                                                                          
 "anchor-attribute-program",                                                                        
 "anchor-derive-accounts",                                                                          
 "anchor-derive-serde",                                                                             
 "anchor-derive-space",                                                                             
 "arrayref",                                                                                        
 "base64 0.21.7",                                                                                   
 "bincode",                                                                                         
 "borsh 0.10.4",                                                                                    
 "bytemuck",                                                                                        
 "getrandom 0.2.15",                                                                                
 "solana-program",                                                                                  
 "thiserror 1.0.69",                                                                                
]  

[[package]]                                                                                         
name = "anchor-lang-idl"                                                                            
version = "0.1.1"                                                                                   
source = "registry+https://github.com/rust-lang/crates.io-index"                                    
checksum = "31cf97b4e6f7d6144a05e435660fcf757dbc3446d38d0e2b851d11ed13625bba"                       
dependencies = [                                                                                    
 "anchor-lang-idl-spec",                                                                            
 "anyhow",                                                                                          
 "heck 0.3.3",                                                                                      
 "serde",                                                                                           
 "serde_json",                                                                                      
 "sha2 0.10.8",                                                                                     
]                                                                                                   
                                                                                                    
[[package]]                                                                                         
name = "anchor-lang-idl-spec"                                                                       
version = "0.1.0"                                                                                   
source = "registry+https://github.com/rust-lang/crates.io-index"                                    
checksum = "2bdf143115440fe621bdac3a29a1f7472e09f6cd82b2aa569429a0c13f103838"                       
dependencies = [                                                                                    
 "anyhow",                                                                                          
 "serde",                                                                                           
]  

How to reproduce

  1. create a rust mod with the following:
pub mod trydeclare {
use anchor_lang::declare_program;
use anchor_lang::declare_id;
declare_id!("CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK");
declare_program!(ammv3);
}
  1. create the ammv3.json from the json file above, adding the metadata field:
{
    "metadata": {
        "address": "CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"
    },
  "version": "0.1.0",
  "name": "amm_v3",
  /// ... 
}
  1. run cargo build or compile any other way. You will then see the error above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant