Skip to content

fix(stageleft_tool): re-export dev-dependencies in trybuild-mode __deps - #104

Merged
akainth015 merged 1 commit into
hydro-project:mainfrom
akainth015:stageleft-dev-deps-in-trybuild-deps
Sep 29, 2026
Merged

akainth015 merged 1 commit into
hydro-project:mainfrom
akainth015:stageleft-dev-deps-in-trybuild-deps

Conversation

@akainth015

Copy link
Copy Markdown
Member

Problem

In trybuild mode (gen_staged_trybuild with a test-mode feature), staged #[cfg(test)] code is kept behind the test-mode feature, and the generated crate makes the original crate's dev-dependencies available under that same feature. However, the generated __deps module only re-exports [dependencies], so spliced code that names a dev-only crate fails to resolve.

For example, with a crate whose test uses a type from a dev-only crate as a type parameter:

[dev-dependencies]
my_test_helper = { path = "../my_test_helper" }
#[cfg(test)]
mod tests {
    #[test]
    fn test() {
        // ...
        let (in_port, input) = process.sim_input_with::<my_test_helper::Codec, _, _, _>();
        // ...
    }
}

the generated code (which starts with use <crate>::__staged::__deps::*;) contains my_test_helper::Codec and fails to compile:

error[E0433]: cannot find module or crate `my_test_helper` in this scope
    |
768 | <my_test_helper::Codec as hydro_lang::__staged::sim::codec::SimCodec<
    |  ^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `my_test_helper`

Change

gen_deps_module now takes the test-mode feature. When set (trybuild mode), it also collects [dev-dependencies] and [target.'cfg(..)'.dev-dependencies], gating each declaration on the test-mode feature and merging it with any regular declaration of the same crate, so the existing merge semantics apply:

Declarations __deps gate
dev-only cfg(any(feature = "<test>"))
dev + non-optional regular ungated (unchanged)
dev + optional regular cfg(any(<regular gates>, any(feature = "<test>")))
target-specific dev cfg(all(<target cfg>, any(feature = "<test>")))

The same gate applies to the runtime add_deps_reexport registration, and package renames are handled as for regular dependencies. Since Cargo does not allow optional dev-dependencies, dev declarations are only ever gated on the test-mode feature.

The __deps generated from gen_final! (build.rs) passes no test-mode feature, so its output is unchanged (the staged_deps snapshot is untouched).

Tests

  • New unit tests for each row above, package renames, and that dev-dependencies are ignored without a test-mode feature.
  • cargo test --workspace --all-targets and cargo clippy --workspace --all-targets -- -D warnings pass.
  • Checked end to end with a Hydro sim test like the example above: it fails with the E0433 above against main and passes with this change.

…eps`

In trybuild mode, staged `#[cfg(test)]` code is kept behind the test-mode
feature, and the generated crate makes dev-dependencies available under
that same feature. However, `__deps` only re-exported `[dependencies]`, so
spliced code which names a dev-only crate (e.g. a type from a dev-only crate
used as a type parameter in a test) failed to resolve with E0433.

`gen_deps_module` now takes the test-mode feature. When it is set (trybuild
mode), `[dev-dependencies]` and `[target.'cfg(..)'.dev-dependencies]` are
also collected, with each declaration gated on the test-mode feature and
merged with any regular declaration of the same crate:

- dev-only: gated on the test-mode feature
- dev + non-optional regular: ungated (unchanged)
- dev + optional regular: gated on any of the regular gates or the
  test-mode feature
- target-specific dev: gated on both the target cfg and the test-mode
  feature

The same gate applies to the runtime `add_deps_reexport` registration. The
`__deps` generated by `gen_final!` (build.rs) passes no test-mode feature,
so its output is unchanged.

Adds unit tests covering the gating cases above, package renames, and that
dev-dependencies are ignored without a test-mode feature.

@shadaj shadaj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Awesome!

@akainth015
akainth015 merged commit 5a142f6 into hydro-project:main Sep 29, 2026
6 checks passed
@akainth015
akainth015 deleted the stageleft-dev-deps-in-trybuild-deps branch September 29, 2026 16:13
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.

2 participants