1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
use build::context::BuildContext;
use itertools::Itertools;
use retrieve::cache::{Binary, OutputLayout};
use std::{
path::{Path, PathBuf},
process::Output,
};
use util::{clear_dir, copy_dir, errors::Res, fmt_output};
#[derive(Debug)]
pub struct CompileInvocation<'a> {
pub src: &'a Path,
pub deps: &'a [&'a Binary],
pub targets: &'a [PathBuf],
pub build: &'a Path,
pub args: &'a [String],
}
impl<'a> CompileInvocation<'a> {
pub fn exec(&self, bcx: &BuildContext) -> Res<Output> {
clear_dir(&self.build)?;
copy_dir(&self.src, &self.build)?;
let mut process = bcx.compiler.process();
process.current_dir(&self.build).arg("--check");
for binary in self.deps {
process.arg("-i").arg(binary.target.path());
}
process.args(self.args);
for target in self.targets {
process.arg(target);
}
let res = process.output()?;
if !res.status.success() {
bail!("[cmd] {:#?}\n{}", process, fmt_output(&res))
}
Ok(res)
}
}
#[derive(Debug)]
pub struct CodegenInvocation<'a> {
pub binary: &'a [PathBuf],
pub output: &'a str,
pub layout: &'a OutputLayout,
pub is_artifact: bool,
pub args: &'a [String],
}
impl<'a> CodegenInvocation<'a> {
pub fn exec(self, bcx: &BuildContext) -> Res<Output> {
let mut process = bcx.compiler.process();
let cwd;
if self.is_artifact {
process.arg("--interface");
}
process
.current_dir(if self.is_artifact {
cwd = self.layout.artifacts.join(&bcx.backend.name);
&cwd
} else {
&self.layout.bin
}).args(&["-o", &self.output])
.args(&[
if bcx.backend.portable {
"--portable-codegen"
} else {
"--codegen"
},
&bcx.backend.name,
]);
if !bcx.backend.opts.is_empty() {
process
.arg("--cg-opt")
.arg(bcx.backend.opts.iter().join(" "));
}
process.args(self.args);
for bin in self.binary {
process.arg(bin);
}
let res = process.output()?;
if !res.stdout.is_empty() {
bail!("[cmd] {:#?}\n{}", process, fmt_output(&res))
}
Ok(res)
}
}