diff options
| author | ruki <[email protected]> | 2021-01-25 22:39:15 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-01-25 22:39:15 +0800 |
| commit | 22e78e33f6c3567228a1b8b4e1837171498ccab3 (patch) | |
| tree | e33a88e9e8d2d2a12ab1564c46f57ed08121679a | |
| parent | fa171c502d6b20431af22321005024e593d4170d (diff) | |
support zig cc/c++
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 2 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 1 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig_cc.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/core/tools/zig_cxx.lua | 24 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_zig_cc.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/find_zig_cxx.lua | 52 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/zig_cc/features.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/zig_cc/has_flags.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/zig_cxx/features.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/zig_cxx/has_flags.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/find_toolname.lua | 32 |
12 files changed, 273 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e994c3961..43d7f5aa5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +### New features + +* [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-766481512): Support `zig cc` and `zig c++` as c/c++ compiler + ## v2.5.1 ### New features @@ -902,6 +906,10 @@ ## master (开发中) +### 新特性 + +* [#955](https://github.com/xmake-io/xmake/issues/955#issuecomment-766481512): 支持 `zig cc` 和 `zig c++` 作为 c/c++ 编译器 + ## v2.5.1 ### 新特性 diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index cd94045db..66360213e 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -699,8 +699,6 @@ function _instance:pkgs() for _, pkg in ipairs(self:orderpkgs()) do self._PKGS_ENABLED[pkg:name()] = pkg end - - -- get it return self._PKGS_ENABLED end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 78caadc12..9bd5e71ba 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -371,6 +371,7 @@ function _instance:_checktool(toolkind, toolpath) -- find tool program local program, toolname local tool = find_tool(toolpath, {cachekey = self:cachekey(), program = toolpath, paths = self:bindir(), envs = self:get("runenvs")}) + print(self:name(), toolkind, tool) if tool then program = tool.program toolname = tool.name diff --git a/xmake/modules/core/tools/zig_cc.lua b/xmake/modules/core/tools/zig_cc.lua new file mode 100644 index 000000000..1e263a4f6 --- /dev/null +++ b/xmake/modules/core/tools/zig_cc.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file zig_cc.lua +-- + +-- inherit gcc +inherit("gcc") + diff --git a/xmake/modules/core/tools/zig_cxx.lua b/xmake/modules/core/tools/zig_cxx.lua new file mode 100644 index 000000000..cb51b6d36 --- /dev/null +++ b/xmake/modules/core/tools/zig_cxx.lua @@ -0,0 +1,24 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file zig_cxx.lua +-- + +-- inherit g++ +inherit("gxx") + + diff --git a/xmake/modules/detect/tools/find_zig_cc.lua b/xmake/modules/detect/tools/find_zig_cc.lua new file mode 100644 index 000000000..3ef1511bb --- /dev/null +++ b/xmake/modules/detect/tools/find_zig_cc.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_zig_cc.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find zig_cc +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local zig_cc = find_zig_cc() +-- local zig_cc, version, hintname = find_zig_cc({program = "zig cc", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "zig cc", opt) + + -- find program version + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/modules/detect/tools/find_zig_cxx.lua b/xmake/modules/detect/tools/find_zig_cxx.lua new file mode 100644 index 000000000..d9e63e7de --- /dev/null +++ b/xmake/modules/detect/tools/find_zig_cxx.lua @@ -0,0 +1,52 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file find_zig_cxx.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find zig_cxx +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local zig_cxx = find_zig_cxx() +-- local zig_cxx, version, hintname = find_zig_cxx({program = "zig c++", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "zig c++", opt) + + -- find program version + local version = nil + if program and opt.version then + version = find_programver(program, opt) + end + return program, version +end diff --git a/xmake/modules/detect/tools/zig_cc/features.lua b/xmake/modules/detect/tools/zig_cc/features.lua new file mode 100644 index 000000000..b887b9efc --- /dev/null +++ b/xmake/modules/detect/tools/zig_cc/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("detect.tools.gcc.features") + diff --git a/xmake/modules/detect/tools/zig_cc/has_flags.lua b/xmake/modules/detect/tools/zig_cc/has_flags.lua new file mode 100644 index 000000000..6464e10b6 --- /dev/null +++ b/xmake/modules/detect/tools/zig_cc/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.gcc.has_flags") + diff --git a/xmake/modules/detect/tools/zig_cxx/features.lua b/xmake/modules/detect/tools/zig_cxx/features.lua new file mode 100644 index 000000000..b887b9efc --- /dev/null +++ b/xmake/modules/detect/tools/zig_cxx/features.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file features.lua +-- + +-- imports +inherit("detect.tools.gcc.features") + diff --git a/xmake/modules/detect/tools/zig_cxx/has_flags.lua b/xmake/modules/detect/tools/zig_cxx/has_flags.lua new file mode 100644 index 000000000..6464e10b6 --- /dev/null +++ b/xmake/modules/detect/tools/zig_cxx/has_flags.lua @@ -0,0 +1,23 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author ruki +-- @file has_flags.lua +-- + +-- imports +inherit("detect.tools.gcc.has_flags") + diff --git a/xmake/modules/lib/detect/find_toolname.lua b/xmake/modules/lib/detect/find_toolname.lua index 21b424fb7..d58010670 100644 --- a/xmake/modules/lib/detect/find_toolname.lua +++ b/xmake/modules/lib/detect/find_toolname.lua @@ -35,7 +35,7 @@ function _find(program) -- remove arguments: " -xxx" or " --xxx" name = name:gsub("%s%-+%w+", " ") - -- get the last name by ' ': xxx xxx toolname + -- try the last name by ' ': xxx xxx toolname local names = name:split("%s") if #names > 0 then name = names[#names] @@ -43,14 +43,12 @@ function _find(program) -- remove suffix: ".xxx" name = name:gsub("%.%w+", "") - - -- find_toolname.lua exists? found - local toolname = name:gsub("[%+%-]", function (ch) return ifelse(ch == "+", "x", "_") end) + local toolname = name:gsub("[%+%-]", function (ch) return (ch == "+" and "x" or "_") end) if module.find("detect.tools.find_" .. toolname) then return toolname end - -- get the last valid name: xxx-xxx-toolname-5 + -- try last valid name: xxx-xxx-toolname-5 local partnames = {} for partname in name:gmatch("([%a%+]+)") do table.insert(partnames, partname) @@ -58,18 +56,32 @@ function _find(program) if #partnames > 0 then name = partnames[#partnames] end - - -- find_toolname.lua exists? found toolname = name:gsub("%+", "x") 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 = {} + 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") + table.insert(partnames, name) + end + toolname = table.concat(partnames, "_") + if module.find("detect.tools.find_" .. toolname) then + return toolname + end end -- find tool name -- -- e.g. -- "xcrun -sdk macosx clang": clang +-- "zig cc": zig_cc +-- "zig.exe c++": zig_c++ -- "/usr/bin/arm-linux-gcc": gcc -- "link.exe -lib": link -- "gcc-5": gcc @@ -88,16 +100,14 @@ function main(program) -- get it from the cache first local toolname = toolnames[program] if toolname ~= nil then - return ifelse(toolname, toolname, nil) + return toolname and toolname or nil end -- find the tool name toolname = _find(program) -- save result to cache - toolnames[program] = ifelse(toolname, toolname, false) + toolnames[program] = toolname and toolname or false _g._TOOLNAMES = toolnames - - -- found? return toolname end |
