Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command run-custom-build. #13676

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/bin/cargo/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub fn builtin() -> Vec<Command> {
add::cli(),
bench::cli(),
build::cli(),
run_custom_build::cli(),
check::cli(),
clean::cli(),
config::cli(),
Expand Down Expand Up @@ -50,6 +51,7 @@ pub fn builtin_exec(cmd: &str) -> Option<Exec> {
"add" => add::exec,
"bench" => bench::exec,
"build" => build::exec,
"run-custom-build" => run_custom_build::exec,
"check" => check::exec,
"clean" => clean::exec,
"config" => config::exec,
Expand Down Expand Up @@ -117,6 +119,7 @@ pub mod read_manifest;
pub mod remove;
pub mod report;
pub mod run;
pub mod run_custom_build;
pub mod rustc;
pub mod rustdoc;
pub mod search;
Expand Down
48 changes: 48 additions & 0 deletions src/bin/cargo/commands/run_custom_build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::command_prelude::*;

use cargo::ops;

pub fn cli() -> Command {
subcommand("run-custom-build")
.about("Run build script build.rs")
.arg_message_format()
.arg_silent_suggestion()
.arg_package_spec(
"Package to build (see `cargo help pkgid`)",
"Build all packages in the workspace",
"Exclude packages from the build",
)
.arg_features()
.arg_redundant_default_mode("debug", "build", "release")
.arg_parallel()
.arg_target_dir()
.arg_build_plan()
.arg_unit_graph()
.arg_timings()
.arg_manifest_path()
.after_help(color_print::cstr!(
"Run `<cyan,bold>cargo help run-custom-build</>` for more detailed information.\n"
))
}

pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let ws = args.workspace(gctx)?;
let mut compile_opts = args.compile_options(
gctx,
CompileMode::RunCustomBuild,
Some(&ws),
ProfileChecking::Custom,
)?;

if let Some(out_dir) = args.value_of_path("out-dir", gctx) {
compile_opts.build_config.export_dir = Some(out_dir);
} else if let Some(out_dir) = gctx.build_config()?.out_dir.as_ref() {
let out_dir = out_dir.resolve_path(gctx);
compile_opts.build_config.export_dir = Some(out_dir);
}
if compile_opts.build_config.export_dir.is_some() {
gctx.cli_unstable().fail_if_stable_opt("--out-dir", 6790)?;
}
ops::compile(&ws, &compile_opts)?;
Ok(())
}
2 changes: 1 addition & 1 deletion src/cargo/ops/cargo_compile/compile_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ impl CompileFilter {
..
} => examples.is_specific() || tests.is_specific() || benches.is_specific(),
},
CompileMode::RunCustomBuild => panic!("Invalid mode"),
CompileMode::RunCustomBuild => true,
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/cargo/ops/cargo_compile/unit_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ impl<'a> UnitGenerator<'a, '_> {
target: &Target,
initial_target_mode: CompileMode,
) -> Vec<Unit> {
// Custom build units are added in `build_unit_dependencies`.
assert!(!target.is_custom_build());
let target_mode = match initial_target_mode {
CompileMode::Test => {
if target.is_example() && !self.filter.is_specific() && !target.tested() {
Expand Down Expand Up @@ -202,7 +200,8 @@ impl<'a> UnitGenerator<'a, '_> {
})
.collect()
}
CompileMode::Doctest | CompileMode::RunCustomBuild | CompileMode::Docscrape => {
CompileMode::RunCustomBuild => targets.iter().filter(|t| t.is_custom_build()).collect(),
CompileMode::Doctest | CompileMode::Docscrape => {
panic!("Invalid mode {:?}", self.mode)
}
}
Expand Down