Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
.idea
202 changes: 202 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion codama-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ name = "tests"
path = "tests/mod.rs"

[dev-dependencies]
solana-address = { version = "2.4.0", features = ["curve25519"] }
trybuild = { version = "1.0.49", features = ["diff"] }

[target.'cfg(not(target_os = "solana"))'.dependencies]
codama-attributes = { version = "0.8.0", path = "../codama-attributes" }
codama-errors = { version = "0.8.0", path = "../codama-errors" }
codama-koroks = { version = "0.8.0", path = "../codama-koroks" }
codama-nodes = { version = "0.8.0", path = "../codama-nodes" }
codama-stores = { version = "0.8.0", path = "../codama-stores" }
codama-syn-helpers = { version = "0.8.0", path = "../codama-syn-helpers" }
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0", features = ["extra-traits"] }
syn = { version = "2.0", features = ["extra-traits", "full"] }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
Expand Down
16 changes: 16 additions & 0 deletions codama-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use proc_macro::TokenStream;
mod attributes;
#[cfg(not(target_os = "solana"))]
mod derives;
#[cfg(not(target_os = "solana"))]
mod pda_helpers;

fn codama_derive(input: TokenStream) -> TokenStream {
#[cfg(not(target_os = "solana"))]
Expand Down Expand Up @@ -57,6 +59,20 @@ pub fn codama_pda_derive(input: TokenStream) -> TokenStream {
codama_derive(input)
}

#[proc_macro_derive(CodamaPdaHelpers, attributes(codama))]
pub fn codama_pda_helpers_derive(input: TokenStream) -> TokenStream {
Comment on lines +62 to +63
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@febo better naming proposals?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Whatever we land on with the derive name, just want to flag that IMO it should start with Codama since it purely relies on codama attributes.

#[cfg(not(target_os = "solana"))]
{
pda_helpers::codama_pda_helpers_derive_impl(input.into())
.unwrap_or_else(codama_errors::CodamaError::into_compile_error)
.into()
}
#[cfg(target_os = "solana")]
{
input
}
}

Comment on lines +62 to +75
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It would be nice if this macro was on its own crate. Maybe something like codama-pda-helpers or whatever the name ends up being here.

That way, if anyone wants to use a slightly different version of our generated code, it's easier for them to fork that crate on its own.

#[proc_macro_derive(CodamaType, attributes(codama))]
pub fn codama_type_derive(input: TokenStream) -> TokenStream {
codama_derive(input)
Expand Down
Loading
Loading