summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-01-30 09:32:47 +0800
committerruki <[email protected]>2021-01-30 09:32:47 +0800
commit7f0bdcf280e617307a9b5895d3a4953c884e88a3 (patch)
tree1302550608b72ae1b7ddd274f0a6d66b00396e99
parentfde1f6f6594af9f5c1855921f0cd2a46628a1c8c (diff)
modify test
-rwxr-xr-xtests/projects/package/toolchain_zig/src/main.c7
-rw-r--r--tests/projects/package/toolchain_zig/src/main.zig6
-rw-r--r--tests/projects/package/toolchain_zig/xmake.lua2
-rw-r--r--xmake/core/tool/toolchain.lua20
-rw-r--r--xmake/toolchains/zig/xmake.lua18
5 files changed, 42 insertions, 11 deletions
diff --git a/tests/projects/package/toolchain_zig/src/main.c b/tests/projects/package/toolchain_zig/src/main.c
deleted file mode 100755
index 9ae580511..000000000
--- a/tests/projects/package/toolchain_zig/src/main.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include <stdio.h>
-
-int main(int argc, char** argv)
-{
- printf("hello world!\n");
- return 0;
-}
diff --git a/tests/projects/package/toolchain_zig/src/main.zig b/tests/projects/package/toolchain_zig/src/main.zig
new file mode 100644
index 000000000..56b206650
--- /dev/null
+++ b/tests/projects/package/toolchain_zig/src/main.zig
@@ -0,0 +1,6 @@
+const std = @import("std");
+
+pub fn main() !void {
+ const stdout = std.io.getStdOut().writer();
+ try stdout.print("Hello, {}!\n", .{"world"});
+}
diff --git a/tests/projects/package/toolchain_zig/xmake.lua b/tests/projects/package/toolchain_zig/xmake.lua
index 1e57fd568..c08fdca16 100644
--- a/tests/projects/package/toolchain_zig/xmake.lua
+++ b/tests/projects/package/toolchain_zig/xmake.lua
@@ -3,5 +3,5 @@ add_requires("zig 0.7.x")
target("test")
set_kind("binary")
- add_files("src/*.c")
+ add_files("src/*.zig")
set_toolchains("zig", {packages = "zig"})
diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua
index 78caadc12..fe3ee3291 100644
--- a/xmake/core/tool/toolchain.lua
+++ b/xmake/core/tool/toolchain.lua
@@ -260,6 +260,26 @@ function _instance:load_cross_toolchain()
return sandbox_module.import("toolchains.cross.load", {rootdir = os.programdir(), anonymous = true})(self)
end
+-- get packages
+function _instance:packages()
+ local packages = self._PACKAGES
+ if packages == nil then
+ packages = {}
+ local project = require("project/project")
+ for _, pkgname in ipairs(table.wrap(self:config("packages"))) do
+ local requires = project.requires()
+ if requires then
+ local pkginfo = requires[pkgname]
+ if pkginfo then
+ table.insert(packages, pkginfo)
+ end
+ end
+ end
+ self._PACKAGES = packages
+ end
+ return packages
+end
+
-- on check (builtin)
function _instance:_on_check()
local on_check = self:info():get("check")
diff --git a/xmake/toolchains/zig/xmake.lua b/xmake/toolchains/zig/xmake.lua
index d2aee0880..a1cd26efe 100644
--- a/xmake/toolchains/zig/xmake.lua
+++ b/xmake/toolchains/zig/xmake.lua
@@ -30,8 +30,20 @@ toolchain("zig")
-- on check
on_check(function (toolchain)
- -- only for overriding cross.on_check, because we will use `-p cross --cross=xxx`
- return true
+ import("lib.detect.find_tool")
+ local paths = {}
+ for _, package in ipairs(toolchain:packages()) do
+ local envs = package:get("envs")
+ if envs then
+ table.join2(paths, envs.PATH)
+ end
+ end
+ local zig = find_tool("zig", {program = get_config("zc"), paths = paths})
+ if zig and zig.program then
+ toolchain:config_set("zig", zig.program)
+ toolchain:configs_save()
+ return true
+ end
end)
-- on load
@@ -39,7 +51,7 @@ toolchain("zig")
-- 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"
+ local zig = toolchain:config("zig")
toolchain:set("toolset", "cc", zig .. " cc")
toolchain:set("toolset", "cxx", zig .. " c++")
toolchain:set("toolset", "ld", zig .. " c++")