features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| s.as_slice()),
+ lib_only: false
},
};
flag_manifest_path: Option<String>,
flag_verbose: bool,
flag_release: bool,
+ flag_lib: bool
}
pub const USAGE: &'static str = "
-h, --help Print this message
-p SPEC, --package SPEC Package to build
-j N, --jobs N The number of jobs to run in parallel
+ --lib Build only lib (if present in package)
--release Build artifacts in release mode, with optimizations
--features FEATURES Space-separated list of features to also build
--no-default-features Do not build the `default` feature
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| s.as_slice()),
+ lib_only: options.flag_lib
};
ops::compile(&root, &mut opts).map(|_| None).map_err(|err| {
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
spec: None,
+ lib_only: false
},
};
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
spec: None,
+ lib_only: false
};
let (target_kind, name) = match (options.flag_name, options.flag_example) {
features: options.flag_features.as_slice(),
no_default_features: options.flag_no_default_features,
spec: options.flag_package.as_ref().map(|s| s.as_slice()),
+ lib_only: false
},
};
pub features: &'a [String],
pub no_default_features: bool,
pub spec: Option<&'a str>,
+ pub lib_only: bool
}
pub fn compile(manifest_path: &Path,
pub fn compile_pkg(package: &Package, options: &mut CompileOptions)
-> CargoResult<ops::Compilation> {
let CompileOptions { env, ref mut shell, jobs, target, spec,
- dev_deps, features, no_default_features } = *options;
+ dev_deps, features, no_default_features,
+ lib_only } = *options;
let target = target.map(|s| s.to_string());
let features = features.iter().flat_map(|s| {
s.as_slice().split(' ')
"doc" | "doc-all" => target.get_profile().get_env() == "doc",
env => target.get_profile().get_env() == env,
}
- }).collect::<Vec<&Target>>();
+ }).filter(|target| !lib_only || target.is_lib()).collect::<Vec<&Target>>();
+
+ if lib_only && targets.len() == 0 {
+ return Err(human("There is no lib to build, remove `--lib` flag".to_string()));
+ }
let ret = {
let _p = profile::start("compiling");
features: [],
no_default_features: false,
spec: None,
+ lib_only: false,
}));
Ok(())
--- /dev/null
+use std::path;
+use support::{basic_bin_manifest, execs, project, ProjectBuilder};
+use support::{COMPILING, RUNNING};
+use hamcrest::{assert_that};
+
+fn setup() {
+}
+
+fn verbose_output_for_lib(p: &ProjectBuilder) -> String {
+ format!("\
+{compiling} {name} v{version} ({url})
+{running} `rustc {dir}{sep}src{sep}lib.rs --crate-name {name} --crate-type lib -g \
+ -C metadata=[..] \
+ -C extra-filename=-[..] \
+ --out-dir {dir}{sep}target \
+ --dep-info [..] \
+ -L {dir}{sep}target \
+ -L {dir}{sep}target{sep}deps`
+",
+ running = RUNNING, compiling = COMPILING, sep = path::SEP,
+ dir = p.root().display(), url = p.url(),
+ name = "foo", version = "0.0.1")
+}
+
+test!(build_lib_only {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+
+ name = "foo"
+ version = "0.0.1"
+ authors = ["wycats@example.com"]
+ "#)
+ .file("src/main.rs", r#"
+ fn main() {}
+ "#)
+ .file("src/lib.rs", r#" "#);
+
+ assert_that(p.cargo_process("build").arg("--lib").arg("-v"),
+ execs()
+ .with_status(0)
+ .with_stdout(verbose_output_for_lib(&p)));
+})
+
+
+test!(build_with_no_lib {
+ let p = project("foo")
+ .file("Cargo.toml", basic_bin_manifest("foo"))
+ .file("src/main.rs", r#"
+ fn main() {}
+ "#);
+
+ assert_that(p.cargo_process("build").arg("--lib"),
+ execs()
+ .with_status(101)
+ .with_stderr("There is no lib to build, remove `--lib` flag"));
+})
mod test_cargo;
mod test_cargo_bench;
+mod test_cargo_build_lib;
mod test_cargo_clean;
mod test_cargo_compile;
mod test_cargo_compile_custom_build;