allow passing flags directly to cargo

This commit is contained in:
Zeyi Fan 2019-07-28 18:37:50 -07:00
parent 961b74b95e
commit 85153b08ef
2 changed files with 8 additions and 2 deletions

View file

@ -121,6 +121,7 @@ fn run_cargo_build(
toolchain: Option<String>,
project: &PathBuf,
release: bool,
cargo_option: &str,
) -> Result<ExitStatus, CargoPlayError> {
let mut cargo = Command::new("cargo");
@ -131,7 +132,9 @@ fn run_cargo_build(
let cargo = cargo
.arg("run")
.arg("--manifest-path")
.arg(project.join("Cargo.toml"));
.arg(project.join("Cargo.toml"))
// FIXME: proper escaping
.args(cargo_option.split_ascii_whitespace());
if release {
cargo.arg("--release");
@ -186,7 +189,7 @@ fn main() -> Result<(), CargoPlayError> {
write_cargo_toml(&temp, src_hash.clone(), dependencies, opt.edition)?;
copy_sources(&temp, &opt.src)?;
match run_cargo_build(opt.toolchain, &temp, opt.release)?.code() {
match run_cargo_build(opt.toolchain, &temp, opt.release, &opt.cargo_option)?.code() {
Some(code) => std::process::exit(code),
None => std::process::exit(-1),
}

View file

@ -68,6 +68,9 @@ pub(crate) struct Opt {
pub release: bool,
#[structopt(long = "cached", hidden = true)]
pub cached: bool,
#[structopt(long = "cargo-option")]
/// Custom flags passing to cargo
pub cargo_option: String,
#[structopt(multiple = true, last = true)]
/// Arguments passed to the underlying program
pub args: Vec<String>,