summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-02-19 22:30:38 +0800
committerruki <[email protected]>2022-02-19 22:30:38 +0800
commit005a664f5b3ef7b833ab7b4afdb41583d56b6811 (patch)
tree8080d7acdc672cccbe428020c1e56dea2dcfb35a
parent43af40334dae383707c15ec731d515cd3ac6b834 (diff)
improve zig cc
-rw-r--r--tests/projects/c++/console_zig_cxx/.gitignore8
-rw-r--r--tests/projects/c++/console_zig_cxx/src/main.cpp9
-rw-r--r--tests/projects/c++/console_zig_cxx/xmake.lua9
-rw-r--r--xmake/modules/core/tools/gcc.lua3
-rw-r--r--xmake/modules/core/tools/zig.lua7
-rw-r--r--xmake/modules/core/tools/zig_cc.lua9
-rw-r--r--xmake/modules/core/tools/zig_cxx.lua2
-rw-r--r--xmake/modules/lib/detect/find_toolname.lua52
8 files changed, 70 insertions, 29 deletions
diff --git a/tests/projects/c++/console_zig_cxx/.gitignore b/tests/projects/c++/console_zig_cxx/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/c++/console_zig_cxx/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/c++/console_zig_cxx/src/main.cpp b/tests/projects/c++/console_zig_cxx/src/main.cpp
new file mode 100644
index 000000000..7c435d251
--- /dev/null
+++ b/tests/projects/c++/console_zig_cxx/src/main.cpp
@@ -0,0 +1,9 @@
+#include <iostream>
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ cout << "hello world!" << endl;
+ return 0;
+}
diff --git a/tests/projects/c++/console_zig_cxx/xmake.lua b/tests/projects/c++/console_zig_cxx/xmake.lua
new file mode 100644
index 000000000..ef3ebc748
--- /dev/null
+++ b/tests/projects/c++/console_zig_cxx/xmake.lua
@@ -0,0 +1,9 @@
+add_rules("mode.debug", "mode.release")
+add_requires("zig 0.7.x")
+
+target("test")
+ set_kind("binary")
+ add_files("src/*.cpp")
+ set_toolchains("@zig")
+
+
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 40d3b8a4e..78b0dece6 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -77,8 +77,7 @@ end
-- make the strip flag
function nf_strip(self, level, target)
- local maps =
- {
+ local maps = {
debug = "-Wl,-S"
, all = "-s"
}
diff --git a/xmake/modules/core/tools/zig.lua b/xmake/modules/core/tools/zig.lua
index f0d6c5d98..88cfd0936 100644
--- a/xmake/modules/core/tools/zig.lua
+++ b/xmake/modules/core/tools/zig.lua
@@ -36,10 +36,9 @@ end
-- make the strip flag
function nf_strip(self, level)
- local maps =
- {
- debug = "--strip"
- , all = "--strip"
+ local maps = {
+ debug = "--strip"
+ , all = "--strip"
}
return maps[level]
end
diff --git a/xmake/modules/core/tools/zig_cc.lua b/xmake/modules/core/tools/zig_cc.lua
index 1e263a4f6..8fefb0f97 100644
--- a/xmake/modules/core/tools/zig_cc.lua
+++ b/xmake/modules/core/tools/zig_cc.lua
@@ -21,3 +21,12 @@
-- inherit gcc
inherit("gcc")
+-- make the strip flag
+function nf_strip(self, level, target)
+ local maps = {
+ debug = "-Wl,-S"
+ , all = "-s"
+ }
+ return maps[level]
+end
+
diff --git a/xmake/modules/core/tools/zig_cxx.lua b/xmake/modules/core/tools/zig_cxx.lua
index f9d7f9c72..48e6dd58f 100644
--- a/xmake/modules/core/tools/zig_cxx.lua
+++ b/xmake/modules/core/tools/zig_cxx.lua
@@ -19,5 +19,3 @@
--
inherit("zig_cc")
-
-
diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua
index b7201ead8..912f0ee8a 100644
--- a/xmake/modules/lib/detect/find_toolname.lua
+++ b/xmake/modules/lib/detect/find_toolname.lua
@@ -21,14 +21,42 @@
-- imports
import("core.sandbox.module")
--- find tool name from the given program
-function _find(program)
+-- find the the whole name
+function _find_with_whole_name(program)
-- attempt to find it directly first
if module.find("detect.tools.find_" .. program) then
return program
end
+ -- find the the whole name with spaces, e.g. "zig cc" -> zig_cc
+ local partnames = {}
+ local names = path.filename(program):lower():split("%s")
+ for _, name in ipairs(names) do
+ -- remove suffix: ".exe", e.g. "zig.exe cc"
+ name = name:gsub("%.%w+", "")
+ -- "zig c++" -> zig_cxx
+ name = name:gsub("%+", "x")
+ -- skip -arguments
+ if not name:startswith("-") then
+ table.insert(partnames, name)
+ end
+ end
+ local toolname = table.concat(partnames, "_")
+ if module.find("detect.tools.find_" .. toolname) then
+ return toolname
+ end
+end
+
+-- find tool name from the given program
+function _find(program)
+
+ -- find whole name first
+ local toolname = _find_with_whole_name(program)
+ if toolname then
+ return toolname
+ end
+
-- get file name first
name = path.filename(program):lower()
@@ -43,7 +71,7 @@ function _find(program)
-- remove suffix: ".xxx"
name = name:gsub("%.%w+", "")
- local toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end)
+ toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end)
if module.find("detect.tools.find_" .. toolname) then
return toolname
end
@@ -60,24 +88,6 @@ function _find(program)
if module.find("detect.tools.find_" .. toolname) then
return toolname
end
-
- -- try the the whole name with spaces, e.g. "zig cc" -> zig_cc
- partnames = {}
- names = path.filename(program):lower():split("%s")
- for _, name in ipairs(names) do
- -- remove suffix: ".exe", e.g. "zig.exe cc"
- name = name:gsub("%.%w+", "")
- -- "zig c++" -> zig_cxx
- name = name:gsub("%+", "x")
- -- skip -arguments
- if not name:startswith("-") then
- table.insert(partnames, name)
- end
- end
- toolname = table.concat(partnames, "_")
- if module.find("detect.tools.find_" .. toolname) then
- return toolname
- end
end
-- find tool name