]> git.proxmox.com Git - cargo.git/blame - src/bin/cargo/commands/rustc.rs
Auto merge of #9186 - weihanglo:issue-9054, r=alexcrichton
[cargo.git] / src / bin / cargo / commands / rustc.rs
CommitLineData
04ddd4d0 1use crate::command_prelude::*;
8e8e924e 2
293a2a7f 3use cargo::ops;
6b9c063b 4
afa1905e 5const PRINT_ARG_NAME: &str = "print";
fc83cbed 6
8e8e924e
AK
7pub fn cli() -> App {
8 subcommand("rustc")
9 .setting(AppSettings::TrailingVarArg)
367fe7bf 10 .about("Compile a package, and pass extra options to the compiler")
e873e4e9 11 .arg(opt("quiet", "No output printed to stdout").short("q"))
367fe7bf 12 .arg(Arg::with_name("args").multiple(true).help("Rustc flags"))
70ff33a5 13 .arg_package("Package to build")
8e8e924e
AK
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",
3a1cad6f 25 "Build all targets",
8e8e924e
AK
26 )
27 .arg_release("Build artifacts in release mode, with optimizations")
86c459d4 28 .arg_profile("Build artifacts with the specified profile")
8e8e924e
AK
29 .arg_features()
30 .arg_target_triple("Target triple which compiles will be for")
13807557
CF
31 .arg(
32 opt(
33 PRINT_ARG_NAME,
34 "Output compiler information without compiling",
35 )
36 .value_name("INFO"),
37 )
dd0b7a2c 38 .arg_target_dir()
8e8e924e
AK
39 .arg_manifest_path()
40 .arg_message_format()
aa80a984 41 .arg_unit_graph()
c221fec9 42 .arg_ignore_rust_version()
6177c658 43 .arg_future_incompat_report()
0e26eae5 44 .after_help("Run `cargo help rustc` for more detailed information.\n")
8e8e924e 45}
6b9c063b 46
6d1d3a68 47pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult {
6b9c063b
AK
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) => {
3a18c89a 55 let err = anyhow::format_err!(
1e682848
AC
56 "unknown profile: `{}`, use dev,
57 test, or bench",
58 mode
59 );
6b9c063b
AK
60 return Err(CliError::new(err, 101));
61 }
62 };
2f81adb1 63 let mut compile_opts = args.compile_options_for_single_package(
29b7e90b
DA
64 config,
65 mode,
66 Some(&ws),
67 ProfileChecking::Unchecked,
68 )?;
3e07a3e6
XL
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 };
13807557 75 if let Some(opt_value) = args.value_of(PRINT_ARG_NAME) {
698fe708
CF
76 config
77 .cli_unstable()
afa1905e 78 .fail_if_stable_opt(PRINT_ARG_NAME, 8923)?;
13807557 79 ops::print(&ws, &compile_opts, opt_value)?;
e078a6c9
CF
80 } else {
81 ops::compile(&ws, &compile_opts)?;
82 }
6b9c063b
AK
83 Ok(())
84}