From da2e3b83c53752c43b651effeb273cb72090d7b0 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 20 Jun 2020 16:07:21 +0800 Subject: add runenvs for cl/link --- xmake/modules/core/tools/cl.lua | 3 ++- xmake/modules/core/tools/link.lua | 9 +++++---- xmake/modules/private/tools/vstool.lua | 12 +++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) (limited to 'xmake/modules') diff --git a/xmake/modules/core/tools/cl.lua b/xmake/modules/core/tools/cl.lua index 9f6421c21..3dfa0bb0f 100644 --- a/xmake/modules/core/tools/cl.lua +++ b/xmake/modules/core/tools/cl.lua @@ -353,7 +353,8 @@ function compile(self, sourcefile, objectfile, dependinfo, flags, opt) end -- use vstool to compile and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528 - return vstool.iorunv(compargv(self, sourcefile, objectfile, compflags, opt)) + local program, argv = compargv(self, sourcefile, objectfile, compflags, opt) + return vstool.iorunv(program, argv, {envs = self:runenvs()}) end, catch { diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index 3bcbb238d..8d1f9083d 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -29,10 +29,10 @@ function init(self) self:set("ldflags", "-nologo", "-dynamicbase", "-nxcompat") -- init arflags - self:set("arflags", "-nologo") + self:set("arflags", "-lib", "-nologo") -- init shflags - self:set("shflags", "-nologo") + self:set("shflags", "-dll", "-nologo") -- init flags map self:set("mapflags", @@ -52,7 +52,7 @@ function get(self, name) local values = self._INFO[name] if name == "ldflags" or name == "arflags" or name == "shflags" then -- switch architecture, @note does cache it in init() for generating vs201x project - values = table.join(values, "-machine:" .. (config.arch() or "x86")) + values = table.join(values, "-machine:" .. (self:arch() or "x86")) end return values end @@ -108,7 +108,8 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt) function () -- use vstool to link and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528 - vstool.runv(linkargv(self, objectfiles, targetkind, targetfile, flags, opt)) + local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + vstool.runv(program, argv, {envs = self:runenvs()}) end, catch { diff --git a/xmake/modules/private/tools/vstool.lua b/xmake/modules/private/tools/vstool.lua index e632ed00f..c8f51b11b 100644 --- a/xmake/modules/private/tools/vstool.lua +++ b/xmake/modules/private/tools/vstool.lua @@ -31,10 +31,11 @@ function runv(program, argv, opt) -- enable unicode output for vs toolchains, e.g. cl.exe, link.exe and etc. -- @see https://github.com/xmake-io/xmake/issues/528 - local envs = {VS_UNICODE_OUTPUT = outfile:rawfd()} + opt.envs = opt.envs or {} + opt.envs.VS_UNICODE_OUTPUT = outfile:rawfd() -- execute it - local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath, envs = envs})) + local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath})) -- close outfile first outfile:close() @@ -93,10 +94,11 @@ function iorunv(program, argv, opt) -- enable unicode output for vs toolchains, e.g. cl.exe, link.exe and etc. -- @see https://github.com/xmake-io/xmake/issues/528 - local envs = {VS_UNICODE_OUTPUT = outfile:rawfd()} + opt.envs = opt.envs or {} + opt.envs.VS_UNICODE_OUTPUT = outfile:rawfd() -- run command - local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath, envs = envs})) + local ok, syserrors = os.execv(program, argv, table.join(opt, {try = true, stdout = outfile, stderr = errpath})) -- get output and error data outfile:close() @@ -132,7 +134,7 @@ function iorunv(program, argv, opt) errors = string.format("vstool.iorunv(%s), %s", cmd, syserrors and syserrors or "unknown reason") end end - + -- raise errors os.raise({errors = errors, stderr = errdata, stdout = outdata}) end -- cgit v1.3.1