diff options
| author | ruki <[email protected]> | 2021-01-27 22:34:26 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-01-27 22:34:26 +0800 |
| commit | abaaa6c248d7b0a92a289e00b76d5da53802cd2b (patch) | |
| tree | f395d2eedaa30211f99b0c2a926b36802c6cd9a1 | |
| parent | 0ba673bb80583c8aab3a94deaa9973b903473422 (diff) | |
improve zig
| -rw-r--r-- | tests/projects/zig/console/src/main.zig | 2 | ||||
| -rw-r--r-- | tests/projects/zig/shared_library/src/main.zig | 2 | ||||
| -rw-r--r-- | tests/projects/zig/static_library/src/main.zig | 2 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig_cc.lua | 25 | ||||
| -rw-r--r-- | xmake/toolchains/zig/xmake.lua | 57 |
5 files changed, 39 insertions, 49 deletions
diff --git a/tests/projects/zig/console/src/main.zig b/tests/projects/zig/console/src/main.zig index fcfd5e0fa..56b206650 100644 --- a/tests/projects/zig/console/src/main.zig +++ b/tests/projects/zig/console/src/main.zig @@ -1,6 +1,6 @@ const std = @import("std"); pub fn main() !void { - const stdout = std.io.getStdOut().outStream(); + const stdout = std.io.getStdOut().writer(); try stdout.print("Hello, {}!\n", .{"world"}); } diff --git a/tests/projects/zig/shared_library/src/main.zig b/tests/projects/zig/shared_library/src/main.zig index cee64b6b7..2675d4326 100644 --- a/tests/projects/zig/shared_library/src/main.zig +++ b/tests/projects/zig/shared_library/src/main.zig @@ -3,6 +3,6 @@ const std = @import("std"); extern fn add(a: i32, b: i32) i32; pub fn main() !void { - const stdout = std.io.getStdOut().outStream(); + const stdout = std.io.getStdOut().writer(); try stdout.print("Hello, {} - {}!\n", .{"world", add(1, 1)}); } diff --git a/tests/projects/zig/static_library/src/main.zig b/tests/projects/zig/static_library/src/main.zig index cee64b6b7..2675d4326 100644 --- a/tests/projects/zig/static_library/src/main.zig +++ b/tests/projects/zig/static_library/src/main.zig @@ -3,6 +3,6 @@ const std = @import("std"); extern fn add(a: i32, b: i32) i32; pub fn main() !void { - const stdout = std.io.getStdOut().outStream(); + const stdout = std.io.getStdOut().writer(); try stdout.print("Hello, {} - {}!\n", .{"world", add(1, 1)}); } diff --git a/xmake/modules/core/tools/zig_cc.lua b/xmake/modules/core/tools/zig_cc.lua index 8d235c818..1e263a4f6 100644 --- a/xmake/modules/core/tools/zig_cc.lua +++ b/xmake/modules/core/tools/zig_cc.lua @@ -21,28 +21,3 @@ -- inherit gcc inherit("gcc") --- init it -function init(self) - - -- init super - _super.init(self) - - -- patch target - if not self:program():find("target", 1, true) then - local march - if is_plat("macosx") then - march = is_arch("x86") and "i386-macos-gnu" or "x86_64-macos-gnu" - elseif is_plat("linux") then - march = is_arch("x86") and "i386-linux-gnu" or "x86_64-linux-gnu" - elseif is_plat("windows") then - march = is_arch("x86") and "i386-windows-msvc" or "x86_64-windows-msvc" - elseif is_plat("mingw") then - march = is_arch("x86") and "i386-windows-gnu" or "x86_64-windows-gnu" - end - if march then - self:add("cxflags", "-target", march) - self:add("ldflags", "-target", march) - self:add("shflags", "-target", march) - end - end -end diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua index 00e5d4ca8..fc83710a7 100644 --- a/xmake/toolchains/zig/xmake.lua +++ b/xmake/toolchains/zig/xmake.lua @@ -25,38 +25,53 @@ toolchain("zig") set_homepage("https://ziglang.org/") set_description("Zig Programming Language Compiler") + -- mark as standalone toolchain + set_kind("standalone") + -- on load on_load(function (toolchain) - -- init march - local march - if toolchain:is_plat("macosx") then - march = toolchain:is_arch("x86") and "i386-macos-gnu" or "x86_64-macos-gnu" - elseif toolchain:is_plat("linux") then - march = toolchain:is_arch("x86") and "i386-linux-gnu" or "x86_64-linux-gnu" - elseif toolchain:is_plat("windows") then - march = toolchain:is_arch("x86") and "i386-windows-msvc" or "x86_64-windows-msvc" - elseif toolchain:is_plat("mingw") then - march = toolchain:is_arch("x86") and "i386-windows-gnu" or "x86_64-windows-gnu" - end - if march then - toolchain:add("zcflags", "-target", march) - toolchain:add("zcldflags", "-target", march) - toolchain:add("zcshflags", "-target", march) - end - -- set toolset -- we patch target to `zig cc` to fix has_flags. see https://github.com/xmake-io/xmake/issues/955#issuecomment-766929692 local zig = get_config("zc") or "zig" - toolchain:set("toolset", "cc", zig .. " cc" .. (march and (" --target=" .. march) or "")) - toolchain:set("toolset", "cxx", zig .. " c++" .. (march and (" --target=" .. march) or "")) - toolchain:set("toolset", "ld", zig .. " c++" .. (march and (" --target=" .. march) or "")) - toolchain:set("toolset", "sh", zig .. " c++" .. (march and (" --target=" .. march) or "")) + toolchain:set("toolset", "cc", zig .. " cc") + toolchain:set("toolset", "cxx", zig .. " c++") + toolchain:set("toolset", "ld", zig .. " c++") + toolchain:set("toolset", "sh", zig .. " c++") 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 arch + if toolchain:is_arch("arm64") then + arch = "aarch64" + elseif toolchain:is_arch("i386", "x86") then + arch = "i386" + else + arch = "x86_64" + end + + -- init target + local target + if toolchain:is_plat("macosx") then + target = arch .. "-macos-gnu" + elseif toolchain:is_plat("linux") then + target = arch .. "-linux-gnu" + elseif toolchain:is_plat("windows") then + target = arch .. "-windows-msvc" + elseif toolchain:is_plat("mingw") then + target = arch .. "-windows-gnu" + end + if target then + toolchain:add("cxflags", "-target", target) + toolchain:add("shflags", "-target", target) + toolchain:add("ldflags", "-target", target) + toolchain:add("zcflags", "-target", target) + toolchain:add("zcldflags", "-target", target) + toolchain:add("zcshflags", "-target", target) + end + -- @see https://github.com/ziglang/zig/issues/5825 if toolchain:is_plat("windows") then toolchain:add("zcldflags", "--subsystem console") |
