Skip to content

Commit a76a4f4

Browse files
committed
Omit build metadata from versions in generated Cargo.toml
Prior to this, top-crates would serialize version reqs like this: [dependencies.foo] package = "foo" version = "=1.2.3+whatever" which would then stick a warning into the output every single time the playground compiles anything, whether or not that crate was ever used. warning: version requirement `=1.2.3+whatever` for dependency `foo` includes semver metadata which will be ignored, removing the metadata is recommended to avoid confusion
1 parent 806ce3e commit a76a4f4

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

top-crates/Cargo.lock

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

top-crates/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ repository = "https://github.com/integer32llc/rust-playground"
1212
cargo = "0.62.0"
1313
itertools = "0.10.0"
1414
reqwest = { version = "0.11.0", features = ["blocking"] }
15+
semver = { version = "1.0.11", features = ["serde"] }
1516
serde = "1.0.1"
1617
serde_derive = "1.0.1"
1718
serde_json = "1.0.0"

top-crates/src/lib.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use cargo::{
1313
util::{Config, VersionExt},
1414
};
1515
use itertools::Itertools;
16+
use semver::Version;
1617
use serde::{Deserialize, Serialize};
1718
use std::{
1819
collections::{BTreeMap, BTreeSet, HashSet},
@@ -38,7 +39,7 @@ struct Crate {
3839
#[derive(Debug, Serialize)]
3940
pub struct CrateInformation {
4041
pub name: String,
41-
pub version: String,
42+
pub version: Version,
4243
pub id: String,
4344
}
4445

@@ -57,18 +58,25 @@ pub struct DependencySpec {
5758
#[serde(skip_serializing_if = "String::is_empty")]
5859
pub package: String,
5960
#[serde(serialize_with = "exact_version")]
60-
pub version: String,
61+
pub version: Version,
6162
#[serde(skip_serializing_if = "Vec::is_empty")]
6263
pub features: Vec<String>,
6364
#[serde(skip_serializing_if = "is_true")]
6465
pub default_features: bool,
6566
}
6667

67-
fn exact_version<S>(version: &String, serializer: S) -> Result<S::Ok, S::Error>
68+
fn exact_version<S>(version: &Version, serializer: S) -> Result<S::Ok, S::Error>
6869
where
6970
S: serde::Serializer,
7071
{
71-
format!("={}", version).serialize(serializer)
72+
semver::Comparator {
73+
op: semver::Op::Exact,
74+
major: version.major,
75+
minor: Some(version.minor),
76+
patch: Some(version.patch),
77+
pre: version.pre.clone(),
78+
}
79+
.serialize(serializer)
7280
}
7381

7482
fn is_true(b: &bool) -> bool {
@@ -367,15 +375,15 @@ pub fn generate_info(modifications: &Modifications) -> (BTreeMap<String, Depende
367375
exposed_name.clone(),
368376
DependencySpec {
369377
package: name.to_string(),
370-
version: version.to_string(),
378+
version: version.clone(),
371379
features,
372380
default_features,
373381
},
374382
);
375383

376384
infos.push(CrateInformation {
377385
name: name.to_string(),
378-
version: version.to_string(),
386+
version: version.clone(),
379387
id: exposed_name,
380388
});
381389

0 commit comments

Comments
 (0)