v.builder: fix building with -cc msvc and non ASCII characters in paths on windows 11 (#22410)

This commit is contained in:
Delyan Angelov 2024-10-05 02:20:15 +03:00 committed by GitHub
parent dc6a9583d7
commit 209c30f3a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 3 deletions

View file

@ -191,6 +191,8 @@ pub fn utf8_str_visible_length(s string) int {
pub fn string_to_ansi_not_null_terminated(_str string) []u8 {
wstr := _str.to_wide()
mut ansi := wide_to_ansi(wstr)
ansi.pop() // remove tailing zero
if ansi.len > 0 {
unsafe { ansi.len-- } // remove tailing zero
}
return ansi
}

View file

@ -355,9 +355,9 @@ pub fn (mut v Builder) cc_msvc() {
a << env_ldflags
}
v.dump_c_options(a)
args := a.join(' ')
args := '\xEF\xBB\xBF' + a.join(' ')
// write args to a file so that we dont smash createprocess
os.write_file_array(out_name_cmd_line, string_to_ansi_not_null_terminated(args)) or {
os.write_file(out_name_cmd_line, args) or {
verror('Unable to write response file to "${out_name_cmd_line}"')
}
cmd := '"${r.full_cl_exe_path}" "@${out_name_cmd_line}"'