summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2020-11-10 23:48:29 +0800
committerruki <[email protected]>2020-11-10 23:48:29 +0800
commit4de40c8e54d44e5f0d99efc6791b2ee5466156e2 (patch)
tree78d2676fb1b423cddc855629a913cae8f8ba09c5
parent85aa5fce76f7dd92dc618a4ae1ef20579b5e5ccd (diff)
improve zig support for 0.7.0
-rw-r--r--xmake/modules/core/tools/zig.lua21
-rw-r--r--xmake/modules/detect/tools/zig/has_flags.lua5
-rw-r--r--xmake/toolchains/zig/xmake.lua15
3 files changed, 19 insertions, 22 deletions
diff --git a/xmake/modules/core/tools/zig.lua b/xmake/modules/core/tools/zig.lua
index c9927a382..81d06c0da 100644
--- a/xmake/modules/core/tools/zig.lua
+++ b/xmake/modules/core/tools/zig.lua
@@ -53,12 +53,12 @@ end
function nf_optimize(self, level)
local maps =
{
- none = "-O0"
- , fast = "--release-safe"
- , aggressive = "--release-fast"
- , fastest = "--release-fast"
- , smallest = "--release-small"
- , aggressive = "--release-fast"
+ none = "-O Debug"
+ , fast = "-O ReleaseSafe"
+ , aggressive = "-O ReleaseFast"
+ , fastest = "-O ReleaseFast"
+ , smallest = "-O ReleaseSmall"
+ , aggressive = "-O ReleaseFast"
}
return maps[level]
end
@@ -111,12 +111,7 @@ function linkargv(self, objectfiles, targetkind, targetfile, flags)
else
raise("unknown target kind(%s)!", targetkind)
end
- local name = targetkind == "binary" and path.basename(targetfile) or target.linkname(path.filename(targetfile))
- table.join2(argv, flags, "--output-dir", path.directory(targetfile), "--name", name)
- for _, objectfile in ipairs(objectfiles) do
- table.insert(argv, "--object")
- table.insert(argv, objectfile)
- end
+ table.join2(argv, flags, "-femit-bin=" .. targetfile, objectfiles)
return self:program(), argv
end
@@ -132,7 +127,7 @@ end
-- make the compile arguments list
function compargv(self, sourcefile, objectfile, flags)
- return self:program(), table.join("build-obj", flags, "--output-dir", path.directory(objectfile), "--name", path.basename(objectfile), sourcefile)
+ return self:program(), table.join("build-obj", flags, "-femit-bin=" .. objectfile, sourcefile)
end
-- compile the source file
diff --git a/xmake/modules/detect/tools/zig/has_flags.lua b/xmake/modules/detect/tools/zig/has_flags.lua
index 1d8f8161b..0feecbe43 100644
--- a/xmake/modules/detect/tools/zig/has_flags.lua
+++ b/xmake/modules/detect/tools/zig/has_flags.lua
@@ -60,7 +60,7 @@ function _check_from_arglist(flags, opt, islinker)
-- get argument list
allflags = {}
- local arglist = os.iorunv(opt.program, {"--help"})
+ local arglist = os.iorunv(opt.program, {"build-obj", "--help"})
if arglist then
for arg in arglist:gmatch("%s+(%-[%-%a%d]+)%s+") do
allflags[arg] = true
@@ -81,13 +81,12 @@ function _check_try_running(flags, opt, islinker)
-- make an stub source file
local sourcefile = path.join(os.tmpdir(), "detect", "zig_has_flags.zig")
- local objectdir = path.join(os.tmpdir(), "detect", "zig_has_flags")
if not os.isfile(sourcefile) then
io.writefile(sourcefile, "pub fn main() !void {}")
end
-- init argv
- local argv = table.join(flags, "--output-dir", objectdir, sourcefile)
+ local argv = table.join(flags, "-femit-bin=" .. os.tmpfile(), sourcefile)
if islinker then
table.insert(argv, 1, "build-exe")
else
diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua
index 5735a4722..0ba11436f 100644
--- a/xmake/toolchains/zig/xmake.lua
+++ b/xmake/toolchains/zig/xmake.lua
@@ -25,14 +25,17 @@ toolchain("zig")
set_homepage("https://ziglang.org/")
set_description("Zig Programming Language Compiler")
- -- set toolset
- set_toolset("zc", "$(env ZC)", "zig")
- set_toolset("zcar", "$(env ZC)", "zig")
- set_toolset("zcld", "$(env ZC)", "zig")
- set_toolset("zcsh", "$(env ZC)", "zig")
-
-- on load
on_load(function (toolchain)
+
+ -- set toolset
+ local zig = get_config("zc") or "zig"
+ toolchain:set("toolset", "zc", "$(env ZC)", zig)
+ toolchain:set("toolset", "zcar", "$(env ZC)", zig)
+ toolchain:set("toolset", "zcld", "$(env ZC)", zig)
+ toolchain:set("toolset", "zcsh", "$(env ZC)", zig)
+
+ -- init flags
local march
if toolchain:is_plat("macosx") then
-- FIXME