From a6667dbf01ca8a4c495c85159bf310559b7a1007 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 27 Jun 2014 23:37:21 +1000 Subject: [PATCH] Add support for multiple [[lib]]s in a package. --- src/cargo/util/toml.rs | 19 ++++++++-------- tests/test_cargo_compile.rs | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 784311f9ce2..6e91bf51d28 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -198,15 +198,16 @@ fn normalize(lib: Option<&[TomlLibTarget]>, } fn lib_targets(dst: &mut Vec, libs: &[TomlLibTarget]) { - let l = &libs[0]; - let path = l.path.clone().unwrap_or_else(|| format!("src/{}.rs", l.name)); - let crate_types = l.crate_type.clone().and_then(|kinds| { - LibKind::from_strs(kinds).ok() - }).unwrap_or_else(|| vec!(Lib)); - - for profile in target_profiles(l).iter() { - dst.push(Target::lib_target(l.name.as_slice(), crate_types.clone(), - &Path::new(path.as_slice()), profile)); + for l in libs.iter() { + let path = l.path.clone().unwrap_or_else(|| format!("src/{}.rs", l.name)); + let crate_types = l.crate_type.clone().and_then(|kinds| { + LibKind::from_strs(kinds).ok() + }).unwrap_or_else(|| vec!(Lib)); + + for profile in target_profiles(l).iter() { + dst.push(Target::lib_target(l.name.as_slice(), crate_types.clone(), + &Path::new(path.as_slice()), profile)); + } } } diff --git a/tests/test_cargo_compile.rs b/tests/test_cargo_compile.rs index 168603d22f9..38e96e24b61 100644 --- a/tests/test_cargo_compile.rs +++ b/tests/test_cargo_compile.rs @@ -559,3 +559,47 @@ test!(many_crate_types { assert!(file0.ends_with(os::consts::DLL_SUFFIX) || file1.ends_with(os::consts::DLL_SUFFIX)); }) + +test!(multiple_libs { + let mut p = project("foo"); + p = p + .file("Cargo.toml", r#" + [project] + + name = "foo" + version = "0.5.0" + authors = ["wycats@example.com"] + + [[lib]] + + name = "foofoofoo" + + [[lib]] + + name = "barbarbar" + "#) + .file("src/foofoofoo.rs", r#" + pub fn foo() {} + "#) + .file("src/barbarbar.rs", r#" + pub fn bar() {} + "#); + + assert_that(p.cargo_process("cargo-build"), + execs().with_status(0)); + + let files = fs::readdir(&p.root().join("target")).assert(); + let mut files: Vec = files.iter().filter_map(|f| { + match f.filename_str().unwrap() { + "deps" => None, + s if s.contains("fingerprint") => None, + s => Some(s.to_str()) + } + }).collect(); + files.sort(); + let file0 = files.get(0).as_slice(); + let file1 = files.get(1).as_slice(); + println!("{} {}", file0, file1); + assert!(file0.contains("barbarbar")); + assert!(file1.contains("foofoofoo")); +})