|
| 1 | +use std::env; |
| 2 | + |
| 3 | +use cargo::ops::CompileOptions; |
| 4 | +use cargo::ops; |
| 5 | +use cargo::util::important_paths::{find_root_manifest_for_cwd}; |
| 6 | +use cargo::util::{CliResult, CliError, Config}; |
| 7 | + |
| 8 | +#[derive(RustcDecodable)] |
| 9 | +struct Options { |
| 10 | + arg_opts: Option<Vec<String>>, |
| 11 | + flag_package: Option<String>, |
| 12 | + flag_jobs: Option<u32>, |
| 13 | + flag_features: Vec<String>, |
| 14 | + flag_no_default_features: bool, |
| 15 | + flag_target: Option<String>, |
| 16 | + flag_manifest_path: Option<String>, |
| 17 | + flag_verbose: bool, |
| 18 | + flag_release: bool, |
| 19 | + flag_lib: bool, |
| 20 | + flag_bin: Vec<String>, |
| 21 | + flag_example: Vec<String>, |
| 22 | + flag_test: Vec<String>, |
| 23 | + flag_bench: Vec<String>, |
| 24 | +} |
| 25 | + |
| 26 | +pub const USAGE: &'static str = " |
| 27 | +Compile a package and all of its dependencies |
| 28 | +
|
| 29 | +Usage: |
| 30 | + cargo rustc [options] [--] [<opts>...] |
| 31 | +
|
| 32 | +Options: |
| 33 | + -h, --help Print this message |
| 34 | + -p SPEC, --package SPEC The profile to compile for |
| 35 | + -j N, --jobs N The number of jobs to run in parallel |
| 36 | + --lib Build only this package's library |
| 37 | + --bin NAME Build only the specified binary |
| 38 | + --example NAME Build only the specified example |
| 39 | + --test NAME Build only the specified test |
| 40 | + --bench NAME Build only the specified benchmark |
| 41 | + --release Build artifacts in release mode, with optimizations |
| 42 | + --features FEATURES Features to compile for the package |
| 43 | + --no-default-features Do not compile default features for the package |
| 44 | + --target TRIPLE Target triple which compiles will be for |
| 45 | + --manifest-path PATH Path to the manifest to fetch depednencies for |
| 46 | + -v, --verbose Use verbose output |
| 47 | +
|
| 48 | +The specified target for the current package (or package specified by SPEC if |
| 49 | +provided) will be compiled along with all of its dependencies. The specified |
| 50 | +<opts>... will all be passed to the final compiler invocation, not any of the |
| 51 | +dependencies. Note that the compiler will still unconditionally receive |
| 52 | +arguments such as -L, --extern, and --crate-type, and the specified <opts>... |
| 53 | +will simply be added to the compiler invocation. |
| 54 | +
|
| 55 | +This command requires that only one target is being compiled. If more than one |
| 56 | +target is available for the current package the filters of --lib, --bin, etc, |
| 57 | +must be used to select which target is compiled. |
| 58 | +"; |
| 59 | + |
| 60 | +pub fn execute(options: Options, config: &Config) -> CliResult<Option<()>> { |
| 61 | + debug!("executing; cmd=cargo-rustc; args={:?}", |
| 62 | + env::args().collect::<Vec<_>>()); |
| 63 | + config.shell().set_verbose(options.flag_verbose); |
| 64 | + |
| 65 | + let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path)); |
| 66 | + |
| 67 | + let opts = CompileOptions { |
| 68 | + config: config, |
| 69 | + jobs: options.flag_jobs, |
| 70 | + target: options.flag_target.as_ref().map(|t| &t[..]), |
| 71 | + features: &options.flag_features, |
| 72 | + no_default_features: options.flag_no_default_features, |
| 73 | + spec: options.flag_package.as_ref().map(|s| &s[..]), |
| 74 | + exec_engine: None, |
| 75 | + mode: ops::CompileMode::Build, |
| 76 | + release: options.flag_release, |
| 77 | + filter: ops::CompileFilter::new(options.flag_lib, |
| 78 | + &options.flag_bin, |
| 79 | + &options.flag_test, |
| 80 | + &options.flag_example, |
| 81 | + &options.flag_bench), |
| 82 | + target_rustc_args: options.arg_opts.as_ref().map(|a| &a[..]), |
| 83 | + }; |
| 84 | + |
| 85 | + ops::compile(&root, &opts).map(|_| None).map_err(|err| { |
| 86 | + CliError::from_boxed(err, 101) |
| 87 | + }) |
| 88 | +} |
| 89 | + |
| 90 | + |
0 commit comments