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

sdk: Add macro to get Cargo.toml package metadata #1464

Merged
merged 4 commits into from
May 23, 2024

Conversation

joncinque
Copy link

Problem

As part of the new format for solana programs, we want to use the [package.metadata] section in Cargo.toml to store Solana-specific information, such as the program id, as in https://github.com/solana-program/config/blob/396c398b558abb0b57c9c03e11f766417ce1fc94/program/Cargo.toml#L11-L12

Unfortunately, we need to specify this in two places since it isn't possible to just get the data from the Cargo.toml's metadata directly, ie https://github.com/solana-program/config/blob/396c398b558abb0b57c9c03e11f766417ce1fc94/program/src/lib.rs#L11

Summary of Changes

Following the implementation at https://gitlab.com/shanepearlman/cargo_meta, add a macro that extracts the data from Cargo.toml directly.

This is the first step, next we need to add a macro to generate a const pubkey that we can use with declare_id, ie. something like:

macro_rules! declare_pubkey {
    ($pk:expr) => {{
        let id_array = bs58::decode($pk.as_bytes())
            .with_alphabet(bs58::Alphabet::RIPPLE)
            .into_array_const_unwrap::<PUBKEY_BYTES>();
        Pubkey::new_from_array(id_array)
    }};
}

declare_id!(declare_pubkey!(package_metadata!("solana.program-id")));

cc @lorisleiva

Fixes #

Copy link

@buffalojoec buffalojoec left a comment

Choose a reason for hiding this comment

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

Neat! Looks good to me, just the CI fix.

sdk/macro/src/lib.rs Outdated Show resolved Hide resolved
@joncinque
Copy link
Author

Should be ready for another look!

@joncinque joncinque added the automerge automerge Merge this Pull Request automatically once CI passes label May 23, 2024
@mergify mergify bot merged commit 097aa8e into anza-xyz:master May 23, 2024
54 checks passed
@joncinque joncinque deleted the tomlmeta branch May 23, 2024 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge automerge Merge this Pull Request automatically once CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants