Skip to content

Commit

Permalink
Fix publication of packages with metadata and resolver
Browse files Browse the repository at this point in the history
This commit fixes an issue where packages which specify `resolver = '2'`
cannot be packaged if they also have a `package.metadata` table. The
issue is that the `toml` serialization implementation serializes fields
in order which requires that tables be emitted last.
  • Loading branch information
alexcrichton committed Mar 25, 2021
1 parent 56b3497 commit 6bc7455
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,8 +815,11 @@ pub struct TomlProject {
license: Option<String>,
license_file: Option<String>,
repository: Option<String>,
metadata: Option<toml::Value>,
resolver: Option<String>,

// Note that this field must come last due to the way toml serialization
// works which requires tables to be emitted after all values.
metadata: Option<toml::Value>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand All @@ -825,8 +828,11 @@ pub struct TomlWorkspace {
#[serde(rename = "default-members")]
default_members: Option<Vec<String>>,
exclude: Option<Vec<String>>,
metadata: Option<toml::Value>,
resolver: Option<String>,

// Note that this field must come last due to the way toml serialization
// works which requires tables to be emitted after all values.
metadata: Option<toml::Value>,
}

impl TomlProject {
Expand Down
22 changes: 22 additions & 0 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1954,3 +1954,25 @@ fn reproducible_output() {
assert_eq!(header.groupname().unwrap().unwrap(), "");
}
}

#[cargo_test]
fn package_with_resolver_and_metadata() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
authors = []
resolver = '2'
[package.metadata.docs.rs]
all-features = true
"#,
)
.file("src/lib.rs", "")
.build();

p.cargo("package").run();
}

0 comments on commit 6bc7455

Please sign in to comment.