]>
Commit | Line | Data |
---|---|---|
7acd343b | 1 | use command_prelude::*; |
8e8e924e | 2 | |
6b9c063b AK |
3 | use cargo::ops::{self, CompileMode}; |
4 | ||
8e8e924e AK |
5 | pub fn cli() -> App { |
6 | subcommand("rustc") | |
7 | .setting(AppSettings::TrailingVarArg) | |
8 | .about("Compile a package and all of its dependencies") | |
9 | .arg(Arg::with_name("args").multiple(true)) | |
ce249e32 | 10 | .arg_single_package("Package to build") |
8e8e924e AK |
11 | .arg_jobs() |
12 | .arg_targets_all( | |
13 | "Build only this package's library", | |
14 | "Build only the specified binary", | |
15 | "Build all binaries", | |
16 | "Build only the specified example", | |
17 | "Build all examples", | |
18 | "Build only the specified test target", | |
19 | "Build all tests", | |
20 | "Build only the specified bench target", | |
21 | "Build all benches", | |
22 | "Build all targets (lib and bin targets by default)", | |
23 | ) | |
24 | .arg_release("Build artifacts in release mode, with optimizations") | |
1e682848 | 25 | .arg(opt("profile", "Profile to build the selected target for").value_name("PROFILE")) |
8e8e924e AK |
26 | .arg_features() |
27 | .arg_target_triple("Target triple which compiles will be for") | |
28 | .arg_manifest_path() | |
29 | .arg_message_format() | |
1e682848 AC |
30 | .after_help( |
31 | "\ | |
8e8e924e AK |
32 | The specified target for the current package (or package specified by SPEC if |
33 | provided) will be compiled along with all of its dependencies. The specified | |
34 | <args>... will all be passed to the final compiler invocation, not any of the | |
35 | dependencies. Note that the compiler will still unconditionally receive | |
36 | arguments such as -L, --extern, and --crate-type, and the specified <args>... | |
37 | will simply be added to the compiler invocation. | |
38 | ||
39 | This command requires that only one target is being compiled. If more than one | |
40 | target is available for the current package the filters of --lib, --bin, etc, | |
41 | must be used to select which target is compiled. To pass flags to all compiler | |
42 | processes spawned by Cargo, use the $RUSTFLAGS environment variable or the | |
43 | `build.rustflags` configuration option. | |
1e682848 AC |
44 | ", |
45 | ) | |
8e8e924e | 46 | } |
6b9c063b AK |
47 | |
48 | pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { | |
49 | let ws = args.workspace(config)?; | |
50 | let mode = match args.value_of("profile") { | |
51 | Some("dev") | None => CompileMode::Build, | |
52 | Some("test") => CompileMode::Test, | |
53 | Some("bench") => CompileMode::Bench, | |
54 | Some("check") => CompileMode::Check { test: false }, | |
55 | Some(mode) => { | |
1e682848 AC |
56 | let err = format_err!( |
57 | "unknown profile: `{}`, use dev, | |
58 | test, or bench", | |
59 | mode | |
60 | ); | |
6b9c063b AK |
61 | return Err(CliError::new(err, 101)); |
62 | } | |
63 | }; | |
1e682848 | 64 | let mut compile_opts = args.compile_options_for_single_package(config, mode)?; |
6b9c063b AK |
65 | compile_opts.target_rustc_args = Some(values(args, "args")); |
66 | ops::compile(&ws, &compile_opts)?; | |
67 | Ok(()) | |
68 | } |