2018-12-06 19:17:36 +00:00
|
|
|
use crate::command_prelude::*;
|
2018-04-14 08:47:58 +00:00
|
|
|
use cargo::ops;
|
2021-07-13 22:22:09 +00:00
|
|
|
use cargo::util::interning::InternedString;
|
2018-03-12 21:06:04 +00:00
|
|
|
|
2021-01-30 16:46:23 +00:00
|
|
|
const PRINT_ARG_NAME: &str = "print";
|
2021-11-17 12:34:44 +00:00
|
|
|
const CRATE_TYPE_ARG_NAME: &str = "crate-type";
|
2021-01-08 17:53:01 +00:00
|
|
|
|
2022-09-20 18:28:34 +00:00
|
|
|
pub fn cli() -> Command {
|
2018-03-08 10:05:49 +00:00
|
|
|
subcommand("rustc")
|
2020-02-17 02:11:27 +00:00
|
|
|
.about("Compile a package, and pass extra options to the compiler")
|
2022-09-28 18:32:27 +00:00
|
|
|
.arg(
|
|
|
|
Arg::new("args")
|
2023-10-17 20:25:52 +00:00
|
|
|
.value_name("ARGS")
|
2022-09-28 18:32:27 +00:00
|
|
|
.num_args(0..)
|
2023-02-19 21:53:53 +00:00
|
|
|
.help("Extra rustc flags")
|
2022-09-28 18:32:27 +00:00
|
|
|
.trailing_var_arg(true),
|
|
|
|
)
|
2023-03-28 10:39:43 +00:00
|
|
|
.arg(
|
|
|
|
opt(
|
|
|
|
PRINT_ARG_NAME,
|
|
|
|
"Output compiler information without compiling",
|
|
|
|
)
|
|
|
|
.value_name("INFO"),
|
|
|
|
)
|
|
|
|
.arg(multi_opt(
|
|
|
|
CRATE_TYPE_ARG_NAME,
|
|
|
|
"CRATE-TYPE",
|
|
|
|
"Comma separated list of types of crates for the compiler to emit",
|
|
|
|
))
|
|
|
|
.arg_future_incompat_report()
|
|
|
|
.arg_message_format()
|
2023-11-11 23:55:30 +00:00
|
|
|
.arg_silent_suggestion()
|
2018-03-16 14:35:13 +00:00
|
|
|
.arg_package("Package to build")
|
2018-03-08 10:05:49 +00:00
|
|
|
.arg_targets_all(
|
|
|
|
"Build only this package's library",
|
|
|
|
"Build only the specified binary",
|
|
|
|
"Build all binaries",
|
|
|
|
"Build only the specified example",
|
|
|
|
"Build all examples",
|
|
|
|
"Build only the specified test target",
|
2023-11-03 20:45:00 +00:00
|
|
|
"Build all test targets",
|
2018-03-08 10:05:49 +00:00
|
|
|
"Build only the specified bench target",
|
2023-11-03 20:45:00 +00:00
|
|
|
"Build all bench targets",
|
2018-09-17 02:41:57 +00:00
|
|
|
"Build all targets",
|
2018-03-08 10:05:49 +00:00
|
|
|
)
|
2023-03-28 10:39:43 +00:00
|
|
|
.arg_features()
|
2023-08-18 09:50:40 +00:00
|
|
|
.arg_parallel()
|
2018-03-08 10:05:49 +00:00
|
|
|
.arg_release("Build artifacts in release mode, with optimizations")
|
2018-04-09 20:09:11 +00:00
|
|
|
.arg_profile("Build artifacts with the specified profile")
|
2018-03-08 10:05:49 +00:00
|
|
|
.arg_target_triple("Target triple which compiles will be for")
|
2018-04-16 23:50:30 +00:00
|
|
|
.arg_target_dir()
|
2020-03-08 22:12:18 +00:00
|
|
|
.arg_unit_graph()
|
2022-01-02 02:47:04 +00:00
|
|
|
.arg_timings()
|
2023-03-28 10:39:43 +00:00
|
|
|
.arg_manifest_path()
|
2024-04-11 18:40:57 +00:00
|
|
|
.arg_ignore_rust_version()
|
2023-08-28 17:05:19 +00:00
|
|
|
.after_help(color_print::cstr!(
|
|
|
|
"Run `<cyan,bold>cargo help rustc</>` for more detailed information.\n"
|
|
|
|
))
|
2018-03-08 10:05:49 +00:00
|
|
|
}
|
2018-03-12 21:06:04 +00:00
|
|
|
|
2024-02-06 22:28:07 +00:00
|
|
|
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
|
|
|
|
let ws = args.workspace(gctx)?;
|
2021-07-13 22:22:09 +00:00
|
|
|
// This is a legacy behavior that changes the behavior based on the profile.
|
|
|
|
// If we want to support this more formally, I think adding a --mode flag
|
|
|
|
// would be warranted.
|
2022-06-08 20:16:51 +00:00
|
|
|
let mode = match args.get_one::<String>("profile").map(String::as_str) {
|
2018-03-12 21:06:04 +00:00
|
|
|
Some("test") => CompileMode::Test,
|
|
|
|
Some("bench") => CompileMode::Bench,
|
|
|
|
Some("check") => CompileMode::Check { test: false },
|
2021-07-13 22:22:09 +00:00
|
|
|
_ => CompileMode::Build,
|
2018-03-12 21:06:04 +00:00
|
|
|
};
|
2019-06-20 15:32:28 +00:00
|
|
|
let mut compile_opts = args.compile_options_for_single_package(
|
2024-02-06 22:28:07 +00:00
|
|
|
gctx,
|
2019-06-20 16:43:33 +00:00
|
|
|
mode,
|
|
|
|
Some(&ws),
|
2021-07-13 22:22:09 +00:00
|
|
|
ProfileChecking::LegacyRustc,
|
2019-06-20 16:43:33 +00:00
|
|
|
)?;
|
2021-07-13 22:22:09 +00:00
|
|
|
if compile_opts.build_config.requested_profile == "check" {
|
|
|
|
compile_opts.build_config.requested_profile = InternedString::new("dev");
|
|
|
|
}
|
2018-03-14 14:50:09 +00:00
|
|
|
let target_args = values(args, "args");
|
|
|
|
compile_opts.target_rustc_args = if target_args.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(target_args)
|
|
|
|
};
|
2022-06-08 20:16:51 +00:00
|
|
|
if let Some(opt_value) = args.get_one::<String>(PRINT_ARG_NAME) {
|
2024-02-06 22:28:07 +00:00
|
|
|
gctx.cli_unstable()
|
2021-05-04 15:55:23 +00:00
|
|
|
.fail_if_stable_opt(PRINT_ARG_NAME, 9357)?;
|
2021-01-30 19:09:01 +00:00
|
|
|
ops::print(&ws, &compile_opts, opt_value)?;
|
2021-11-17 12:34:44 +00:00
|
|
|
return Ok(());
|
2021-01-08 17:46:16 +00:00
|
|
|
}
|
2021-11-17 12:34:44 +00:00
|
|
|
let crate_types = values(args, CRATE_TYPE_ARG_NAME);
|
|
|
|
compile_opts.target_rustc_crate_types = if crate_types.is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(crate_types)
|
|
|
|
};
|
|
|
|
ops::compile(&ws, &compile_opts)?;
|
|
|
|
|
2018-03-12 21:06:04 +00:00
|
|
|
Ok(())
|
|
|
|
}
|