Skip to content

Commit

Permalink
Merge pull request #197 from dtolnay/optional3
Browse files Browse the repository at this point in the history
Also look for optional "dep:" in target.'cfg(…)'.dependencies
  • Loading branch information
dtolnay authored Oct 6, 2022
2 parents 0b9bcba + 28e2ff5 commit 3b55adc
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,30 @@ impl Runner {
},
);

let mut targets = source_manifest.target;
for target in targets.values_mut() {
let dev_dependencies = mem::replace(&mut target.dev_dependencies, Map::new());
target.dependencies.extend(dev_dependencies);
}

let mut features = source_manifest.features;
for (feature, enables) in &mut features {
enables.retain(|en| {
if let Some(dep_name) = en.strip_prefix("dep:") {
dependencies.get(dep_name).map_or(false, |dep| dep.optional)
} else {
false
let dep_name = match en.strip_prefix("dep:") {
Some(dep_name) => dep_name,
None => return false,
};
if let Some(Dependency { optional: true, .. }) = dependencies.get(dep_name) {
return true;
}
for target in targets.values() {
if let Some(Dependency { optional: true, .. }) =
target.dependencies.get(dep_name)
{
return true;
}
}
false
});
enables.insert(0, format!("{}/{}", crate_name, feature));
}
Expand All @@ -262,7 +278,7 @@ impl Runner {
},
features,
dependencies,
target: source_manifest.target,
target: targets,
bins: Vec::new(),
workspace: Some(Workspace {
dependencies: workspace_manifest.workspace.dependencies,
Expand All @@ -273,11 +289,6 @@ impl Runner {
replace: workspace_manifest.replace,
};

for target in manifest.target.values_mut() {
let dev_dependencies = mem::replace(&mut target.dev_dependencies, Map::new());
target.dependencies.extend(dev_dependencies);
}

manifest.bins.push(Bin {
name: Name(project_name.to_owned()),
path: Path::new("main.rs").to_owned(),
Expand Down

0 comments on commit 3b55adc

Please sign in to comment.