@@ -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.
0 commit comments