@@ -12,7 +12,7 @@ const cc_ldflags = os.getenv_opt('LDFLAGS') or { '' }
12
12
const cc_cflags = os.getenv_opt ('CFLAGS' ) or { '' }
13
13
const cc_cflags_opt = os.getenv_opt ('CFLAGS_OPT' ) or { '' } // '-O3' }
14
14
15
- fn parallel_cc (mut b builder.Builder, result c.GenOutput) {
15
+ fn parallel_cc (mut b builder.Builder, result c.GenOutput) ! {
16
16
tmp_dir := os.vtmp_dir ()
17
17
sw_total := time.new_stopwatch ()
18
18
defer {
@@ -94,25 +94,37 @@ fn parallel_cc(mut b builder.Builder, result c.GenOutput) {
94
94
for postfix in o_postfixes {
95
95
cmds << '${cc} ${cc_cflags} ${cc_cflags_opt} ${scompile_args} -w -o ${tmp_dir} /out_${postfix} .o -c ${tmp_dir} /out_${postfix} .c'
96
96
}
97
+ mut failed := 0
97
98
sw := time.new_stopwatch ()
98
99
mut pp := pool.new_pool_processor (callback: build_parallel_o_cb)
99
100
pp.set_max_jobs (util.nr_jobs)
100
101
pp.work_on_items (cmds)
101
- eprint_time (sw, 'C compilation on ${util.nr_jobs} thread(s), processing ${cmds.len} commands' )
102
+ for x in pp.get_results[os.Result]() {
103
+ failed + = if x.exit_code == 0 { 0 } else { 1 }
104
+ }
105
+ eprint_time (sw, 'C compilation on ${util.nr_jobs} thread(s), processing ${cmds.len} commands, failed: ${failed} ' )
106
+ if failed > 0 {
107
+ return error_with_code ('failed parallel C compilation' , failed)
108
+ }
102
109
103
110
obj_files := fnames.map (it .replace ('.c' , '.o' )).join (' ' )
104
111
link_cmd := '${cc} ${scompile_args_for_linker} -o ${os.quoted_path(b.pref.out_name)} ${tmp_dir} /out_0.o ${obj_files} ${tmp_dir} /out_x.o ${slinker_args} ${cc_ldflags} '
105
112
sw_link := time.new_stopwatch ()
106
113
link_res := os.execute (link_cmd)
107
114
eprint_result_time (sw_link, 'link_cmd' , link_cmd, link_res)
115
+ if link_res.exit_code != 0 {
116
+ return error_with_code ('failed to link after parallel C compilation' , 1 )
117
+ }
108
118
}
109
119
110
- fn build_parallel_o_cb (mut p pool.PoolProcessor, idx int , _wid int ) voidptr {
120
+ fn build_parallel_o_cb (mut p pool.PoolProcessor, idx int , _wid int ) & os.Result {
111
121
cmd := p.get_item[string ](idx)
112
122
sw := time.new_stopwatch ()
113
123
res := os.execute (cmd)
114
124
eprint_result_time (sw, 'cc_cmd' , cmd, res)
115
- return unsafe { nil }
125
+ return & os.Result{
126
+ ...res
127
+ }
116
128
}
117
129
118
130
fn eprint_result_time (sw time.StopWatch, label string , cmd string , res os.Result) {
0 commit comments