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

Deserialize features into BTreeSet #1

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions bob_the_builder/src/cargo_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub mod workspace {
}

pub mod package {
use std::hash::Hash;
use std::{collections::BTreeSet, hash::Hash};

use serde::Deserialize;

Expand Down Expand Up @@ -138,7 +138,7 @@ pub mod package {
#[derive(Clone, Deserialize, Debug, Default, PartialEq, Eq, Hash)]
pub struct BuildSettings {
/// Features to be enabled for this build.
pub features: Option<Vec<Feature>>,
pub features: Option<BTreeSet<Feature>>,
}

/// Get all the builds and wasm name from the `Cargo.toml` file.
Expand Down Expand Up @@ -191,6 +191,7 @@ pub mod package {
builds = [
{ name = "optimized", features = ["opt1", "opt2"] },
{ name = "debug", features = ["debug"] },
{ name = "boring", features = [] },
]
"#;

Expand All @@ -205,13 +206,22 @@ pub mod package {
Build {
name: "optimized".to_string(),
settings: BuildSettings {
features: Some(vec!["opt1".to_string(), "opt2".to_string()])
features: Some(BTreeSet::from([
"opt1".to_string(),
"opt2".to_string()
]))
}
},
Build {
name: "debug".to_string(),
settings: BuildSettings {
features: Some(vec!["debug".to_string()])
features: Some(BTreeSet::from(["debug".to_string()]))
}
},
Build {
name: "boring".to_string(),
settings: BuildSettings {
features: Some(BTreeSet::default())
}
}
]
Expand Down
14 changes: 4 additions & 10 deletions bob_the_builder/src/pkg_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ impl ParsedPackage {
let mut builds_with_settings: HashMap<BuildSettings, BuildName> = HashMap::new();

// Build all the requested builds
for mut build in self.builds.into_iter() {
for build in self.builds.into_iter() {
// Sort features so feature ordering doesn't matter.
let settings = &mut build.settings;
settings.features.as_mut().map(|f| f.sort());
let settings = &build.settings;

if builds_with_settings.contains_key(settings) {
// build already exists, copy the wasm file with identical features to a new build name
Expand Down Expand Up @@ -69,14 +68,9 @@ impl Build {
.map(|arg| arg.to_string())
.collect::<Vec<String>>();

let featured_arg: String = if !features.is_empty() {
features.join(",")
} else {
String::new()
};

// Add features to command
args.push(format!("--features={}", featured_arg));
let features_arg = features.into_iter().collect::<Vec<String>>().join(", ");
args.push(format!("--features={}", features_arg));

// Run the build
let mut child = Command::new(crate::CARGO_PATH)
Expand Down