diff options
| author | ruki <[email protected]> | 2020-05-20 22:57:42 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-05-20 11:46:14 +0800 |
| commit | eff77a9a787016605baf133bc1a582ef8437a7fa (patch) | |
| tree | 6cb69279b6801629bca9892ce5dcbde0b238f70c | |
| parent | 59caa4b16d0f8ab122338d7dfbcd461cc6017324 (diff) | |
add vs toolchain
| -rw-r--r-- | xmake/platforms/windows/check.lua | 128 | ||||
| -rw-r--r-- | xmake/platforms/windows/load.lua | 38 | ||||
| -rw-r--r-- | xmake/platforms/windows/xmake.lua | 4 | ||||
| -rw-r--r-- | xmake/toolchains/vs/check.lua | 97 | ||||
| -rw-r--r-- | xmake/toolchains/vs/xmake.lua | 46 |
5 files changed, 165 insertions, 148 deletions
diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua index 4503a35db..0dfc7b536 100644 --- a/xmake/platforms/windows/check.lua +++ b/xmake/platforms/windows/check.lua @@ -20,120 +20,32 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("core.platform.environment") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_vstudio") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local mrc = toolchain("the resource compiler") - local ld = toolchain("the linker") - local sh = toolchain("the shared library linker") - local ar = toolchain("the static library archiver") - local ex = toolchain("the static library extractor") - local as = toolchain("the assember") - local gc = toolchain("the golang compiler") - local gc_ld = toolchain("the golang linker") - local gc_ar = toolchain("the golang static library archiver") - local dc = toolchain("the dlang compiler") - local dc_ld = toolchain("the dlang linker") - local dc_sh = toolchain("the dlang shared library linker") - local dc_ar = toolchain("the dlang static library archiver") - local rc = toolchain("the rust compiler") - local rc_ld = toolchain("the rust linker") - local rc_sh = toolchain("the rust shared library linker") - local rc_ar = toolchain("the rust static library archiver") - local cu = toolchain("the cuda compiler") - local cu_ld = toolchain("the cuda linker") - local toolchains = {cc = cc, cxx = cxx, mrc = mrc, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - gc = gc, ["gcld"] = gc_ld, ["gcar"] = gc_ar, - dc = dc, ["dcld"] = dc_ld, ["dcsh"] = dc_sh, ["dcar"] = dc_ar, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar, - cu = cu, ["culd"] = cu_ld} - - -- init the c compiler - cc:add("cl.exe") - - -- init the c++ compiler - cxx:add("cl.exe") - - -- init the resource compiler - mrc:add("rc.exe") - - -- init the assember - local arch = config.get("arch") - if arch and arch:find("64") then - as:add("ml64.exe") - else - as:add("ml.exe") - end - - -- init the linker - ld:add("link.exe") - - -- init the shared library linker - sh:add("link.exe -dll") - - -- init the static library archiver - ar:add("link.exe -lib") - - -- init the static library extractor - ex:add("lib.exe") - - -- init the golang compiler and linker - gc:add("$(env GC)", "go", "gccgo") - gc_ld:add("$(env GC)", "go", "gccgo") - gc_ar:add("$(env GC)", "go", "gccgo") - - -- init the dlang compiler and linker - dc:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ld:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_sh:add("$(env DC)", "dmd", "ldc2", "gdc") - dc_ar:add("$(env DC)", "dmd", "ldc2", "gdc") - - -- init the rust compiler and linker - rc:add("$(env RC)", "rustc") - rc_ld:add("$(env RC)", "rustc") - rc_sh:add("$(env RC)", "rustc") - rc_ar:add("$(env RC)", "rustc") - - -- init the cuda compiler and linker - cu:add("nvcc", "clang") - cu_ld:add("nvcc") - - return toolchains -end -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("windows.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - environment.enter("toolchains") - check_toolchain(config, name, toolchain) - environment.leave("toolchains") - end - else +function main(platform) - -- check arch - check_arch(config) + -- check arch + check_arch(config) - -- check vstudio - local cc = path.basename(config.get("cc") or "cl"):lower() - local cxx = path.basename(config.get("cxx") or "cl"):lower() - local mrc = path.basename(config.get("mrc") or "rc"):lower() - if cc == "cl" or cxx == "cl" or mrc == "rc" then - check_vstudio(config) + -- check toolchains + local toolchains = platform:toolchains() + local idx = 1 + local num = #toolchains + local standalone = false + while idx <= num do + local toolchain = toolchains[idx] + -- we need remove other standalone toolchains if standalone toolchain found + if (standalone and toolchain:standalone()) or not toolchain:check() then + table.remove(toolchains, idx) + num = num - 1 + else + if toolchain:standalone() then + standalone = true + end + idx = idx + 1 end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua deleted file mode 100644 index 710cb8723..000000000 --- a/xmake/platforms/windows/load.lua +++ /dev/null @@ -1,38 +0,0 @@ ---!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-2020, TBOOX Open Source Group. --- --- @author ruki --- @file load.lua --- - --- imports -import("core.project.config") - --- load it -function main(platform) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x64" and "win64" or "win32") - - -- init flags for dlang - local dc_archs = { x86 = "-m32", x64 = "-m64" } - platform:add("dcflags", dc_archs[arch]) - platform:add("dcshflags", dc_archs[arch]) - platform:add("dcldflags", dc_archs[arch]) -end diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 3bc2bf0cf..dd0c37679 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -42,8 +42,8 @@ platform("windows") -- on environment leave on_environment_leave("environment.leave") - -- on load - on_load("load") + -- set toolchains + set_toolchains("vs", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/toolchains/vs/check.lua b/xmake/toolchains/vs/check.lua new file mode 100644 index 000000000..1e9a97d48 --- /dev/null +++ b/xmake/toolchains/vs/check.lua @@ -0,0 +1,97 @@ +--!A cross-toolchain 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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file check.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_vstudio") +import("lib.detect.find_tool") +import("core.platform.environment") + +-- attempt to check vs environment +function _check_vsenv() + + -- have been checked? + local vs = config.get("vs") + if vs and config.get("__vcvarsall") then + return vs + end + + -- find vstudio + local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = config.get("vs_sdkver")}) + if vstudio then + + -- make order vsver + local vsvers = {} + for vsver, _ in pairs(vstudio) do + if not vs or vs ~= vsver then + table.insert(vsvers, vsver) + end + end + table.sort(vsvers, function (a, b) return tonumber(a) > tonumber(b) end) + if vs then + table.insert(vsvers, 1, vs) + end + + -- get vcvarsall + for _, vsver in ipairs(vsvers) do + local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {} + local vsenv = vcvarsall[config.get("arch") or ""] + if vsenv and vsenv.path and vsenv.include and vsenv.lib then + + -- save vsenv + config.set("__vcvarsall", vcvarsall) + + -- check compiler + environment.enter("toolchains") + local program = nil + local tool = find_tool("cl.exe", {force = true}) + if tool then + program = tool.program + end + environment.leave("toolchains") + + -- ok? + if program then + return vsver + end + end + end + end +end + +-- check the visual studio +function main() + local vs = _check_vsenv() + if vs then + config.set("vs", vs, {readonly = true, force = true}) + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", config.get("arch"), vs) + else + cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", config.get("arch")) + if not (opt and opt.try) then + print("please run:") + print(" - xmake config --vs=xxx [--vs_toolset=xxx]") + print("or - xmake global --vs=xxx") + raise() + end + end + return vs +end + diff --git a/xmake/toolchains/vs/xmake.lua b/xmake/toolchains/vs/xmake.lua new file mode 100644 index 000000000..a2b1c71db --- /dev/null +++ b/xmake/toolchains/vs/xmake.lua @@ -0,0 +1,46 @@ +--!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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("vs") + + -- mark as standalone toolchain + set_kind("standalone") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load(function (toolchain) + + -- set toolsets + toolchain:set("toolsets", "cc", "cl.exe") + toolchain:set("toolsets", "cxx", "cl.exe") + toolchain:set("toolsets", "mrc", "rc.exe") + if is_arch("x64") then + toolchain:set("toolsets", "as", "ml64.exe") + else + toolchain:set("toolsets", "as", "ml.exe") + end + toolchain:set("toolsets", "ld", "link.exe") + toolchain:set("toolsets", "sh", "link.exe -dll") + toolchain:set("toolsets", "ar", "link.exe -lib") + toolchain:set("toolsets", "ex", "lib.exe") + end) |
