-
-
Save Dirbaio/115eb27f57da55fb1b73496893ea3209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::Arc; | |
use crate::command_prelude::*; | |
use cargo::{ | |
core::{ | |
compiler::{BuildContext, Context, DefaultExecutor, Executor, UnitInterner}, | |
Workspace, | |
}, | |
ops::{self, CompileOptions}, | |
util::profile, | |
}; | |
pub fn cli() -> App { | |
subcommand("multi").arg(Arg::with_name("args").multiple(true)) | |
} | |
pub fn exec(config: &mut Config, args: &ArgMatches<'_>) -> CliResult { | |
let args: Vec<_> = args.values_of("args").unwrap().collect(); | |
struct Command<'a> { | |
ws: Workspace<'a>, | |
compile_opts: CompileOptions, | |
} | |
let mut cmds = Vec::new(); | |
for args in args.split(|x| *x == "---") { | |
let cli = super::build::cli(); | |
let args = cli.get_matches_from_safe(args)?; | |
println!("args opts: {:#?}", args); | |
let ws = args.workspace(config)?; | |
let mut compile_opts = args.compile_options( | |
config, | |
CompileMode::Build, | |
Some(&ws), | |
ProfileChecking::Custom, | |
)?; | |
if let Some(out_dir) = args.value_of_path("out-dir", config) { | |
compile_opts.build_config.export_dir = Some(out_dir); | |
} else if let Some(out_dir) = config.build_config()?.out_dir.as_ref() { | |
let out_dir = out_dir.resolve_path(config); | |
compile_opts.build_config.export_dir = Some(out_dir); | |
} | |
//if compile_opts.build_config.export_dir.is_some() { | |
// config | |
// .cli_unstable() | |
// .fail_if_stable_opt("--out-dir", 6790)?; | |
//} | |
//println!("compile opts: {:#?}", compile_opts); | |
cmds.push(Command { ws, compile_opts }); | |
} | |
let interner = UnitInterner::new(); | |
let mut merged_bcx: Option<BuildContext<'_, '_>> = None; | |
for cmd in &cmds { | |
let bcx = ops::create_bcx(&cmd.ws, &cmd.compile_opts, &interner).unwrap(); | |
if let Some(merged_bcx) = &mut merged_bcx { | |
// merge!!! | |
merged_bcx.unit_graph.extend(bcx.unit_graph); | |
merged_bcx.roots.extend(bcx.roots); | |
} else { | |
merged_bcx = Some(bcx) | |
} | |
} | |
let bcx = merged_bcx.unwrap(); | |
//if true { | |
// unit_graph::emit_serialized_unit_graph(&bcx.roots, &bcx.unit_graph, ws.config())?; | |
// return Ok(()); | |
//} | |
let _p = profile::start("compiling"); | |
let cx = Context::new(&bcx)?; | |
let exec: Arc<dyn Executor> = Arc::new(DefaultExecutor); | |
cx.compile(&exec)?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment