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

update linting configurations #35

Merged
merged 3 commits into from
Oct 24, 2024
Merged
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 Cargo.lock

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

2 changes: 1 addition & 1 deletion clients/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license-file = "../../LICENSE"
[features]
anchor = ["dep:anchor-lang"]
test-sbf = []
serde = ["dep:serde", "dep:serde_with"]
serde = ["dep:serde", "dep:serde_with", "kaigan/serde"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lorisleiva this optional feature-flag for kaigan is only necessary when the user adds kaigan types to the repository. This is a manual step, right? Would they be configuring Codama to use kaigan as well?

Asking because it doesn't seem like there's a good place to work this into create-solana-program.

Copy link
Member

Choose a reason for hiding this comment

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

Yes this is a manual step that you only need to do if you end up using more complex types that are defined in Kaigan.


[dependencies]
anchor-lang = { version = "0.30.0", optional = true }
Expand Down
25 changes: 0 additions & 25 deletions clients/rust/src/generated/accounts/address_lookup_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,3 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for AddressLook
Self::deserialize(&mut data)
}
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountDeserialize for AddressLookupTable {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
Ok(Self::deserialize(buf)?)
}
}

#[cfg(feature = "anchor")]
impl anchor_lang::AccountSerialize for AddressLookupTable {}

