]> git.proxmox.com Git - cargo.git/blame - src/bin/commands/rustc.rs
Auto merge of #5190 - mbrubeck:doc, r=alexcrichton
[cargo.git] / src / bin / commands / rustc.rs
CommitLineData
7acd343b 1use command_prelude::*;
8e8e924e 2
6b9c063b
AK
3use cargo::ops::{self, CompileMode};
4
8e8e924e
AK
5pub 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
32The specified target for the current package (or package specified by SPEC if
33provided) 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
35dependencies. Note that the compiler will still unconditionally receive
36arguments such as -L, --extern, and --crate-type, and the specified <args>...
37will simply be added to the compiler invocation.
38
39This command requires that only one target is being compiled. If more than one
40target is available for the current package the filters of --lib, --bin, etc,
41must be used to select which target is compiled. To pass flags to all compiler
42processes spawned by Cargo, use the $RUSTFLAGS environment variable or the
43`build.rustflags` configuration option.
1e682848
AC
44",
45 )
8e8e924e 46}
6b9c063b
AK
47
48pub 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}