diff options
| author | ruki <[email protected]> | 2022-02-20 09:12:30 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-20 09:12:30 +0800 |
| commit | 1adac6da5c51607e020c8ea26c96e77cca88a909 (patch) | |
| tree | 1cfb495d2c3ed0403943788764b926ba185bdf00 | |
| parent | 43af40334dae383707c15ec731d515cd3ac6b834 (diff) | |
| parent | b5339465eecc7676879924f9cdd0da6545fc71ea (diff) | |
Merge pull request #2068 from xmake-io/zig
Improve zig cc/c++
| -rw-r--r-- | .github/workflows/archlinux.yml | 2 | ||||
| -rw-r--r-- | tests/projects/c++/console_zig_cxx/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/c++/console_zig_cxx/src/main.cpp | 9 | ||||
| -rw-r--r-- | tests/projects/c++/console_zig_cxx/xmake.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/core/tools/gcc.lua | 30 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig_cc.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig_cxx.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_toolname.lua | 52 |
9 files changed, 80 insertions, 48 deletions
diff --git a/.github/workflows/archlinux.yml b/.github/workflows/archlinux.yml index 035433687..391b6d783 100644 --- a/.github/workflows/archlinux.yml +++ b/.github/workflows/archlinux.yml @@ -18,7 +18,7 @@ jobs: steps: - name: Prepare build tools run: | - pacman -Sy --noconfirm --needed git base-devel perl make unzip + pacman -Sy --noconfirm --needed glibc git base-devel perl make unzip - uses: actions/checkout@v2 with: 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..eec7dae65 --- /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.9.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..812de70aa 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -52,8 +52,7 @@ function init(self) end -- init flags map - self:set("mapflags", - { + self:set("mapflags", { -- warnings ["-W1"] = "-Wall" , ["-W2"] = "-Wall" @@ -68,8 +67,7 @@ function init(self) -- for macho target if is_plat("macosx") or is_plat("iphoneos") then - self:add("mapflags", - { + self:add("mapflags", { ["-s"] = "-Wl,-x" }) end @@ -77,8 +75,7 @@ end -- make the strip flag function nf_strip(self, level, target) - local maps = - { + local maps = { debug = "-Wl,-S" , all = "-s" } @@ -95,8 +92,7 @@ function nf_symbol(self, level) if language.sourcekinds()[kind] then local maps = _g.symbol_maps if not maps then - maps = - { + maps = { debug = "-g" , hidden = "-fvisibility=hidden" } @@ -111,8 +107,7 @@ end -- make the warning flag function nf_warning(self, level) - local maps = - { + local maps = { none = "-w" , less = "-Wall" , more = "-Wall" @@ -126,8 +121,7 @@ end -- make the fp-model flag function nf_fpmodel(self, level) - local maps = - { + local maps = { precise = "" --default , fast = "-ffast-math" , strict = {"-frounding-math", "-ftrapping-math"} @@ -139,8 +133,7 @@ end -- make the optimize flag function nf_optimize(self, level) - local maps = - { + local maps = { none = "-O0" , fast = "-O1" , faster = "-O2" @@ -153,8 +146,7 @@ end -- make the vector extension flag function nf_vectorext(self, extension) - local maps = - { + local maps = { mmx = "-mmmx" , sse = "-msse" , sse2 = "-msse2" @@ -172,8 +164,7 @@ function nf_language(self, stdname) -- the stdc maps if _g.cmaps == nil then - _g.cmaps = - { + _g.cmaps = { -- stdc ansi = "-ansi" , c89 = "-std=c89" @@ -191,8 +182,7 @@ function nf_language(self, stdname) -- the stdc++ maps if _g.cxxmaps == nil then - _g.cxxmaps = - { + _g.cxxmaps = { cxx98 = "-std=c++98" , gnuxx98 = "-std=gnu++98" , cxx11 = "-std=c++11" 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 |