#[cfg(feature = "anchor")]
impl anchor_lang::Owner for AddressLookupTable {
fn owner() -> Pubkey {
crate::ADDRESS_LOOKUP_TABLE_ID
}
}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::IdlBuild for AddressLookupTable {}

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for AddressLookupTable {
const DISCRIMINATOR: [u8; 8] = [0; 8];
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'a, 'b> CloseLookupTableCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(4 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.address.clone());
account_infos.push(self.authority.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl<'a, 'b> CreateLookupTableCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.address.clone());
account_infos.push(self.authority.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a, 'b> DeactivateLookupTableCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.address.clone());
account_infos.push(self.authority.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl<'a, 'b> ExtendLookupTableCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.address.clone());
account_infos.push(self.authority.clone());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a, 'b> FreezeLookupTableCpi<'a, 'b> {
accounts,
data,
};
let mut account_infos = Vec::with_capacity(2 + 1 + remaining_accounts.len());
let mut account_infos = Vec::with_capacity(3 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.address.clone());
account_infos.push(self.authority.clone());
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"devDependencies": {
"@codama/renderers-js": "^1.0.0",
"@codama/renderers-rust": "^1.0.0",
"@codama/renderers-rust": "^1.0.3",
"@iarna/toml": "^2.2.5",
"codama": "^1.0.0",
"typescript": "^5.5.2",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

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

8 changes: 8 additions & 0 deletions program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,11 @@ crate-type = ["cdylib", "lib"]

[build-dependencies]
rustc_version = "0.4"

[lints.rust.unexpected_cfgs]
level = "warn"
check-cfg = [
'cfg(target_os, values("solana"))',
'cfg(feature, values("min_specialization"))',
'cfg(RUSTC_WITH_SPECIALIZATION)',
buffalojoec marked this conversation as resolved.
Show resolved Hide resolved
]
2 changes: 1 addition & 1 deletion program/tests/create_lookup_table_ix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ fn test_create_lookup_table_idempotent() {
lookup_table_account.lamports(),
Rent::default().minimum_balance(LOOKUP_TABLE_META_SIZE)
);
let lookup_table = AddressLookupTable::deserialize(&lookup_table_account.data()).unwrap();
let lookup_table = AddressLookupTable::deserialize(lookup_table_account.data()).unwrap();
assert_eq!(lookup_table.meta.deactivation_slot, Slot::MAX);
assert_eq!(lookup_table.meta.authority, Some(authority));
assert_eq!(lookup_table.meta.last_extended_slot, 0);
Expand Down
2 changes: 1 addition & 1 deletion program/tests/deactivate_lookup_table_ix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn test_deactivate_lookup_table() {

let lookup_table_account = result.get_account(&lookup_table_address).unwrap();

let lookup_table = AddressLookupTable::deserialize(&lookup_table_account.data()).unwrap();
let lookup_table = AddressLookupTable::deserialize(lookup_table_account.data()).unwrap();
assert_eq!(lookup_table.meta.deactivation_slot, 0);

// Check that only the deactivation slot changed
Expand Down
2 changes: 1 addition & 1 deletion program/tests/extend_lookup_table_ix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn run_test_case(mollusk: &Mollusk, test_case: TestCase) {
assert!(matches!(result.program_result, ProgramResult::Success));

let table_account = result.get_account(&test_case.lookup_table_address).unwrap();
let lookup_table = AddressLookupTable::deserialize(&table_account.data()).unwrap();
let lookup_table = AddressLookupTable::deserialize(table_account.data()).unwrap();
assert_eq!(lookup_table, expected_account.state);
assert_eq!(table_account.lamports(), expected_account.lamports);
assert_eq!(table_account.data().len(), expected_account.data_len);
Expand Down
2 changes: 1 addition & 1 deletion program/tests/freeze_lookup_table_ix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn test_freeze_lookup_table() {
);

let lookup_table_account = result.get_account(&lookup_table_address).unwrap();
let lookup_table = AddressLookupTable::deserialize(&lookup_table_account.data()).unwrap();
let lookup_table = AddressLookupTable::deserialize(lookup_table_account.data()).unwrap();

assert_eq!(lookup_table.meta.authority, None);

Expand Down
2 changes: 2 additions & 0 deletions scripts/client/lint-rust.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
// Configure arguments here.
const lintArgs = [
'-Zunstable-options',
'--all-targets',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to add --all-features here as well, but looks like maybe we're not configuring kaigan serde support properly?

the trait `generated::accounts::address_lookup_table::_::_serde::Deserialize<'_>` is not implemented for `kaigan::types::U64PrefixVec<solana_program::pubkey::Pubkey>`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nvm, I added the fix for this. But I found another clippy error for the Anchor one.

expected `anchor_lang::prelude::Pubkey`, found `solana_program::pubkey::Pubkey`
   |                   help: change the output type to match the trait: `anchor_lang::prelude::Pubkey`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might need to adjust the renderer @lorisleiva so that it uses more Anchor-compatible types, or can somehow tell rustc that the types are the same. Maybe it's a versioning thing?

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I'm not sure I understand what you'd like to adjust. Could you share the bit of code that is causing this clippy error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a clippy error that arises if you pass --all-features, which runs lint on the anchor feature.

Looks like it's because Anchor 0.30 runs solana-program v1.16.
https://github.com/coral-xyz/anchor/blob/852fcc77beb6302474a11e0f8e6f1e688021be36/lang/Cargo.toml#L60

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I guess we just have to make sure create-solana-program generates a template with compatible SDK versions for Anchor, or remove the Anchor support from the base template.

Copy link
Member

Choose a reason for hiding this comment

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

Oh I see what you mean.

The way create-solana-program figures out versioning is by checking the version of your local binaries. So if you end up with incompatible versions, it should mean that the versions you had locally were incompatible at the time of generating the repo.

Recently, we added a new option on the Rust renderer that turns off any Anchor-related traits so you don't need to have any dependency on Anchor. So maybe we should use that here.

Copy link
Contributor Author

@buffalojoec buffalojoec Oct 24, 2024

Choose a reason for hiding this comment

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

Ohh perfect! I just added the new renderer.

'--all-features',
'--',
'--deny=warnings',
...cliArguments(),
Expand Down
1 change: 1 addition & 0 deletions scripts/generate-clients.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ codama.accept(
const rustClient = path.join(__dirname, '..', 'clients', 'rust');
codama.accept(
renderRustVisitor(path.join(rustClient, 'src', 'generated'), {
anchorTraits: false,
formatCode: true,
crateFolder: rustClient,
toolchain: getToolchainArgument('format'),
Expand Down
4 changes: 2 additions & 2 deletions scripts/program/lint.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
// Configure arguments here.
const lintArgs = [
'-Zunstable-options',
'--features',
'bpf-entrypoint,test-sbf',
'--all-targets',
'--all-features',
'--',
'--deny=warnings',
'--deny=clippy::arithmetic_side_effects',
Expand Down