Skip to content

Commit

Permalink
Fix --all-targets in a crate without a lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 30, 2017
1 parent 8be175e commit b9497ab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ pub enum CompileFilter<'a> {
required_features_filterable: bool,
},
Only {
all_targets: bool,
lib: bool,
bins: FilterRule<'a>,
examples: FilterRule<'a>,
Expand Down Expand Up @@ -389,13 +390,15 @@ impl<'a> CompileFilter<'a> {

if all_targets {
CompileFilter::Only {
all_targets: true,
lib: true, bins: FilterRule::All,
examples: FilterRule::All, benches: FilterRule::All,
tests: FilterRule::All,
}
} else if lib_only || rule_bins.is_specific() || rule_tsts.is_specific()
|| rule_exms.is_specific() || rule_bens.is_specific() {
CompileFilter::Only {
all_targets: false,
lib: lib_only, bins: rule_bins,
examples: rule_exms, benches: rule_bens,
tests: rule_tsts,
Expand All @@ -410,7 +413,7 @@ impl<'a> CompileFilter<'a> {
pub fn matches(&self, target: &Target) -> bool {
match *self {
CompileFilter::Default { .. } => true,
CompileFilter::Only { lib, bins, examples, tests, benches } => {
CompileFilter::Only { lib, bins, examples, tests, benches, .. } => {
let rule = match *target.kind() {
TargetKind::Bin => bins,
TargetKind::Test => tests,
Expand Down Expand Up @@ -637,7 +640,7 @@ fn generate_targets<'a>(pkg: &'a Package,
};
generate_auto_targets(mode, pkg.targets(), profile, deps, required_features_filterable)
}
CompileFilter::Only { lib, bins, examples, tests, benches } => {
CompileFilter::Only { all_targets, lib, bins, examples, tests, benches } => {
let mut targets = Vec::new();

if lib {
Expand All @@ -647,7 +650,7 @@ fn generate_targets<'a>(pkg: &'a Package,
profile: profile,
required: true,
});
} else {
} else if !all_targets {
bail!("no library targets found")
}
}
Expand Down
28 changes: 28 additions & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3943,3 +3943,31 @@ fn build_filter_infer_profile() {
--emit=dep-info,link[..]")
);
}

#[test]
fn all_targets_no_lib() {
let p = project("foo")
.file("Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("src/main.rs", "fn main() {}")
.build();
assert_that(p.cargo("build").arg("-v").arg("--all-targets"),
execs().with_status(0)
// bin
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --crate-type bin \
--emit=dep-info,link[..]")
// bench
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C opt-level=3 --test [..]")
// unit test
.with_stderr_contains("\
[RUNNING] `rustc --crate-name foo src[/]main.rs --emit=dep-info,link \
-C debuginfo=2 --test [..]")
);
}

0 comments on commit b9497ab

Please sign in to comment.