]>
Commit | Line | Data |
---|---|---|
7acd343b | 1 | use command_prelude::*; |
8e8e924e | 2 | |
293a2a7f | 3 | use cargo::ops; |
6b9c063b | 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)) | |
70ff33a5 | 10 | .arg_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", | |
3a1cad6f | 22 | "Build all targets", |
8e8e924e AK |
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") | |
dd0b7a2c | 28 | .arg_target_dir() |
8e8e924e AK |
29 | .arg_manifest_path() |
30 | .arg_message_format() | |
1e682848 AC |
31 | .after_help( |
32 | "\ | |
8e8e924e AK |
33 | The specified target for the current package (or package specified by SPEC if |
34 | provided) will be compiled along with all of its dependencies. The specified | |
35 | <args>... will all be passed to the final compiler invocation, not any of the | |
36 | dependencies. Note that the compiler will still unconditionally receive | |
37 | arguments such as -L, --extern, and --crate-type, and the specified <args>... | |
38 | will simply be added to the compiler invocation. | |
39 | ||
40 | This command requires that only one target is being compiled. If more than one | |
41 | target is available for the current package the filters of --lib, --bin, etc, | |
42 | must be used to select which target is compiled. To pass flags to all compiler | |
43 | processes spawned by Cargo, use the $RUSTFLAGS environment variable or the | |
44 | `build.rustflags` configuration option. | |
1e682848 AC |
45 | ", |
46 | ) | |
8e8e924e | 47 | } |
6b9c063b AK |
48 | |
49 | pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { | |
50 | let ws = args.workspace(config)?; | |
51 | let mode = match args.value_of("profile") { | |
52 | Some("dev") | None => CompileMode::Build, | |
53 | Some("test") => CompileMode::Test, | |
54 | Some("bench") => CompileMode::Bench, | |
55 | Some("check") => CompileMode::Check { test: false }, | |
56 | Some(mode) => { | |
1e682848 AC |
57 | let err = format_err!( |
58 | "unknown profile: `{}`, use dev, | |
59 | test, or bench", | |
60 | mode | |
61 | ); | |
6b9c063b AK |
62 | return Err(CliError::new(err, 101)); |
63 | } | |
64 | }; | |
1e682848 | 65 | let mut compile_opts = args.compile_options_for_single_package(config, mode)?; |
3e07a3e6 XL |
66 | let target_args = values(args, "args"); |
67 | compile_opts.target_rustc_args = if target_args.is_empty() { | |
68 | None | |
69 | } else { | |
70 | Some(target_args) | |
71 | }; | |
6b9c063b AK |
72 | ops::compile(&ws, &compile_opts)?; |
73 | Ok(()) | |
74 | } |