Consider an anchor workspace set up like so:
programs/a/lib.rs
programs/b/lib.rs
programs/c/lib.rs
common/lib.rs
With accounts struct in the common
crate:
// common/lib.rs
#[derive(Accounts)]
pub struct Inner {
// ...
}
And each program using it as a composite field in their own Accounts structs:
// programs/a/lib.rs, programs/b/lib.rs, programs/c/lib.rs:w
use common::Inner;
#[derive(Accounts)]
pub struct Outer {
pub inner: Inner,
// ...
}
The above setup will fail to compile, seemingly due to the syn
crate only looking in the program crate for Accounts structs when it builds a lookup table, so when it gets to Inner
, it can't find anything and panics.
https://github.com/coral-xyz/anchor/blob/93332766f13e86efbe77c9986722731742317ede/lang/syn/src/idl/file.rs#L631
Is there a workaround for this?
Edit: Since it's a panic out of a macro expansion, there is no compiler error, only a traceback, as shown below:
thread 'main' panicked at 'Could not resolve Accounts symbol Inner', lang/syn/src/idl/file.rs:631:21
stack backtrace:
0: 0x56102cb233e1 - std::backtrace_rs::backtrace::libunwind::trace::h5e7b7b93d1f3acd5
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
1: 0x56102cb233e1 - std::backtrace_rs::backtrace::trace_unsynchronized::h0b55e59d6533cb7a
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
2: 0x56102cb233e1 - std::sys_common::backtrace::_print_fmt::h8d9df3b204a71ddc
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/sys_common/backtrace.rs:66:5
3: 0x56102cb233e1 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h166638903f004cd7
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/sys_common/backtrace.rs:45:22
4: 0x56102c8320ac - core::fmt::write::h4a54f58ff9354b6b
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/core/src/fmt/mod.rs:1196:17
5: 0x56102caf73d4 - std::io::Write::write_fmt::h285cd63945fc257a
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/io/mod.rs:1654:15
6: 0x56102cb25646 - std::sys_common::backtrace::_print::h2c317b930e1ae70b
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/sys_common/backtrace.rs:48:5
7: 0x56102cb25646 - std::sys_common::backtrace::print::h27906e0460eccc74
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/sys_common/backtrace.rs:35:9
8: 0x56102cb25646 - std::panicking::default_hook::{{closure}}::h0440e717959fdde2
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:295:22
9: 0x56102cb26687 - std::panicking::default_hook::h9b8b53679edadd5f
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:314:9
10: 0x56102cb26687 - std::panicking::rust_panic_with_hook::h2fd904b55fab5e80
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:698:17
11: 0x56102cb26162 - std::panicking::begin_panic_handler::{{closure}}::h58d92438ce0acd94
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:588:13
12: 0x56102cb260d6 - std::sys_common::backtrace::__rust_end_short_backtrace::h4bd12a47413d97f7
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/sys_common/backtrace.rs:138:18
13: 0x56102cb26092 - rust_begin_unwind
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/std/src/panicking.rs:584:5
14: 0x56102c573ae2 - core::panicking::panic_fmt::h23013d1ada43f7ea
at /rustc/e0944922007e1bb4fe59809293acf4364410cccc/library/core/src/panicking.rs:142:14
15: 0x56102c790573 - anchor_syn::idl::file::idl_accounts::h55187b8f1adc6481
16: 0x56102c60f7c0 - anchor_syn::idl::file::parse::he5a5767ddbce7c68
17: 0x56102c60ccc4 - anchor_cli::config::WithPath<anchor_cli::config::Config>::read_all_programs::h533c1402e02976ad
18: 0x56102c6a5251 - anchor_cli::cd_member::hea7318802013fcc1
19: 0x56102c6a4229 - anchor_cli::build::h7a2132f36bd7a741
20: 0x56102c67e678 - anchor_cli::entry::hbd3eaf36ba0a2053
21: 0x56102c587033 - anchor::main::h3e549e6b7904e2b8
22: 0x56102c584e63 - std::sys_common::backtrace::__rust_begin_short_backtrace::h1d8764eeff3a1fbd
23: 0x56102c587840 - main
24: 0x7fddde498290 - <unknown>
25: 0x7fddde49834a - __libc_start_main
26: 0x56102c584d85 - _start
at /build/glibc/src/glibc/csu/../sysdeps/x86_64/start.S:115
27: 0x0 - <unknown>