]>
Commit | Line | Data |
---|---|---|
1 | use crate::command_prelude::*; | |
2 | ||
3 | use cargo::ops; | |
4 | ||
5 | const PRINT_ARG_NAME: &str = "print"; | |
6 | ||
7 | pub fn cli() -> App { | |
8 | subcommand("rustc") | |
9 | .setting(AppSettings::TrailingVarArg) | |
10 | .about("Compile a package, and pass extra options to the compiler") | |
11 | .arg(opt("quiet", "No output printed to stdout").short("q")) | |
12 | .arg(Arg::with_name("args").multiple(true).help("Rustc flags")) | |
13 | .arg_package("Package to build") | |
14 | .arg_jobs() | |
15 | .arg_targets_all( | |
16 | "Build only this package's library", | |
17 | "Build only the specified binary", | |
18 | "Build all binaries", | |
19 | "Build only the specified example", | |
20 | "Build all examples", | |
21 | "Build only the specified test target", | |
22 | "Build all tests", | |
23 | "Build only the specified bench target", | |
24 | "Build all benches", | |
25 | "Build all targets", | |
26 | ) | |
27 | .arg_release("Build artifacts in release mode, with optimizations") | |
28 | .arg_profile("Build artifacts with the specified profile") | |
29 | .arg_features() | |
30 | .arg_target_triple("Target triple which compiles will be for") | |
31 | .arg( | |
32 | opt( | |
33 | PRINT_ARG_NAME, | |
34 | "Output compiler information without compiling", | |
35 | ) | |
36 | .value_name("INFO"), | |
37 | ) | |
38 | .arg_target_dir() | |
39 | .arg_manifest_path() | |
40 | .arg_message_format() | |
41 | .arg_unit_graph() | |
42 | .arg_ignore_rust_version() | |
43 | .arg_future_incompat_report() | |
44 | .after_help("Run `cargo help rustc` for more detailed information.\n") | |
45 | } | |
46 | ||
47 | pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { | |
48 | let ws = args.workspace(config)?; | |
49 | let mode = match args.value_of("profile") { | |
50 | Some("dev") | None => CompileMode::Build, | |
51 | Some("test") => CompileMode::Test, | |
52 | Some("bench") => CompileMode::Bench, | |
53 | Some("check") => CompileMode::Check { test: false }, | |
54 | Some(mode) => { | |
55 | let err = anyhow::format_err!( | |
56 | "unknown profile: `{}`, use dev, | |
57 | test, or bench", | |
58 | mode | |
59 | ); | |
60 | return Err(CliError::new(err, 101)); | |
61 | } | |
62 | }; | |
63 | let mut compile_opts = args.compile_options_for_single_package( | |
64 | config, | |
65 | mode, | |
66 | Some(&ws), | |
67 | ProfileChecking::Unchecked, | |
68 | )?; | |
69 | let target_args = values(args, "args"); | |
70 | compile_opts.target_rustc_args = if target_args.is_empty() { | |
71 | None | |
72 | } else { | |
73 | Some(target_args) | |
74 | }; | |
75 | if let Some(opt_value) = args.value_of(PRINT_ARG_NAME) { | |
76 | config | |
77 | .cli_unstable() | |
78 | .fail_if_stable_opt(PRINT_ARG_NAME, 8923)?; | |
79 | ops::print(&ws, &compile_opts, opt_value)?; | |
80 | } else { | |
81 | ops::compile(&ws, &compile_opts)?; | |
82 | } | |
83 | Ok(()) | |
84 | } |