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 (https://github.com/coral-xyz/anchor/pull/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?
Problem
The new IDL crate depends on
anchor-syn
(behindbuild
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'sidl-build
implementation. This should work fine since we pass the program path as an env variable (https://github.com/coral-xyz/anchor/pull/2946), and we can use that to run the logic with theidl-build
feature. However, there is one downside: we lose the span information:Before:
After:
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?