Skip to content

Commit 4ddedff

Browse files
authored
Merge pull request #5303 from ChrisCatCP/vs_unicode
fix msvc output when toolset less than 8.0
2 parents 0bf2063 + a2558e3 commit 4ddedff

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

xmake/modules/private/tools/vstool.lua

+14-2
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ function runv(program, argv, opt)
2424
-- init options
2525
opt = opt or {}
2626

27+
-- if has VS_BINARY_OUTPUT dont enable unicode output
28+
local envs = opt.envs or {}
29+
if envs.VS_BINARY_OUTPUT then
30+
return os.runv(program, argv, opt)
31+
end
32+
2733
-- make temporary output and error file
2834
local outpath = os.tmpfile()
2935
local errpath = os.tmpfile()
3036
local outfile = io.open(outpath, 'w')
3137

3238
-- enable unicode output for vs toolchains, e.g. cl.exe, link.exe and etc.
3339
-- @see https://github.com/xmake-io/xmake/issues/528
34-
opt.envs = table.join(opt.envs or {}, {VS_UNICODE_OUTPUT = outfile:rawfd()})
40+
opt.envs = table.join(envs, {VS_UNICODE_OUTPUT = outfile:rawfd()})
3541

3642
-- execute it
3743
local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath}))
@@ -85,6 +91,12 @@ function iorunv(program, argv, opt)
8591

8692
-- init options
8793
opt = opt or {}
94+
95+
-- if has VS_BINARY_OUTPUT dont enable unicode output
96+
local envs = opt.envs or {}
97+
if envs.VS_BINARY_OUTPUT then
98+
return os.runv(program, argv, opt)
99+
end
88100

89101
-- make temporary output and error file
90102
local outpath = os.tmpfile()
@@ -93,7 +105,7 @@ function iorunv(program, argv, opt)
93105

94106
-- enable unicode output for vs toolchains, e.g. cl.exe, link.exe and etc.
95107
-- @see https://github.com/xmake-io/xmake/issues/528
96-
opt.envs = table.join(opt.envs or {}, {VS_UNICODE_OUTPUT = outfile:rawfd()})
108+
opt.envs = table.join(envs, {VS_UNICODE_OUTPUT = outfile:rawfd()})
97109

98110
-- run command
99111
local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath}))

xmake/toolchains/msvc/load.lua

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
-- imports
2222
import("core.base.option")
23+
import("core.base.semver")
2324
import("core.project.config")
2425
import("detect.sdks.find_vstudio")
2526

@@ -78,5 +79,11 @@ function main(toolchain)
7879
_add_vsenv(toolchain, name, curenvs)
7980
end
8081
end
82+
83+
-- check and add vs_binary_output env
84+
local vs = toolchain:config("vs")
85+
if vs and semver.is_valid(vs) and semver.compare(vs, "2005") < 0 then
86+
toolchain:add("runenvs", "VS_BINARY_OUTPUT", "1")
87+
end
8188
end
8289

0 commit comments

Comments
 (0)