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

cli: Fix altering user-provided lib name #3467

Conversation

acheroncrypto
Copy link
Collaborator

Problem

Anchor converts user-provided lib name to snake case:

anchor/cli/src/config.rs

Lines 82 to 91 in 7b6c2b3

if self.lib.is_some() && self.lib.as_ref().unwrap().name.is_some() {
Ok(self
.lib
.as_ref()
.unwrap()
.name
.as_ref()
.unwrap()
.to_string()
.to_snake_case())

This makes the output incompatible with cargo because cargo tooling does not alter user-provided lib names.

For example, if the user sets the lib name to include numbers (in some cases) or uses a non-standard, i.e. non-snake_case, name:

[lib]
name = "myProgram"
crate-type = ["cdylib", "lib"]

Running anchor test results in:

Unable to get latest blockhash. Test validator does not look started. Check ".anchor/test-ledger/test-ledger-log.txt" for errors. Consider increasing [test.startup_wait] in Anchor.toml.

And in .anchor/test-ledger/test-ledger-log.txt:

Error: program file does not exist: target/deploy/my_program.so

This is because the build tool (cargo-build-sbf) outputs the program binary as myProgram.so, but Anchor incorrectly tries to find my_program.so.

Summary of changes

Fix altering user-provided lib name.

Note: Removing the to_snake_case call would have been enough to fix this issue, but the lib_name method implementation was quite repetitive and unidiomatic, so I thought it would be great to rewrite it to make it more concise and idiomatic.

Copy link

vercel bot commented Jan 8, 2025

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added cli fix Bug fix PR labels Jan 8, 2025
@acheroncrypto acheroncrypto merged commit 0922dc3 into coral-xyz:master Jan 8, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli fix Bug fix PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant