Skip to content

feat(toolkit-macros): compile-time gear dependency linking via re-exports#4146

Merged
MikeFalcon77 merged 15 commits into
constructorfabric:mainfrom
maurolacy:feature/gears-deps
Jul 17, 2026
Merged

feat(toolkit-macros): compile-time gear dependency linking via re-exports#4146
MikeFalcon77 merged 15 commits into
constructorfabric:mainfrom
maurolacy:feature/gears-deps

Conversation

@maurolacy

@maurolacy maurolacy commented Jun 26, 2026

Copy link
Copy Markdown

Problem

The deps field in #[toolkit::gear(deps = [...])] declares runtime lifecycle
dependencies between gears. At startup, build_dependency_graph() validates that
every declared dep exists in the inventory-based registry. However, inventory
relies on linker-section tricks: only crates explicitly referenced with use X as _;
in the generated main.rs survive the linker. Transitive Cargo dependencies get
their inventory::submit! registrations silently stripped.

This forces users to flatten the entire gear dependency tree in Gears.toml. For
example, listing api-gateway is not enough. You must also manually list
grpc-hub, authn-resolver, types-registry, and every other transitive dep.
Forgetting one causes a runtime UnknownDependency error at startup, with no
compile-time signal that anything is wrong.

Solution

The #[toolkit::gear] macro now generates pub use re-exports for each declared
dependency:

#[toolkit::gear(name = "api-gateway", deps = ["grpc-hub", "authn-resolver"])]

expands to (among other things):

#[cfg(not(test))]
#[doc(hidden)]
pub use grpc_hub as _gear_dep_grpc_hub;

#[cfg(not(test))]
#[doc(hidden)]
pub use authn_resolver as _gear_dep_authn_resolver;

This forces the linker to keep the dependency gear crates (and their
inventory::submit! registrations) alive when a gear is pulled in transitively.
The re-exports chain: if api-gateway re-exports authn-resolver, and
authn-resolver re-exports types-registry, then pulling in api-gateway alone
is sufficient to register the entire transitive dependency tree.

The re-exports are gated behind #[cfg(not(test))], so that test builds (where
gears are often defined in the same compilation unit) don't require phantom
external crate dependencies.

Trade-off: Cargo.toml dependencies

For the pub use to compile, each gear's Cargo.toml must list its dep gear
crates as Cargo dependencies (not just SDKs). This is a new requirement, but
forgetting a dependency is now a compile-time error (no external crate),
not a silent runtime failure. The SDK dependencies remain necessary for the
actual API types used in gear implementations.

Naming convention

This change relies on a strict, bidirectional naming convention:

Gear name Crate name Lib name
api-gateway cf-gears-api-gateway api_gateway
types-registry cf-gears-types-registry types_registry

The macro derives the lib name from the dep's gear name by replacing - with _.
This convention is already followed by all gear crates in the repo (24/27 gears;
the 3 exceptions are internal plugins in mini-chat which are same-crate and
unaffected).

Changes

  • libs/toolkit-macros/src/lib.rs: Generate pub use re-exports for each
    entry in deps = [...], gated behind #[cfg(not(test))].
  • Cargo.toml (root): Added 8 workspace-level dependency entries for gear
    crates that were previously only available as SDKs.
  • 22 gear Cargo.toml files: Added the full gear crate as a dependency
    (via { workspace = true }) for each declared dep.

Verification

  • cargo build: Entire workspace compiles cleanly.
  • cargo test --workspace: All test suites pass.

What this enables

With this change, cargo gears and future tooling no longer needs to resolve
and flatten the transitive gear dependency tree. Users can list only the gears
they directly use in Gears.toml, and the macro-generated re-exports ensure the
full dependency chain is linked.

Summary by CodeRabbit

  • New Features

    • Gear dependency declarations now use consistent identifier-based syntax, with clearer validation for incorrect formats.
    • Gear integrations now benefit from automatic dependency handling/re-exports to improve reliability.
    • Expanded workspace support adds additional system crates, enabling broader capabilities across gears and plugins.
  • Documentation

    • Added guidance on declaring gear dependencies and configuring CI “shear” exclusions.
  • CI Improvements

    • Coverage and shear jobs now free disk space before running to improve build stability.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d91fd416-a7b9-4270-9381-8ce8f895b70a

