diff options
| author | ruki <[email protected]> | 2023-01-04 23:01:41 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2023-01-04 23:01:41 +0800 |
| commit | 0ec969792ddf1e9b964c2744f146b53e63f79910 (patch) | |
| tree | c62d6d8add2b2c947ee373a0419b0e4bbd0d53ee | |
| parent | d7b98c9c16ca12c25267c43c6b88ba7645fe5476 (diff) | |
improve link for masm32
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 2 | ||||
| -rw-r--r-- | xmake/languages/asm/xmake.lua | 3 | ||||
| -rw-r--r-- | xmake/modules/core/tools/link.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_link.lua | 38 | ||||
| -rw-r--r-- | xmake/toolchains/masm32/xmake.lua | 1 |
5 files changed, 34 insertions, 19 deletions
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 32507768a..0ee62b34e 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -439,7 +439,7 @@ function _instance:_checktool(toolkind, toolpath) end -- find tool program - local tool = find_tool(toolpath, {cachekey = cachekey, program = program or toolpath, paths = self:bindir(), envs = self:get("runenvs")}) + local tool = find_tool(toolpath, {toolchain = self, cachekey = cachekey, program = program or toolpath, paths = self:bindir(), envs = self:get("runenvs")}) if tool then program = tool.program toolname = toolname or tool.name diff --git a/xmake/languages/asm/xmake.lua b/xmake/languages/asm/xmake.lua index bdf4a4514..66115f65b 100644 --- a/xmake/languages/asm/xmake.lua +++ b/xmake/languages/asm/xmake.lua @@ -59,6 +59,9 @@ language("asm") , "config.links" , "target.links" , "toolchain.links" + , "config.syslinks" + , "target.syslinks" + , "toolchain.syslinks" } , shared = { "config.linkdirs" diff --git a/xmake/modules/core/tools/link.lua b/xmake/modules/core/tools/link.lua index b5ee775af..38ce20a83 100644 --- a/xmake/modules/core/tools/link.lua +++ b/xmake/modules/core/tools/link.lua @@ -140,9 +140,14 @@ 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 + local toolchain = self:toolchain() local program, argv = linkargv(self, objectfiles, targetkind, targetfile, flags, opt) - vstool.runv(program, argv, {envs = self:runenvs()}) + if toolchain and toolchain:name() == "masm32" then + os.iorunv(program, argv, {envs = self:runenvs()}) + else + -- use vstool to link and enable vs_unicode_output @see https://github.com/xmake-io/xmake/issues/528 + vstool.runv(program, argv, {envs = self:runenvs()}) + end end, catch { diff --git a/xmake/modules/detect/tools/find_link.lua b/xmake/modules/detect/tools/find_link.lua index 0c2abae7b..fedea7b6d 100644 --- a/xmake/modules/detect/tools/find_link.lua +++ b/xmake/modules/detect/tools/find_link.lua @@ -44,26 +44,32 @@ function main(opt) -- init options opt = opt or {} opt.check = opt.check or function (program) + local toolchain = opt.toolchain + if toolchain and toolchain:name() == "masm32" then + -- if this link.exe is from masm32 sdk, we just pass it fastly + -- because it does not contain cl.exe + -- + -- TODO maybe we can use ml to improve it + else + local cl = assert(find_tool("cl", {envs = opt.envs})) - -- find cl - local cl = assert(find_tool("cl", {envs = opt.envs})) + -- make an stub source file + local binaryfile = os.tmpfile() .. ".exe" + local objectfile = os.tmpfile() .. ".obj" + local sourcefile = os.tmpfile() .. ".c" - -- make an stub source file - local binaryfile = os.tmpfile() .. ".exe" - local objectfile = os.tmpfile() .. ".obj" - local sourcefile = os.tmpfile() .. ".c" + -- compile sourcefile first + io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") + os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) - -- compile sourcefile first - io.writefile(sourcefile, "int main(int argc, char** argv)\n{return 0;}") - os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) + -- do link + verinfo = os.iorunv(program, {"-lib", "-out:" .. binaryfile, objectfile}, {envs = opt.envs}) - -- do link - verinfo = os.iorunv(program, {"-lib", "-out:" .. binaryfile, objectfile}, {envs = opt.envs}) - - -- remove files - os.rm(objectfile) - os.rm(sourcefile) - os.rm(binaryfile) + -- remove files + os.rm(objectfile) + os.rm(sourcefile) + os.rm(binaryfile) + end end opt.command = opt.command or function () return verinfo end opt.parse = opt.parse or function (output) return output:match("Version (%d+%.?%d*%.?%d*.-)%s") end diff --git a/xmake/toolchains/masm32/xmake.lua b/xmake/toolchains/masm32/xmake.lua index f0a1ac7a4..f4cba74af 100644 --- a/xmake/toolchains/masm32/xmake.lua +++ b/xmake/toolchains/masm32/xmake.lua @@ -47,4 +47,5 @@ toolchain("masm32") toolchain:add("includedirs", path.join(sdkdir, "include")) toolchain:add("linkdirs", path.join(sdkdir, "lib")) end + toolchain:add("asflags", "/coff") end) |
