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

idl: Remove anchor-syn dependency #3030

Conversation

acheroncrypto
Copy link
Collaborator

Problem

The new IDL crate depends on anchor-syn (behind build feature flag), only to check the safety comments. Ideally, the IDL crate shouldn't depend on any of the other Anchor crates and be a stand-alone crate (as it's versioning is also different).

Summary of changes

Handle the safety comment checks inside the #[program] macro's idl-build implementation. This should work fine since we pass the program path as an env variable (#2946), and we can use that to run the logic with the idl-build feature. However, there is one downside: we lose the span information:

Before:

Error: 
        /program/src/lib.rs:87:8
        Struct field "new_account" is unsafe, but is not documented.
        Please add a `/// CHECK:` doc comment explaining why no checks through types are necessary.
        See https://www.anchor-lang.com/docs/the-accounts-struct#safety-checks for more information.

After:

error: custom attribute panicked
  --> program/src/lib.rs:11:1
   |
11 | #[program]
   | ^^^^^^^^^^
   |
   = help: message: Safety checks failed: 
                   /program/src/lib.rs:0:0
                   Struct field "new_account" is unsafe, but is not documented.
                   Please add a `/// CHECK:` doc comment explaining why no checks through types are necessary.
                   See https://www.anchor-lang.com/docs/the-accounts-struct#safety-checks for more information.
                               

error: could not compile `program` (lib test) due to 1 previous error
Error: Building IDL failed

The line and column info is set to 0 when we parse the crate inside a proc macro. Not exactly sure why this happens, but I don't think it's that big of a deal since the file name and the account name is still correct. Not planning to change the span info in this PR as it's harmless, and maybe we can make it work in the future?

Copy link

vercel bot commented Jun 16, 2024

@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 dependencies Pull requests that update a dependency file idl related to the IDL, either program or client side feature labels Jun 16, 2024
@acheroncrypto acheroncrypto merged commit d4318cc into coral-xyz:master Jun 16, 2024
48 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file feature idl related to the IDL, either program or client side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant