let crate_types = target.rustc_crate_types();
- for crate_type in crate_types.iter() {
- log!(5, "root={}; target={}; crate_type={}; dest={}; deps={}; verbose={}",
- root.display(), target, crate_type, dest.display(), deps.display(),
- verbose);
+ log!(5, "root={}; target={}; crate_types={}; dest={}; deps={}; verbose={}",
+ root.display(), target, crate_types, dest.display(), deps.display(),
+ verbose);
- let rustc = prepare_rustc(root, target, *crate_type, dest, deps);
+ let rustc = prepare_rustc(root, target, crate_types, dest, deps);
- try!(if verbose {
- rustc.exec().map_err(|err| human(err.to_str()))
- } else {
- rustc.exec_with_output().and(Ok(())).map_err(|err| human(err.to_str()))
- });
- }
+ try!(if verbose {
+ rustc.exec().map_err(|err| human(err.to_str()))
+ } else {
+ rustc.exec_with_output().and(Ok(())).map_err(|err| human(err.to_str()))
+ });
Ok(())
}
-fn prepare_rustc(root: &Path, target: &Target, crate_type: &'static str,
+fn prepare_rustc(root: &Path, target: &Target, crate_types: Vec<&str>,
dest: &Path, deps: &Path) -> ProcessBuilder {
let mut args = Vec::new();
- build_base_args(&mut args, target, crate_type, dest);
+ build_base_args(&mut args, target, crate_types, dest);
build_deps_args(&mut args, dest, deps);
util::process("rustc")
.env("RUST_LOG", None) // rustc is way too noisy
}
-fn build_base_args(into: &mut Args, target: &Target, crate_type: &'static str,
+fn build_base_args(into: &mut Args, target: &Target, crate_types: Vec<&str>,
dest: &Path) {
// TODO: Handle errors in converting paths into args
into.push(target.get_path().display().to_str());
- into.push("--crate-type".to_str());
- into.push(crate_type.to_str());
+ for crate_type in crate_types.iter() {
+ into.push("--crate-type".to_str());
+ into.push(crate_type.to_str());
+ }
into.push("--out-dir".to_str());
into.push(dest.display().to_str());
}
+use std::io::fs;
+use std::os;
+
use support::{ResultTest,project,execs,main_file};
use hamcrest::{assert_that,existing_file};
use cargo;
assert_that(p.cargo_process("cargo-compile"),
execs().with_status(0));
})
+
+test!(many_crate_types {
+ let mut p = project("foo");
+ p = p
+ .file("Cargo.toml", r#"
+ [project]
+
+ name = "foo"
+ version = "0.5.0"
+ authors = ["wycats@example.com"]
+
+ [[lib]]
+
+ name = "foo"
+ crate_type = ["rlib", "dylib"]
+ "#)
+ .file("src/foo.rs", r#"
+ pub fn foo() {}
+ "#);
+ assert_that(p.cargo_process("cargo-compile"),
+ execs().with_status(0));
+
+ let files = fs::readdir(&p.root().join("target")).assert();
+ let mut files: Vec<String> = files.iter().filter_map(|f| {
+ match f.filename_str().unwrap() {
+ "deps" => None,
+ s => Some(s.to_str())
+ }
+ }).collect();
+ files.sort();
+ let file0 = files.get(0).as_slice();
+ let file1 = files.get(1).as_slice();
+ assert!(file0.ends_with(".rlib") || file1.ends_with(".rlib"));
+ assert!(file0.ends_with(os::consts::DLL_SUFFIX) ||
+ file1.ends_with(os::consts::DLL_SUFFIX));
+})