diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 788b6d7ff..d12762ba1 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -30,6 +30,10 @@ pub fn to_manifest(contents: &[u8], Some(ref toml) => add_unused_keys(&mut manifest, toml, "".to_string()), None => {} } + if manifest.get_targets().len() == 0 { + return Err(human(format!("either a [[lib]] or [[bin]] section must \ + be present"))) + } return Ok((manifest, paths)); fn add_unused_keys(m: &mut Manifest, toml: &toml::Value, key: String) { diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 7119ef6b7..a0e2010ba 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -766,3 +766,19 @@ test!(ignore_broken_symlinks { process(p.bin("foo")), execs().with_stdout("i am foo\n")); }) + +test!(missing_lib_and_bin { + let mut p = project("foo"); + p = p + .file("Cargo.toml", r#" + [package] + + name = "test" + version = "0.0.0" + authors = [] + "#); + assert_that(p.cargo_process("cargo-build"), + execs().with_status(101) + .with_stderr("either a [[lib]] or [[bin]] section \ + must be present\n")); +}) diff --git a/tests/test_cargo_compile_path_deps.rs b/tests/test_cargo_compile_path_deps.rs index eb02258a3..42a25f10c 100644 --- a/tests/test_cargo_compile_path_deps.rs +++ b/tests/test_cargo_compile_path_deps.rs @@ -493,6 +493,10 @@ test!(error_message_for_missing_manifest { [dependencies.bar] path = "src/bar" + + [[lib]] + + name = "foo" "#) .file("src/bar/not-a-manifest", "");