cargo/src/bin/cargo/commands/rustc.rs

101 lines
3.3 KiB
Rust
Raw Normal View History

2018-12-06 19:17:36 +00:00
use crate::command_prelude::*;
2018-04-14 08:47:58 +00:00
use cargo::ops;
use cargo::util::interning::InternedString;
2018-03-12 21:06:04 +00:00
const PRINT_ARG_NAME: &str = "print";
const CRATE_TYPE_ARG_NAME: &str = "crate-type";
pub fn cli() -> Command {
2018-03-08 10:05:49 +00:00
subcommand("rustc")
.about("Compile a package, and pass extra options to the compiler")
.arg_quiet()
2022-09-28 18:32:27 +00:00
.arg(
Arg::new("args")
.num_args(0..)
.help("Rustc flags")
.trailing_var_arg(true),
)
.arg_package("Package to build")
2018-03-08 10:05:49 +00:00
.arg_jobs()
.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",
"Build all tests",
"Build only the specified bench target",
"Build all benches",
"Build all targets",
2018-03-08 10:05:49 +00:00
)
.arg_release("Build artifacts in release mode, with optimizations")
.arg_profile("Build artifacts with the specified profile")
2018-03-08 10:05:49 +00:00
.arg_features()
.arg_target_triple("Target triple which compiles will be for")
.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_target_dir()
2018-03-08 10:05:49 +00:00
.arg_manifest_path()
.arg_message_format()
2020-03-08 22:12:18 +00:00
.arg_unit_graph()
.arg_ignore_rust_version()
Implement future incompatibility report support cc rust-lang/rust#71249 This implements the Cargo side of 'Cargo report future-incompat' Based on feedback from alexcrichton and est31, I'm implemented this a flag `--future-compat-report` on `cargo check/build/rustc`, rather than a separate `cargo describe-future-incompatibilities` command. This allows us to avoid writing additional information to disk (beyond the pre-existing recording of rustc command outputs). This PR contains: * Gating of all functionality behind `-Z report-future-incompat`. Without this flag, all user output is unchanged. * Passing `-Z emit-future-incompat-report` to rustc when `-Z report-future-incompat` is enabled * Parsing the rustc JSON future incompat report, and displaying it it a user-readable format. * Emitting a warning at the end of a build if any crates had future-incompat reports * A `--future-incompat-report` flag, which shows the full report for each affected crate. * Tests for all of the above. At the moment, we can use the `array_into_iter` to write a test. However, we might eventually get to a point where rustc is not currently emitting future-incompat reports for any lints. What would we want the cargo tests to do in this situation? This functionality didn't require any significant internal changes to Cargo, with one exception: we now process captured command output for all units, not just ones where we want to display warnings. This may result in a slightly longer time to run `cargo build/check/rustc` from a full cache. since we do slightly more work for each upstream dependency. Doing this seems unavoidable with the current architecture, since we need to process captured command outputs to detect any future-incompat-report messages that were emitted.
2020-10-29 21:48:09 +00:00
.arg_future_incompat_report()
.arg_timings()
.after_help("Run `cargo help rustc` for more detailed information.\n")
2018-03-08 10:05:49 +00:00
}
2018-03-12 21:06:04 +00:00
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
2018-03-12 21:06:04 +00:00
let ws = args.workspace(config)?;
// 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.
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 },
_ => CompileMode::Build,
2018-03-12 21:06:04 +00:00
};
let mut compile_opts = args.compile_options_for_single_package(
config,
mode,
Some(&ws),
ProfileChecking::LegacyRustc,
)?;
if compile_opts.build_config.requested_profile == "check" {
compile_opts.build_config.requested_profile = InternedString::new("dev");
}
let target_args = values(args, "args");
compile_opts.target_rustc_args = if target_args.is_empty() {
None
} else {
Some(target_args)
};
if let Some(opt_value) = args.get_one::<String>(PRINT_ARG_NAME) {
2021-01-08 18:31:19 +00:00
config
.cli_unstable()
.fail_if_stable_opt(PRINT_ARG_NAME, 9357)?;
ops::print(&ws, &compile_opts, opt_value)?;
return Ok(());
}
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(())
}