r/programmingprojects • u/127001-sweet-127001 • 2h ago
Why ArchUnitRust still sees an import behind a disabled Cargo feature
One tradeoff in my architecture-testing crate is that it reads Rust source without asking the compiler which feature combination is active. It keeps cfg branches together in the dependency graph.
For example, suppose the core of a project must not depend on its SQLite adapter. This import is still a dependency for the architecture check:
#[cfg(feature = "sqlite")]
use crate::sqlite::Connection;It doesn't disappear from the check just because the default Cargo features omit sqlite. Ordinary imports between files inside the core can remain allowed.
That is useful if the rule means “keep this boundary in every feature variant represented in the source”. You can catch the feature-gated shortcut while working on the default configuration.
The price is precision
This is a conservative source graph. Mutually exclusive branches can appear together, so a cycle in that graph is not proof that the cycle exists in one actual build. It also doesn't expand macros or inspect build-script-generated source. If you need the exact dependency graph of a compiled variant, this analysis isn't that.
The crate is archunit 0.0.2, free and MIT licensed. Project: https://github.com/dragonsec-ai/ArchUnitRust

