Skip to content

Commit 903e349

Browse files
authored
v.builder: fail the whole v compilation, if linking or compiling during -parallel-cc fails (#23211)
1 parent 9ae0a9d commit 903e349

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

vlib/v/builder/cbuilder/cbuilder.v

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn gen_c(mut b builder.Builder, v_files []string) string {
8282
if b.pref.parallel_cc {
8383
b.cc() // Call it just to gen b.str_args
8484
util.timing_start('Parallel C compilation')
85-
parallel_cc(mut b, result)
85+
parallel_cc(mut b, result) or { builder.verror(err.msg()) }
8686
util.timing_measure('Parallel C compilation')
8787
}
8888

vlib/v/builder/cbuilder/parallel_cc.v

+16-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const cc_ldflags = os.getenv_opt('LDFLAGS') or { '' }
1212
const cc_cflags = os.getenv_opt('CFLAGS') or { '' }
1313
const cc_cflags_opt = os.getenv_opt('CFLAGS_OPT') or { '' } // '-O3' }
1414

15-
fn parallel_cc(mut b builder.Builder, result c.GenOutput) {
15+
fn parallel_cc(mut b builder.Builder, result c.GenOutput) ! {
1616
tmp_dir := os.vtmp_dir()
1717
sw_total := time.new_stopwatch()
1818
defer {
@@ -94,25 +94,37 @@ fn parallel_cc(mut b builder.Builder, result c.GenOutput) {
9494
for postfix in o_postfixes {
9595
cmds << '${cc} ${cc_cflags} ${cc_cflags_opt} ${scompile_args} -w -o ${tmp_dir}/out_${postfix}.o -c ${tmp_dir}/out_${postfix}.c'
9696
}
97+
mut failed := 0
9798
sw := time.new_stopwatch()
9899
mut pp := pool.new_pool_processor(callback: build_parallel_o_cb)
99100
pp.set_max_jobs(util.nr_jobs)
100101
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+
}
102109

103110
obj_files := fnames.map(it.replace('.c', '.o')).join(' ')
104111
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}'
105112
sw_link := time.new_stopwatch()
106113
link_res := os.execute(link_cmd)
107114
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+
}
108118
}
109119

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 {
111121
cmd := p.get_item[string](idx)
112122
sw := time.new_stopwatch()
113123
res := os.execute(cmd)
114124
eprint_result_time(sw, 'cc_cmd', cmd, res)
115-
return unsafe { nil }
125+
return &os.Result{
126+
...res
127+
}
116128
}
117129

118130
fn eprint_result_time(sw time.StopWatch, label string, cmd string, res os.Result) {

0 commit comments

Comments
 (0)