📥 Commits

Reviewing files that changed from the base of the PR and between 8065c59 and ea5f581.

📒 Files selected for processing (2)
  • CONTRIBUTING.md
  • libs/toolkit-macros/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • CONTRIBUTING.md
  • libs/toolkit-macros/src/lib.rs

📝 Walkthrough

Walkthrough

The PR changes #[toolkit::gear(deps = [...])] from string literals to crate identifiers, updates the macro to parse and re-export dependencies, adds corresponding workspace and crate manifest entries, updates examples and documentation, and adds disk cleanup steps to coverage and shear CI jobs.

Changes

Gear dependency wiring

Layer / File(s) Summary
Workspace and crate dependency manifests
Cargo.toml, examples/**/Cargo.toml, gears/**/Cargo.toml
Adds pinned workspace gear dependencies and propagates workspace-sourced resolver, registry, credential, and application dependencies through affected crates and plugins.
Identifier-based gear declarations
examples/**/src/gear.rs, gears/**/src/gear.rs, gears/**/src/module.rs
Updates gear dependency declarations from hyphenated string literals to underscore-based crate identifiers.
Gear macro parsing and dependency re-exports
libs/toolkit-macros/src/lib.rs, libs/toolkit/src/lib.rs, libs/toolkit/tests/*, libs/toolkit-macros-tests/tests/*
Parses identifier arrays, derives package names, emits hidden dependency re-exports, and updates examples, documentation, and UI fixtures.
Example linkage, documentation, and CI support
examples/oop-gears/calculator-gateway/*, CONTRIBUTING.md, .github/workflows/ci.yml
Adds calculator linkage and cargo-shear metadata, documents macro-generated dependency handling, and adds disk cleanup to coverage and shear jobs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant GearCrate
  participant ToolkitMacro
  participant DependencyCrate
  GearCrate->>ToolkitMacro: Declare deps with crate identifiers
  ToolkitMacro->>DependencyCrate: Resolve and re-export dependencies
  ToolkitMacro->>GearCrate: Emit gear metadata and generated wiring
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main change: toolkit-macros now links gear dependencies via generated re-exports.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
libs/toolkit-macros/src/lib.rs (1)

771-787: 🩺 Stability & Availability | 🔵 Trivial

Anchor the re-export path with a leading :: to avoid module-scope shadowing.

The generated pub use #crate_identas#alias_ident; expands at the call site of the #[gear] macro. If the macro is invoked within a submodule that defines a local item (e.g., mod crate_name or const crate_name), the unqualified use resolution may resolve to that local item instead of the intended extern crate. Using ::#crate_ident`` forces resolution against the extern prelude, ensuring the re-export remains stable regardless of local scope.

♻️ Proposed change
             quote! {
                 #[cfg(not(test))]
                 #[doc(hidden)]
-                pub use `#crate_ident` as `#alias_ident`;
+                pub use ::`#crate_ident` as `#alias_ident`;
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/toolkit-macros/src/lib.rs` around lines 771 - 787, The generated
re-export in the macro expansion is currently using an unqualified path that can
be shadowed by local module items. Update the re-export inside the dep reexports
generation in lib.rs so the pub use in the quote! block anchors the crate path
with a leading ::, using the existing crate_ident and alias_ident symbols, to
ensure the extern crate is always resolved from the extern prelude even when
#[gear] is invoked inside a submodule with a conflicting local name.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@libs/toolkit-macros/src/lib.rs`:
- Around line 771-787: The generated re-export in the macro expansion is
currently using an unqualified path that can be shadowed by local module items.
Update the re-export inside the dep reexports generation in lib.rs so the pub
use in the quote! block anchors the crate path with a leading ::, using the
existing crate_ident and alias_ident symbols, to ensure the extern crate is
always resolved from the extern prelude even when #[gear] is invoked inside a
submodule with a conflicting local name.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ea1176a7-fe6b-4137-a78c-d7bf844fa564

📥 Commits

Reviewing files that changed from the base of the PR and between 650eae8 and 8aa9b1f.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (25)
  • Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • examples/toolkit/users-info/users-info/Cargo.toml
  • gears/credstore/credstore/Cargo.toml
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/simple-user-settings/simple-user-settings/Cargo.toml
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/system/api-gateway/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/resource-group/resource-group/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • libs/toolkit-macros/src/lib.rs

@maurolacy
maurolacy force-pushed the feature/gears-deps branch 3 times, most recently from 3a8c413 to bb56a4b Compare July 15, 2026 06:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml`:
- Around line 39-42: Add the required cf-studio-path configuration with the
value ".cf-studio" to the Cargo manifest’s package metadata, alongside the
existing cargo-shear metadata. Preserve the current ignored dependency
configuration.

In `@gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml`:
- Around line 27-28: Add the Cargo manifest metadata key cf-studio-path with
value ".cf-studio" to
gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml (lines 27-28),
both affected dependency sections in gears/bss/ledger/ledger/Cargo.toml (lines
71 and 83-87), and gears/simple-user-settings/simple-user-settings/Cargo.toml
(line 25).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f858e232-6f3b-4ebd-a24b-6ba34ff29729

📥 Commits

Reviewing files that changed from the base of the PR and between de9c728 and bb56a4b.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (27)
  • Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • examples/toolkit/users-info/users-info/Cargo.toml
  • gears/bss/ledger/ledger/Cargo.toml
  • gears/credstore/credstore/Cargo.toml
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/file-storage/file-storage/Cargo.toml
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/simple-user-settings/simple-user-settings/Cargo.toml
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/system/api-gateway/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/resource-group/resource-group/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • libs/toolkit-macros/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (23)
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/credstore/credstore/Cargo.toml
  • gears/system/api-gateway/Cargo.toml
  • examples/toolkit/users-info/users-info/Cargo.toml
  • gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
  • Cargo.toml
  • gears/file-storage/file-storage/Cargo.toml
  • gears/system/resource-group/resource-group/Cargo.toml
  • gears/system/oagw/oagw/Cargo.toml
  • libs/toolkit-macros/src/lib.rs
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml

Comment thread examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
Comment thread gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
@maurolacy
maurolacy force-pushed the feature/gears-deps branch from bb56a4b to 8a225e9 Compare July 15, 2026 07:46
@aviator5

aviator5 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Could we avoid deriving the Rust crate identifier from the dependency’s runtime name ("authn-resolver" -> authn_resolver) and make deps use crate identifiers instead?

For example:

#[toolkit::gear(
    name = "api-gateway",
    deps = [grpc_hub, authn_resolver],
)]

Each gear macro expansion could expose its canonical runtime name:

#[doc(hidden)]
pub const __TOOLKIT_GEAR_NAME: &str = "authn-resolver";

Then the api-gateway expansion could both force-link and register the dependency without duplicating or deriving its name:

#[doc(hidden)]
pub use ::authn_resolver as _toolkit_gear_dep_authn_resolver;

builder.register_core_with_meta(
    "api-gateway",
    &[::authn_resolver::__TOOLKIT_GEAR_NAME],
    // ...
);

This would keep the link-time behavior from this PR, while removing the implicit gear name -> lib crate name convention and allowing Cargo aliases or custom [lib] names. The compiler would also validate the actual dependency path directly.

@maurolacy, what do you think about this direction?

Mauro Lacy added 9 commits July 16, 2026 16:58
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
@maurolacy

maurolacy commented Jul 16, 2026

Copy link
Copy Markdown
Author

Could we avoid deriving the Rust crate identifier from the dependency’s runtime name ("authn-resolver" -> authn_resolver) and make deps use crate identifiers instead?

I think this is a great idea, since in that way the compiler can validate those identifiers directly.

Now, introducing a new __TOOLKIT_GEAR_NAME const has some problems: Every gear defines its struct in a submodule (src/gear.rs or src/module.rs), not at crate root, and the #[gear] macro generates code at the call site. So the const would end up at e.g. ::authn_resolver::gear::__TOOLKIT_GEAR_NAME, not at ::authn_resolver::__TOOLKIT_GEAR_NAME.
For the macro expansion to reference ::authn_resolver::__TOOLKIT_GEAR_NAME, every gear crate's lib.rs would need to add a re-export. That's ~30 gear crates to update, plus a new convention to maintain.

Since the naming convention currently holds, and for ~30 crates, why introduce a mapping at all? In any case, that mapping can be introduced later, if / when needed (i.e. when somebody breaks the naming convention for some (sound) reason).

So, my proposal would be a hybrid of the current changes and your proposal:

  • Accept idents: deps = [authn_resolver].
  • Use idents directly for pub use re-exports (compile-time validation).
  • Derive runtime name at macro time: authn_resolver"authn-resolver".
  • Pro: Same compile-time validation win, zero lib.rs changes, tests work as-is.
  • Con: Still has a naming convention (just reversed).

I'll go ahead and implement this variant, and we can discuss it further in any case.

MF: sorry, I edited this comment by mistake. (reverted to original)

@maurolacy
maurolacy force-pushed the feature/gears-deps branch from 8a225e9 to fa65cbe Compare July 16, 2026 15:53
Mauro Lacy added 3 commits July 16, 2026 17:55
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
@maurolacy
maurolacy force-pushed the feature/gears-deps branch from fa65cbe to cec1f7f Compare July 16, 2026 15:56
Mauro Lacy added 2 commits July 16, 2026 21:36
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
@maurolacy
maurolacy force-pushed the feature/gears-deps branch from e89f43c to 0cd439e Compare July 16, 2026 19:36

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@gears/system/authn-resolver/authn-resolver/Cargo.toml`:
- Line 26: Add the required cf-studio-path metadata with value ".cf-studio" to
gears/system/authn-resolver/authn-resolver/Cargo.toml at lines 26-26,
gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml at lines 27-28,
and gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml at lines
24-24, preserving the existing manifest entries.

In `@gears/system/resource-group/resource-group/Cargo.toml`:
- Around line 63-64: Add cf-studio-path = ".cf-studio" to both manifest
dependency sections: gears/system/resource-group/resource-group/Cargo.toml at
lines 63-64 and gears/system/usage-collector/usage-collector/Cargo.toml at lines
23-25. Ensure both Cargo.toml files define the required configuration.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d41a92f-9fd0-4972-8230-82d2cd5efd7d

📥 Commits

Reviewing files that changed from the base of the PR and between bb56a4b and e89f43c.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (58)
  • .github/workflows/ci.yml
  • Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/src/gear.rs
  • examples/toolkit/users-info/users-info/Cargo.toml
  • examples/toolkit/users-info/users-info/src/gear.rs
  • gears/bss/ledger/ledger/Cargo.toml
  • gears/bss/ledger/ledger/src/module.rs
  • gears/credstore/credstore/Cargo.toml
  • gears/credstore/credstore/src/gear.rs
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/credstore/plugins/static-credstore-plugin/src/gear.rs
  • gears/file-storage/file-storage/Cargo.toml
  • gears/file-storage/file-storage/src/gear.rs
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/mini-chat/mini-chat/src/gear.rs
  • gears/mini-chat/mini-chat/src/infra/plugins/static_audit/gear.rs
  • gears/mini-chat/mini-chat/src/infra/plugins/static_model_policy/gear.rs
  • gears/simple-user-settings/simple-user-settings/Cargo.toml
  • gears/simple-user-settings/simple-user-settings/src/gear.rs
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/account-management/account-management/src/gear.rs
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/src/gear.rs
  • gears/system/api-gateway/Cargo.toml
  • gears/system/api-gateway/src/gear.rs
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/src/gear.rs
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/src/gear.rs
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/src/gear.rs
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/src/gear.rs
  • gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/static-authz-plugin/src/gear.rs
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/src/gear.rs
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/oagw/oagw/src/gear.rs
  • gears/system/resource-group/resource-group/Cargo.toml
  • gears/system/resource-group/resource-group/src/gear.rs
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/src/gear.rs
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/src/module.rs
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • gears/system/usage-collector/usage-collector/src/module.rs
  • libs/toolkit-macros-tests/tests/ui/fail/deps_not_array.stderr
  • libs/toolkit-macros/src/lib.rs
  • libs/toolkit/src/lib.rs
  • libs/toolkit/tests/macro_tests.rs
🚧 Files skipped from review as they are similar to previous changes (20)
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/api-gateway/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/simple-user-settings/simple-user-settings/Cargo.toml
  • gears/file-storage/file-storage/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/bss/ledger/ledger/Cargo.toml
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/credstore/credstore/Cargo.toml
  • gears/mini-chat/mini-chat/Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • Cargo.toml

Comment thread gears/system/authn-resolver/authn-resolver/Cargo.toml
Comment thread gears/system/resource-group/resource-group/Cargo.toml
@MikeFalcon77

MikeFalcon77 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Agreeing with the hybrid @maurolacy described. The __TOOLKIT_GEAR_NAME route (as @aviator5 suggested) does need a re-export in each gear crate's lib.rs since the macro expands in a submodule (src/gear.rs / module.rs), so the const lands at ::crate::gear::__TOOLKIT_GEAR_NAME, not at crate root — i.e. ~30 crates to touch, not a one-liner. Fine to defer until the naming convention actually needs to break.

One thing not yet raised: the cargo-shear ignore list is a maintenance footgun. Every new gear dep has to be added to the workspace/package ignored list by hand, since the dep is only consumed through the macro-generated re-export and shear can't see it. Forgetting it is a CI break unrelated to the change — might be worth a note in the macro docs / CONTRIBUTING so it isn't discovered the hard way.

@maurolacy

maurolacy commented Jul 16, 2026

Copy link
Copy Markdown
Author

Yeah, I was thinking and analysing this a bit more with AI, and the fact remains: This is a real limitation of proc macros in Rust; they can only emit code at their invocation site. No way to "reach up" to the crate root.

So the options remain:

  • Current approach: _ → - derivation, zero manual steps, universally correct today.
  • Const approach: accurate names from source, but requires a one-line pub use in every gear's lib.rs (and 4 gears need module:: instead of gear::).

Regarding cargo-shear ignore list, there's not much to do here, except maybe turning these into warnings / non-errors in CI. Will investigate / propose this, as I have some ideas on CI improvements already for another PR.
Adding a note in CONTRIBUTING.md.

@maurolacy
maurolacy force-pushed the feature/gears-deps branch from 8c8a53d to 3006fc8 Compare July 16, 2026 22:28
@maurolacy
maurolacy force-pushed the feature/gears-deps branch from 3006fc8 to 8065c59 Compare July 17, 2026 13:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Cargo.toml`:
- Around line 282-289: Add the required cf-studio-path configuration set to
.cf-studio in Cargo.toml and each affected manifest:
gears/credstore/plugins/static-credstore-plugin/Cargo.toml,
gears/simple-user-settings/simple-user-settings/Cargo.toml,
gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml, and
gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml.

In `@CONTRIBUTING.md`:
- Line 94: Update the dependency-attribute example in CONTRIBUTING.md to use the
fully qualified toolkit::gear syntax, including the namespace in the attribute
declaration. Preserve the existing deps example and surrounding documentation.

In `@gears/credstore/plugins/static-credstore-plugin/Cargo.toml`:
- Line 22: Add the required cf-studio-path configuration to the
static-credstore-plugin Cargo.toml, setting it to .cf-studio alongside the
existing types-registry workspace dependency.

In `@gears/simple-user-settings/simple-user-settings/Cargo.toml`:
- Line 25: Add the required cf-studio-path configuration to the
simple-user-settings package's Cargo.toml, setting it explicitly to .cf-studio
alongside the existing authz-resolver workspace dependency.

In `@gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml`:
- Line 24: Update the static-authz-plugin Cargo.toml configuration to add the
required cf-studio-path setting with the value .cf-studio, alongside the
existing types-registry workspace dependency.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 638a3e43-2caf-4044-9e6d-2e8b21e52507

📥 Commits

Reviewing files that changed from the base of the PR and between bb56a4b and 8065c59.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (59)
  • .github/workflows/ci.yml
  • CONTRIBUTING.md
  • Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • examples/oop-gears/calculator-gateway/calculator-gateway/src/gear.rs
  • examples/toolkit/users-info/users-info/Cargo.toml
  • examples/toolkit/users-info/users-info/src/gear.rs
  • gears/bss/ledger/ledger/Cargo.toml
  • gears/bss/ledger/ledger/src/module.rs
  • gears/credstore/credstore/Cargo.toml
  • gears/credstore/credstore/src/gear.rs
  • gears/credstore/plugins/static-credstore-plugin/Cargo.toml
  • gears/credstore/plugins/static-credstore-plugin/src/gear.rs
  • gears/file-storage/file-storage/Cargo.toml
  • gears/file-storage/file-storage/src/gear.rs
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/mini-chat/mini-chat/src/gear.rs
  • gears/mini-chat/mini-chat/src/infra/plugins/static_audit/gear.rs
  • gears/mini-chat/mini-chat/src/infra/plugins/static_model_policy/gear.rs
  • gears/simple-user-settings/simple-user-settings/Cargo.toml
  • gears/simple-user-settings/simple-user-settings/src/gear.rs
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/account-management/account-management/src/gear.rs
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/src/gear.rs
  • gears/system/api-gateway/Cargo.toml
  • gears/system/api-gateway/src/gear.rs
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/src/gear.rs
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/src/gear.rs
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/src/gear.rs
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/src/gear.rs
  • gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/static-authz-plugin/src/gear.rs
  • gears/system/authz-resolver/plugins/tr-authz-plugin/Cargo.toml
  • gears/system/authz-resolver/plugins/tr-authz-plugin/src/gear.rs
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/oagw/oagw/src/gear.rs
  • gears/system/resource-group/resource-group/Cargo.toml
  • gears/system/resource-group/resource-group/src/gear.rs
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/static-tr-plugin/src/gear.rs
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/src/gear.rs
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/src/module.rs
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • gears/system/usage-collector/usage-collector/src/module.rs
  • libs/toolkit-macros-tests/tests/ui/fail/deps_not_array.stderr
  • libs/toolkit-macros/src/lib.rs
  • libs/toolkit/src/lib.rs
  • libs/toolkit/tests/macro_tests.rs
🚧 Files skipped from review as they are similar to previous changes (46)
  • gears/system/authn-resolver/authn-resolver/Cargo.toml
  • libs/toolkit-macros-tests/tests/ui/fail/deps_not_array.stderr
  • gears/credstore/credstore/src/gear.rs
  • gears/system/authz-resolver/authz-resolver/Cargo.toml
  • gears/system/tenant-resolver/tenant-resolver/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/Cargo.toml
  • gears/system/authn-resolver/authn-resolver/src/gear.rs
  • gears/system/tenant-resolver/plugins/static-tr-plugin/Cargo.toml
  • gears/system/usage-collector/usage-collector/src/module.rs
  • gears/system/tenant-resolver/tenant-resolver/src/gear.rs
  • libs/toolkit/tests/macro_tests.rs
  • gears/credstore/credstore/Cargo.toml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/src/module.rs
  • .github/workflows/ci.yml
  • gears/system/usage-collector/plugins/noop-usage-collector-plugin/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/src/gear.rs
  • gears/credstore/plugins/static-credstore-plugin/src/gear.rs
  • libs/toolkit/src/lib.rs
  • gears/system/oagw/oagw/src/gear.rs
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/Cargo.toml
  • gears/system/resource-group/resource-group/src/gear.rs
  • gears/bss/ledger/ledger/src/module.rs
  • examples/toolkit/users-info/users-info/Cargo.toml
  • gears/file-storage/file-storage/Cargo.toml
  • gears/mini-chat/mini-chat/src/gear.rs
  • examples/oop-gears/calculator-gateway/calculator-gateway/src/gear.rs
  • gears/system/tenant-resolver/plugins/single-tenant-tr-plugin/src/gear.rs
  • examples/oop-gears/calculator-gateway/calculator-gateway/Cargo.toml
  • gears/mini-chat/mini-chat/src/infra/plugins/static_model_policy/gear.rs
  • gears/bss/ledger/ledger/Cargo.toml
  • gears/system/authz-resolver/authz-resolver/src/gear.rs
  • gears/mini-chat/mini-chat/Cargo.toml
  • gears/system/usage-collector/usage-collector/Cargo.toml
  • gears/system/tenant-resolver/plugins/rg-tr-plugin/Cargo.toml
  • gears/system/account-management/account-management/Cargo.toml
  • gears/system/account-management/plugins/static-idp-plugin/src/gear.rs
  • gears/system/account-management/plugins/static-idp-plugin/Cargo.toml
  • gears/system/oagw/oagw/Cargo.toml
  • gears/system/authn-resolver/plugins/static-authn-plugin/Cargo.toml
  • gears/system/api-gateway/Cargo.toml
  • gears/system/authn-resolver/plugins/oidc-authn-plugin/src/gear.rs
  • examples/toolkit/users-info/users-info/src/gear.rs
  • gears/system/authz-resolver/plugins/static-authz-plugin/src/gear.rs
  • gears/system/resource-group/resource-group/Cargo.toml
  • libs/toolkit-macros/src/lib.rs
  • gears/file-storage/file-storage/src/gear.rs

Comment thread Cargo.toml
Comment thread CONTRIBUTING.md

#### Gear dependencies and `cargo-shear`

When a gear declares dependencies via `#[gear(deps = [...])]`, the dep entries are

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use the actual toolkit::gear attribute in the example.

The documented syntax omits the toolkit:: namespace, while this feature is exposed as #[toolkit::gear(deps = [...])]. As written, contributors may copy an attribute that does not resolve.

Proposed fix
-When a gear declares dependencies via `#[gear(deps = [...])]`, the dep entries are
+When a gear declares dependencies via `#[toolkit::gear(deps = [...])]`, the dep entries are
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
When a gear declares dependencies via `#[gear(deps = [...])]`, the dep entries are
When a gear declares dependencies via `#[toolkit::gear(deps = [...])]`, the dep entries are
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CONTRIBUTING.md` at line 94, Update the dependency-attribute example in
CONTRIBUTING.md to use the fully qualified toolkit::gear syntax, including the
namespace in the attribute declaration. Preserve the existing deps example and
surrounding documentation.

Comment thread gears/credstore/plugins/static-credstore-plugin/Cargo.toml
Comment thread gears/simple-user-settings/simple-user-settings/Cargo.toml
Comment thread gears/system/authz-resolver/plugins/static-authz-plugin/Cargo.toml
The #[gear(deps = [...])] macro generates hidden pub use re-exports
that cargo-shear cannot trace. Document this in the macro's rustdoc
and in CONTRIBUTING.md so new gear dependencies don't cause unexpected
CI failures in the shear job.

Co-Authored-By: Claude Opus 4.6
Signed-off-by: Mauro Lacy <mauro.lacy@acronis.com>
@maurolacy
maurolacy force-pushed the feature/gears-deps branch from 8065c59 to ea5f581 Compare July 17, 2026 15:20
@MikeFalcon77
MikeFalcon77 merged commit 7d6d0d7 into constructorfabric:main Jul 17, 2026
28 checks passed
@maurolacy
maurolacy deleted the feature/gears-deps branch July 17, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants