Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo add does not maintain sort order of dependencies table #11744

Closed
lopopolo opened this issue Feb 20, 2023 · 2 comments
Closed

cargo add does not maintain sort order of dependencies table #11744

lopopolo opened this issue Feb 20, 2023 · 2 comments
Labels

Comments

@lopopolo
Copy link

Problem

Adding a new dependency to the [dependencies] table with cargo add does not maintain sort order.

Steps

cargo new xxx
cd xxx
cargo new --lib scolapasta-path
cargo new --lib scolapasta-string-escape

Then use this Cargo.toml:

[package]
name = "xxx"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.1.0", optional = true }
# XXX: load-bearing unused dependency.
#
# `rustyline` improperly declares its minimum version on `log` as `0.4` despite
# requiring `>=0.4.5` to compile. Link in at least the minimum version here so
# cargo pulls in at least 0.4.5, e.g. when using `-Zminimal-versions`.
#
# Upstream has not been willing to merge a patch to fix this, so hack around it
# here.
#
# See: https://github.com/kkawakam/rustyline/pull/583
log = { version = "0.4.5", optional = true }
scolapasta-path = { version = "0.1.0", path = "scolapasta-path" }
scolapasta-string-escape = { version = "0.1.0", path = "scolapasta-string-escape", default-features = false }
rustyline = { version = "10.0.0", optional = true, default-features = false }
termcolor = { version = "1.1.0", optional = true }

[workspace]
members = ["scolapasta-path", "scolapasta-string-escape"]

Then: cargo add directories and observe this diff:

diff --git i/Cargo.toml w/Cargo.toml
index 80a27ab..862e90d 100644
--- i/Cargo.toml
+++ w/Cargo.toml
@@ -22,6 +22,7 @@ scolapasta-path = { version = "0.1.0", path = "scolapasta-path" }
 scolapasta-string-escape = { version = "0.1.0", path = "scolapasta-string-escape", default-features = false }
 rustyline = { version = "10.0.0", optional = true, default-features = false }
 termcolor = { version = "1.1.0", optional = true }
+directories = "4.0.1"

 [workspace]
 members = ["scolapasta-path", "scolapasta-string-escape"]

Possible Solution(s)

No response

Notes

This ticket was created at the suggestion of @weihanglo and @epage from #11743.

Version

cargo 1.67.1 (8ecd4f20a 2023-01-10)
release: 1.67.1
commit-hash: 8ecd4f20a9efb626975ac18a016d480dc7183d9b
commit-date: 2023-01-10
host: x86_64-apple-darwin
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0 (sys:0.4.59+curl-7.86.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
os: Mac OS 13.2.1 [64-bit]
@epage
Copy link
Contributor

epage commented Feb 20, 2023

scolapasta-string-escape = { version = "0.1.0", path = "scolapasta-string-escape", default-features = false }
rustyline = { version = "10.0.0", optional = true, default-features = false }

Aren't these already out of order?

cargo add only preserves sorting when it exists. It doesn't attempt to find a sorted-like position if they aren't sorted.

@lopopolo
Copy link
Author

ahh! look at that. thank you!

lopopolo added a commit to artichoke/artichoke that referenced this issue Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants