Skip to content

Commit b1d6b78

Browse files
authored
builder,cgen: fix msvc build filename, remove temp files (#23890)
1 parent 6cda3b0 commit b1d6b78

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

vlib/v/builder/msvc_windows.v

+28-2
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,15 @@ pub fn (mut v Builder) cc_msvc() {
256256
}
257257
out_name_pdb := os.real_path(v.out_name_c + '.pdb')
258258
out_name_cmd_line := os.real_path(v.out_name_c + '.rsp')
259+
// testdll.01JNX9W7JAV4FKMZ6KDXT67QYV.tmp.so.c
260+
app_dir_out_name_c := (v.pref.out_name.all_before_last('\\') + '\\' +
261+
v.pref.out_name_c.all_after_last('\\')).all_before_last('.')
262+
// testdll.dll
263+
app_dir_out_name := if v.pref.out_name.ends_with('.dll') || v.pref.out_name.ends_with('.exe') {
264+
v.pref.out_name[0..v.pref.out_name.len - 4]
265+
} else {
266+
v.pref.out_name
267+
}
259268
mut a := []string{}
260269

261270
env_cflags := os.getenv('CFLAGS')
@@ -282,6 +291,10 @@ pub fn (mut v Builder) cc_msvc() {
282291
} else {
283292
a << '/MD'
284293
a << '/DNDEBUG'
294+
if !v.ccoptions.debug_mode {
295+
v.pref.cleanup_files << out_name_pdb
296+
v.pref.cleanup_files << app_dir_out_name + '.pdb'
297+
}
285298
}
286299
if v.pref.is_shared {
287300
if !v.pref.out_name.ends_with('.dll') {
@@ -319,6 +332,9 @@ pub fn (mut v Builder) cc_msvc() {
319332
// The C file we are compiling
320333
// a << '"$TmpPath/$v.out_name_c"'
321334
a << '"' + os.real_path(v.out_name_c) + '"'
335+
if !v.ccoptions.debug_mode {
336+
v.pref.cleanup_files << os.real_path(v.out_name_c)
337+
}
322338
// Emily:
323339
// Not all of these are needed (but the compiler should discard them if they are not used)
324340
// these are the defaults used by msbuild and visual studio
@@ -340,8 +356,13 @@ pub fn (mut v Builder) cc_msvc() {
340356
if v.pref.is_shared {
341357
// generate a .def for export function names, avoid function name mangle
342358
// must put after the /link flag!
343-
def_name := v.pref.out_name[0..v.pref.out_name.len - 4]
344-
a << '/DEF:' + os.quoted_path('${def_name}.def')
359+
def_name := app_dir_out_name + '.def'
360+
a << '/DEF:' + os.quoted_path(def_name)
361+
if !v.ccoptions.debug_mode {
362+
v.pref.cleanup_files << def_name
363+
v.pref.cleanup_files << app_dir_out_name_c + '.exp'
364+
v.pref.cleanup_files << app_dir_out_name_c + '.lib'
365+
}
345366
}
346367

347368
a << '/nologo' // NOTE: /NOLOGO is explicitly not recognised!
@@ -370,6 +391,11 @@ pub fn (mut v Builder) cc_msvc() {
370391
os.write_file(out_name_cmd_line, args) or {
371392
verror('Unable to write response file to "${out_name_cmd_line}"')
372393
}
394+
if !v.ccoptions.debug_mode {
395+
v.pref.cleanup_files << out_name_cmd_line
396+
v.pref.cleanup_files << app_dir_out_name_c + '.obj'
397+
v.pref.cleanup_files << app_dir_out_name + '.ilk'
398+
}
373399
cmd := '"${r.full_cl_exe_path}" "@${out_name_cmd_line}"'
374400
// It is hard to see it at first, but the quotes above ARE balanced :-| ...
375401
// Also the double quotes at the start ARE needed.

vlib/v/gen/c/cgen.v

+11-4
Original file line numberDiff line numberDiff line change
@@ -726,10 +726,17 @@ pub fn gen(files []&ast.File, mut table ast.Table, pref_ &pref.Preferences) GenO
726726

727727
if g.pref.is_shared && g.pref.os == .windows && g.export_funcs.len > 0 {
728728
// generate a .def for export function names, avoid function name mangle
729-
def_name := g.pref.out_name[0..g.pref.out_name.len - 4]
730-
dll_name := g.pref.out_name.all_after_last('\\')
731-
file_content := 'LIBRARY ${dll_name}.dll\n\nEXPORTS\n' + g.export_funcs.join('\n')
732-
os.write_file('${def_name}.def', file_content) or { panic(err) }
729+
mut def_name := ''
730+
mut dll_name := ''
731+
if g.pref.out_name.ends_with('.dll') {
732+
def_name = g.pref.out_name[0..g.pref.out_name.len - 4] + '.def'
733+
dll_name = g.pref.out_name.all_after_last('\\')
734+
} else {
735+
def_name = g.pref.out_name + '.def'
736+
dll_name = g.pref.out_name.all_after_last('\\') + '.dll'
737+
}
738+
file_content := 'LIBRARY ${dll_name}\n\nEXPORTS\n' + g.export_funcs.join('\n')
739+
os.write_file('${def_name}', file_content) or { panic(err) }
733740
}
734741

735742
// End of out_0.c

0 commit comments

Comments
 (0)