Workspace apps: discovery is hard-wired to the `app` crate, and a missing `discover` call fails silently

Open
#822 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
backend

Research direction

Start with src/foundation/mod.rs around read_config and register, macros/core/src/testing.rs, and Registrar's seeder API. The issue outlines three possible changes but leaves their design and scope open; first decide which direction to pursue with maintainers, then trace the related discovery and test setup paths. Done means the agreed approach supports workspace crates and has coverage for the behavior described.

Written by the indexing model from the issue text.

Description

Large applications tend to become Cargo workspaces. I'm evaluating Laravel for Rust against a ~380-crate ERP workspace (one crate per screen/routine, grouped by module), and the multi-crate story currently goes through the package mechanism. That works, but a few things are hard-wired to the crate named app:

  • read_config and register call config.discover("app"), registrar.discover("app"), registrar.auth.discover("app") and registrar.seeders.discover("app") (src/foundation/mod.rs#L1021, #L1045-L1048).
  • #[laravel::test] defaults to ::app::testing::create (macros/core/src/testing.rs#L64). A workspace crate can't depend on app, because app depends on it.

Why splitting matters beyond organization: compile times. On stable Rust the front-end of a crate (macro expansion, type checking) runs on one thread, while Cargo checks independent crates in parallel. We measured this on our real workspace (380 crates, ~314k lines in src/, Rust 1.99, 22 logical cores, third-party dependencies already built, no sccache):

Measurement Result
cargo check of all workspace crates, CARGO_INCREMENTAL=0, -j22 9.1 s
Same, -j1 51.8 s (so cross-crate parallelism gives 5.7×)
Per-crate check cost (linear fit over the 380 crates, -j1) ≈ 0.083 s fixed + 0.061 s per 1,000 lines (R² 0.54)
Edit loop, touching a leaf crate (3 dependents) check 0.75 s, build 2.2 s
Edit loop, touching a base crate (311 dependents) check 3.6 s, build ~8 s

By that fit, the same ~314k lines in a single app crate would take about 19 s to check on one thread, roughly 2× the split workspace. That's an estimate, not a measurement of a merged crate. Splitting isn't free either: the fixed per-crate cost adds up to ~32 s of the 51.8 s serial total. That's why we'd like granularity to be the application's choice, not something the framework makes awkward.

I'm not asking for automatic provider discovery (I saw #50 was closed). I agree with the reasoning in packages.md that explicit providers keep the startup sequence transparent. The concerns are narrower:

  1. Silent failure. If a crate defines #[listener], #[command], #[singleton] or #[schedule::tasks] items but its provider forgets app.discover(env!("CARGO_CRATE_NAME")), those items never run, with no warning. I opened #821, which logs a warning at boot naming each undiscovered item.
  2. Seeders can't come from a provider. Registrar has no public way to discover #[seeder] functions of another crate, so per-module seeders must be re-exported through app. (Auth guards being app-only is documented and seems fine.)
  3. Tests inside a workspace crate must always pass app = ... and rebuild the application themselves.

Possible directions:

  • The boot warning from #821 (or an about/debug-only check, if you prefer another shape).
  • Add app.seeders().discover(crate_name) (or include seeders in Registrar::discover).
  • Let the default for #[laravel::test] be configured once per crate (for example, a crate-level attribute or a documented convention such as crate::testing::create) instead of the hard-coded ::app path.
Dominant language
Rust
Stars
847
Forks
174
Avg merge
5h 40m
Merged PRs (30d)
167

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from laravel/rust-framework

All issues in laravel/rust-framework

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.