Skip to content

fix(manifest): added dev-dependencies to Manifest#124

Open
JadKHaddad wants to merge 1 commit intoeupn:masterfrom
JadKHaddad:fix/manifest
Open

fix(manifest): added dev-dependencies to Manifest#124
JadKHaddad wants to merge 1 commit intoeupn:masterfrom
JadKHaddad:fix/manifest

Conversation

@JadKHaddad
Copy link

@JadKHaddad JadKHaddad commented May 17, 2025

A project like this

[package]
name = "test-project"
version = "0.1.0"
edition = "2018"

[lib]

[features]
default = []

test-feature = ["dep:tracing"]

[dev-dependencies]
macrotest = { path = "../" }
tracing = { version = "0.1.40" }

[dependencies]
tracing = { version = "0.1.40", default-features = false, optional = true }

where the same dependency is defined twice, as optional and as not optional, and there is a feature that requires this dependency, macrotest will fail with the following error:

Caused by:
  feature `test-feature` includes `dep:tracing`, but `tracing` is not an optional dependency
  A non-optional dependency of the same name is defined; consider adding `optional = true` to its definition.

This PR adds dev-dependencies to the manifest and extends the manifest.dev_dependencies instead of the manifest.dependencies with the source_manifest.dev_dependencies, which was causing the dependencies to be overridden by the dev-dependencies.

Signed-off-by: Jad K. Haddad <jadkhaddad@gmail.com>
Copy link
Collaborator

@taiki-e taiki-e left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. The code to be expanded is treated as a bin crate, so I guess this breaks cases that using dev-dependencies in the code to be expanded.

@JadKHaddad JadKHaddad requested a review from taiki-e May 17, 2025 19:37
@taiki-e taiki-e removed their request for review May 17, 2025 19:42
@JadKHaddad
Copy link
Author

JadKHaddad commented May 17, 2025

@taiki-e So dev-dependencies should be merged with dependencies under dependencies in the bin crate? The dependencies: BTreeMap in the manifest is overriding the keys, so dev-dependencies meta will override dependencies meta. Would it make sense to change the order the manifest.dependencies are extended? dev-dependencies then dependencies, so that dependencies override the dev ones? Since cargo features may only enable optional dependencies and no dev-dependencies, as far as i am concerned.

@taiki-e
Copy link
Collaborator

taiki-e commented May 17, 2025

So dev-dependencies should be merged with dependencies under dependencies in the bin crate?

Yes, but dev-dependencies should win, similar to the way dev-dependencies are handled in normal tests, because “we do not enable it as a library dependency by default, but we always use it in our tests” is a common case.

The (non-exhaustive) rules when there is a conflict with normal dependencies should probably be found in something like the following

  • Merge the features fields of the normal dependency and the dev-dependency.
  • Retain the no-default-features field only if both have no-default-features, otherwise remove it.
  • If the normal dependency is an optional dependency, make it non-optional and find a reference to it in the list of features in [features] table and remove it.

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