From c6c71612e034c2e741add2b9deb69be4c93a8388 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 00:03:19 +0800 Subject: add xcode toolchain --- xmake/core/platform/platform.lua | 6 + xmake/core/tool/toolchain.lua | 231 +++++++++++++++++++++++++++++++++++++++ xmake/platforms/macosx/xmake.lua | 3 + xmake/toolchains/xcode/xmake.lua | 23 ++++ 4 files changed, 263 insertions(+) create mode 100644 xmake/core/tool/toolchain.lua create mode 100644 xmake/toolchains/xcode/xmake.lua diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index bf6734373..b6574584e 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -103,6 +103,11 @@ function _instance:archs() return self._INFO:get("archs") end +-- get the toolchains +function _instance:toolchains() + return self._INFO:get("toolchains") +end + -- get the platform script function _instance:script(name) return self._INFO:get(name) @@ -175,6 +180,7 @@ function platform._apis() , "platform.set_hosts" , "platform.set_archs" , "platform.set_installdir" + , "platform.set_toolchains" } , script = { diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua new file mode 100644 index 000000000..ba5640126 --- /dev/null +++ b/xmake/core/tool/toolchain.lua @@ -0,0 +1,231 @@ +--!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 toolchain.lua +-- + +-- define module +local toolchain = toolchain or {} +local _instance = _instance or {} + +-- load modules +local os = require("base/os") +local path = require("base/path") +local utils = require("base/utils") +local table = require("base/table") +local interpreter = require("base/interpreter") +local language = require("language/language") +local sandbox = require("sandbox/sandbox") + +-- new an instance +function _instance.new(name, info, rootdir) + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._ROOTDIR = rootdir + return instance +end + +-- get toolchain name +function _instance:name() + return self._NAME +end + +-- set the value to the toolchain configuration +function _instance:set(name, ...) + self._INFO:apival_set(name, ...) +end + +-- add the value to the toolchain configuration +function _instance:add(name, ...) + self._INFO:apival_add(name, ...) +end + +-- get the toolchain configuration +function _instance:get(name) + + -- attempt to get the static configure value + local value = self._INFO:get(name) + if value ~= nil then + return value + end + + -- lazy loading toolchain if get other configuration + if not self._LOADED and not self:_is_builtin_conf(name) then + local on_load = self._INFO:get("load") + if on_load then + local ok, errors = sandbox.load(on_load, self) + if not ok then + os.raise(errors) + end + end + self._LOADED = true + end + + -- get other toolchain info + return self._INFO:get(name) +end + +-- get the toolchain script +function _instance:script(name) + return self._INFO:get(name) +end + +-- is builtin configuration? +function _instance:_is_builtin_conf(name) + + local builtin_configs = self._BUILTIN_CONFIGS + if not builtin_configs then + builtin_configs = {} + for apiname, _ in pairs(toolchain._interpreter():apis("toolchain")) do + local pos = apiname:find('_', 1, true) + if pos then + builtin_configs[apiname:sub(pos + 1)] = true + end + end + self._BUILTIN_CONFIGS = builtin_configs + end + return builtin_configs[name] +end + +-- the interpreter +function toolchain._interpreter() + + -- the interpreter has been initialized? return it directly + if toolchain._INTERPRETER then + return toolchain._INTERPRETER + end + + -- init interpreter + local interp = interpreter.new() + assert(interp) + + -- define apis + interp:api_define(toolchain._apis()) + + -- define apis for language + interp:api_define(language.apis()) + + -- save interpreter + toolchain._INTERPRETER = interp + + -- ok? + return interp +end + +-- get toolchain apis +function toolchain._apis() + return + { + values = + { + -- toolchain.set_xxx + "toolchain.set_cc" + , "toolchain.set_cxx" + , "toolchain.set_ld" + , "toolchain.set_sh" + } + , script = + { + -- toolchain.on_xxx + "toolchain.on_load" + } + , dictionary = + { + -- toolchain.set_xxx + , "toolchain.set_formats" + } + } +end + +-- get toolchain directories +function toolchain.directories() + + -- init directories + local dirs = toolchain._DIRS or { path.join(global.directory(), "toolchains") + , path.join(os.programdir(), "toolchains") + } + + -- save directories to cache + toolchain._DIRS = dirs + return dirs +end + +-- load the given toolchain +function toolchain.load(name, plat) + + -- get toolchain name + plat = plat or config.get("plat") or os.host() + if not plat then + return nil, string.format("unknown toolchain!") + end + + -- get cache key + local cachekey = plat .. "_" .. (config.get("arch") or os.arch()) + + -- get it directly from cache dirst + toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} + if toolchain._TOOLCHAINS[cachekey] then + return toolchain._TOOLCHAINS[cachekey] + end + + -- find the toolchain script path + local scriptpath = nil + for _, dir in ipairs(toolchain.directories()) do + scriptpath = path.join(dir, name, "xmake.lua") + if os.isfile(scriptpath) then + break + end + end + if not scriptpath or not os.isfile(scriptpath) then + return nil, string.format("the toolchain %s not found!", name) + end + + -- get interpreter + local interp = toolchain._interpreter() + + -- load script + local ok, errors = interp:load(scriptpath) + if not ok then + return nil, errors + end + + -- load toolchain + local results, errors = interp:make("toolchain", true, false) + if not results and os.isfile(scriptpath) then + return nil, errors + end + + -- check the toolchain name + local result = results[name] + if not result then + return nil, string.format("the toolchain %s not found!", name) + end + + -- new an instance + local instance, errors = _instance.new(name, result, interp:rootdir()) + if not instance then + return nil, errors + end + + -- save instance to the cache + toolchain._TOOLCHAINS[cachekey] = instance + return instance +end + +-- return module +return toolchain diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 452c528db..d65c03a9e 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -45,6 +45,9 @@ platform("macosx") -- on load on_load("load") + -- set toolchains + set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") + -- set menu set_menu { config = diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua new file mode 100644 index 000000000..633f5a45d --- /dev/null +++ b/xmake/toolchains/xcode/xmake.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-2020, TBOOX Open Source Group. +-- +-- @author ruki +-- @file xmake.lua +-- + +-- define toolchain +toolchain("xcode") + -- cgit v1.3.1 From 82bf1252a0104734b8f3b5d7ef154d3025b9f96f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 10:24:27 +0800 Subject: get tool from toolchains --- xmake/core/platform/platform.lua | 62 +++++++++++++++++++++++++++++++++------- xmake/core/tool/toolchain.lua | 4 +++ xmake/platforms/macosx/xmake.lua | 3 +- 3 files changed, 58 insertions(+), 11 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index b6574584e..9a3aff93a 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -28,6 +28,7 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local interpreter = require("base/interpreter") +local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") @@ -105,7 +106,40 @@ end -- get the toolchains function _instance:toolchains() - return self._INFO:get("toolchains") + local toolchains = self._TOOLCHAINS + if not toolchains then + local names = {} + if config.get("toolchain") then + table.insert(names, config.get("toolchain")) + end + if self._INFO:get("toolchains") then + table.join2(names, self._INFO:get("toolchains")) + end + toolchains = {} + for _, name in ipairs(names) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end + self._TOOLCHAINS = toolchains + end + return toolchains +end + +-- get the program and name of the given tool kind +function _instance:tool(toolkind) + local toolchains = self:toolchains() + for idx, toolchain_inst in ipairs(toolchains) do + local program, toolname = toolchain_inst:tool(toolkind) + if program then + -- move this toolchain to head + table.remove(toolchains, idx) + table.insert(toolchains, 1, toolchain_inst) + return program, toolname + end + end end -- get the platform script @@ -327,16 +361,24 @@ function platform.tool(toolkind, plat) if not instance then os.raise(errors) end - - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) + -- get it from the platform toolchains + program, toolname = instance:tool(toolkind) + if program then + config.set(toolkind, program, {force = true, readonly = true}) + config.set("__toolname_" .. toolkind, toolname) + else + -- TODO deprecated + -- check it first + local on_check = instance:script("config_check") + if on_check then + on_check(instance, toolkind) + end + + -- get it again + program = config.get(toolkind) + toolname = config.get("__toolname_" .. toolkind) + end end -- contain toolname? parse it, e.g. 'gcc@xxxx.exe' diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ba5640126..ef2b4eda6 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -80,6 +80,10 @@ function _instance:get(name) return self._INFO:get(name) end +-- get the program and name of the given tool kind +function _instance:tool(toolkind) +end + -- get the toolchain script function _instance:script(name) return self._INFO:get(name) diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index d65c03a9e..b7abea032 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -46,7 +46,8 @@ platform("macosx") on_load("load") -- set toolchains - set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") +-- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") + set_toolchains("xcode") -- set menu set_menu { -- cgit v1.3.1 From 87a0828f8d20d3a1a83aed640e6e77560668e488 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 10:52:33 +0800 Subject: fix toolchain errors --- xmake/core/tool/toolchain.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ef2b4eda6..ef04e31bf 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -151,7 +151,7 @@ function toolchain._apis() , dictionary = { -- toolchain.set_xxx - , "toolchain.set_formats" + "toolchain.set_formats" } } end -- cgit v1.3.1 From d021df166bfd45c2d18ae6fa39cd685006491d01 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 10:59:10 +0800 Subject: rename dlang, rust, swift, go ldflags --- xmake/core/language/language.lua | 6 +++--- xmake/core/tool/linker.lua | 6 +++--- xmake/core/tool/toolchain.lua | 2 ++ xmake/languages/dlang/xmake.lua | 8 ++++---- xmake/languages/golang/xmake.lua | 4 ++-- xmake/languages/rust/xmake.lua | 8 ++++---- xmake/languages/swift/xmake.lua | 6 +++--- xmake/modules/core/tools/dmd.lua | 4 ++-- xmake/modules/core/tools/go.lua | 2 +- xmake/modules/core/tools/ldc2.lua | 2 +- xmake/modules/core/tools/rustc.lua | 6 +++--- xmake/platforms/android/config.lua | 2 +- xmake/platforms/android/load.lua | 8 ++++---- xmake/platforms/bsd/config.lua | 6 +++--- xmake/platforms/bsd/load.lua | 10 +++++----- xmake/platforms/cygwin/config.lua | 6 +++--- xmake/platforms/iphoneos/config.lua | 2 +- xmake/platforms/iphoneos/load.lua | 4 ++-- xmake/platforms/linux/config.lua | 6 +++--- xmake/platforms/linux/load.lua | 10 +++++----- xmake/platforms/macosx/config.lua | 8 ++++---- xmake/platforms/macosx/load.lua | 14 +++++++------- xmake/platforms/msys/config.lua | 6 +++--- xmake/platforms/watchos/config.lua | 2 +- xmake/platforms/watchos/load.lua | 4 ++-- xmake/platforms/windows/config.lua | 6 +++--- xmake/platforms/windows/load.lua | 4 ++-- 27 files changed, 77 insertions(+), 75 deletions(-) diff --git a/xmake/core/language/language.lua b/xmake/core/language/language.lua index cd42d8ae2..eedb2c9a2 100644 --- a/xmake/core/language/language.lua +++ b/xmake/core/language/language.lua @@ -646,9 +646,9 @@ end -- e.g. -- -- { --- binary = {"ld", "gc-ld", "dc-ld"} --- , static = {"ar", "gc-ar", "dc-ar"} --- , shared = {"sh", "dc-sh"} +-- binary = {"ld", "gcld", "dcld"} +-- , static = {"ar", "gcar", "dcar"} +-- , shared = {"sh", "dcsh"} -- } -- function language.targetkinds() diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index ed1f47daa..d5a410b31 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -39,7 +39,7 @@ local compiler = require("tool/compiler") -- add flags from the platform function linker:_add_flags_from_platform(flags, targetkind) - -- attempt to add special lanugage flags first for target kind, e.g. binary.go.gc-ldflags, static.dc-arflags + -- attempt to add special lanugage flags first for target kind, e.g. binary.go.gcldflags, static.dcarflags if targetkind then local toolkind = self:kind() local toolname = self:name() @@ -57,7 +57,7 @@ function linker:_add_flags_from_linker(flags) local toolkind = self:kind() for _, flagkind in ipairs(self:_flagkinds()) do - -- attempt to add special lanugage flags first, e.g. gc-ldflags, dc-arflags + -- attempt to add special lanugage flags first, e.g. gcldflags, dcarflags table.join2(flags, self:get(toolkind .. 'flags') or self:get(flagkind)) end end @@ -185,7 +185,7 @@ function linker.load(targetkind, sourcekinds, target) local toolname = linkertool:name() for _, flagkind in ipairs(instance:_flagkinds()) do - -- add special lanugage flags first, e.g. go.gc-ldflags or gcc.ldflags or gc-ldflags or ldflags + -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags linkertool:add(toolkind .. 'flags', platform.get(toolname .. '.' .. toolkind .. 'flags') or platform.get(toolkind .. 'flags')) linkertool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index ef04e31bf..6cfaf5802 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -27,7 +27,9 @@ local os = require("base/os") local path = require("base/path") local utils = require("base/utils") local table = require("base/table") +local global = require("base/global") local interpreter = require("base/interpreter") +local config = require("project/config") local language = require("language/language") local sandbox = require("sandbox/sandbox") diff --git a/xmake/languages/dlang/xmake.lua b/xmake/languages/dlang/xmake.lua index 6481381f0..f30706797 100644 --- a/xmake/languages/dlang/xmake.lua +++ b/xmake/languages/dlang/xmake.lua @@ -28,7 +28,7 @@ language("dlang") set_sourceflags {dc = "dcflags"} -- set target kinds - set_targetkinds {binary = "dc-ld", static = "dc-ar", shared = "dc-sh"} + set_targetkinds {binary = "dcld", static = "dcar", shared = "dcsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -113,9 +113,9 @@ language("dlang") , {nil, "dc", "kv", nil, "The Dlang Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "dc-ld", "kv", nil, "The Dlang Linker" } - , {nil, "dc-ar", "kv", nil, "The Dlang Static Library Archiver" } - , {nil, "dc-sh", "kv", nil, "The Dlang Shared Library Linker" } + , {nil, "dcld", "kv", nil, "The Dlang Linker" } + , {nil, "dcar", "kv", nil, "The Dlang Static Library Archiver" } + , {nil, "dcsh", "kv", nil, "The Dlang Shared Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } , {nil, "links", "kv", nil, "The Link Libraries" } diff --git a/xmake/languages/golang/xmake.lua b/xmake/languages/golang/xmake.lua index 385e43c8b..d78d64e1d 100644 --- a/xmake/languages/golang/xmake.lua +++ b/xmake/languages/golang/xmake.lua @@ -28,7 +28,7 @@ language("golang") set_sourceflags {gc = "gcflags"} -- set target kinds - set_targetkinds {binary = "gc-ld", static = "gc-ar"} + set_targetkinds {binary = "gcld", static = "gcar"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags"} @@ -109,7 +109,7 @@ language("golang") , {nil, "go", "kv", nil, "The Golang Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "gc-ld", "kv", nil, "The Golang Linker" } + , {nil, "gcld", "kv", nil, "The Golang Linker" } , {nil, "go-ar", "kv", nil, "The Golang Static Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } diff --git a/xmake/languages/rust/xmake.lua b/xmake/languages/rust/xmake.lua index 8afd1ea7a..044ed0111 100644 --- a/xmake/languages/rust/xmake.lua +++ b/xmake/languages/rust/xmake.lua @@ -28,7 +28,7 @@ language("rust") set_sourceflags {rc = "rcflags"} -- set target kinds - set_targetkinds {binary = "rc-ld", static = "rc-ar", shared = "rc-sh"} + set_targetkinds {binary = "rcld", static = "rcar", shared = "rcsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -94,9 +94,9 @@ language("rust") , {nil, "rc", "kv", nil, "The Rust Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , {nil, "rc-ld", "kv", nil, "The Rust Linker" } - , {nil, "rc-ar", "kv", nil, "The Rust Static Library Archiver" } - , {nil, "rc-sh", "kv", nil, "The Rust Shared Library Linker" } + , {nil, "rcld", "kv", nil, "The Rust Linker" } + , {nil, "rcar", "kv", nil, "The Rust Static Library Archiver" } + , {nil, "rcsh", "kv", nil, "The Rust Shared Library Linker" } , {category = "Cross Complation Configuration/Builtin Flags Configuration" } , {nil, "linkdirs", "kv", nil, "The Link Search Directories" } diff --git a/xmake/languages/swift/xmake.lua b/xmake/languages/swift/xmake.lua index a3b121a13..3ac1f0b87 100644 --- a/xmake/languages/swift/xmake.lua +++ b/xmake/languages/swift/xmake.lua @@ -28,7 +28,7 @@ language("swift") set_sourceflags {sc = "scflags"} -- set target kinds - set_targetkinds {binary = "sc-ld", static = "ar", shared = "sc-sh"} + set_targetkinds {binary = "scld", static = "ar", shared = "scsh"} -- set target flags set_targetflags {binary = "ldflags", static = "arflags", shared = "shflags"} @@ -153,8 +153,8 @@ language("swift") , { nil, "sc", "kv", nil, "The Swift Compiler" } , {category = "Cross Complation Configuration/Linker Configuration" } - , { nil, "sc-ld", "kv", nil, "The Swift Linker" } - , { nil, "sc-sh", "kv", nil, "The Swift Shared Library Linker" } + , { nil, "scld", "kv", nil, "The Swift Linker" } + , { nil, "scsh", "kv", nil, "The Swift Shared Library Linker" } , { category = "Cross Complation Configuration/Builtin Flags Configuration" } , { nil, "links", "kv", nil, "The Link Libraries" } diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index eaadb249c..4d74c21ae 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -27,10 +27,10 @@ import("core.project.project") function init(self) -- init arflags - self:set("dc-arflags", "-lib") + self:set("dcarflags", "-lib") -- init shflags - self:set("dc-shflags", "-shared", "-fPIC") + self:set("dcshflags", "-shared", "-fPIC") -- init dcflags for the kind: shared self:set("shared.dcflags", "-fPIC") diff --git a/xmake/modules/core/tools/go.lua b/xmake/modules/core/tools/go.lua index 944a14eff..80230ba4f 100644 --- a/xmake/modules/core/tools/go.lua +++ b/xmake/modules/core/tools/go.lua @@ -27,7 +27,7 @@ import("core.project.project") function init(self) -- init arflags - self:set("gc-arflags", "grc") + self:set("gcarflags", "grc") -- init the file formats self:set("formats", { static = "$(name).a" }) diff --git a/xmake/modules/core/tools/ldc2.lua b/xmake/modules/core/tools/ldc2.lua index ef4796156..9cf9fd48b 100644 --- a/xmake/modules/core/tools/ldc2.lua +++ b/xmake/modules/core/tools/ldc2.lua @@ -28,7 +28,7 @@ function init(self) _super.init(self) -- init shflags - self:set("dc-shflags", "-shared") + self:set("dcshflags", "-shared") -- init cxflags for the kind: shared self:set("shared.dcflags", "") diff --git a/xmake/modules/core/tools/rustc.lua b/xmake/modules/core/tools/rustc.lua index 227c6ad43..0ec83c803 100644 --- a/xmake/modules/core/tools/rustc.lua +++ b/xmake/modules/core/tools/rustc.lua @@ -27,13 +27,13 @@ import("core.project.project") function init(self) -- init arflags - self:set("rc-arflags", "--crate-type=lib") + self:set("rcarflags", "--crate-type=lib") -- init shflags - self:set("rc-shflags", "--crate-type=dylib") + self:set("rcshflags", "--crate-type=dylib") -- init ldflags - self:set("rc-ldflags", "--crate-type=bin") + self:set("rcldflags", "--crate-type=bin") -- init the file formats self:set("formats", { static = "lib$(name).rlib" }) diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua index f199d08ba..e99a4d14a 100644 --- a/xmake/platforms/android/config.lua +++ b/xmake/platforms/android/config.lua @@ -81,7 +81,7 @@ function _toolchains() local rc_sh = toolchain("the rust shared library linker") local rc_ar = toolchain("the rust static library archiver") local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar} + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} -- init the c compiler cc:add({name = "gcc", cross = cross}, "clang") diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua index b0ed21ba3..773d69fcc 100644 --- a/xmake/platforms/android/load.lua +++ b/xmake/platforms/android/load.lua @@ -305,15 +305,15 @@ function main(platform) if targets_rust[arch] then platform:add("rcflags", "--target=" .. targets_rust[arch]) end - platform:add("rc-shflags", "-C link-args=\"" .. (table.concat(platform:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) - platform:add("rc-ldflags", "-C link-args=\"" .. (table.concat(platform:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + platform:add("rcshflags", "-C link-args=\"" .. (table.concat(platform:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + platform:add("rcldflags", "-C link-args=\"" .. (table.concat(platform:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) local sh = config.get("sh") if sh then - platform:add("rc-shflags", "-C linker=" .. sh) + platform:add("rcshflags", "-C linker=" .. sh) end local ld = config.get("ld") if ld then - platform:add("rc-ldflags", "-C linker=" .. ld) + platform:add("rcldflags", "-C linker=" .. ld) end end diff --git a/xmake/platforms/bsd/config.lua b/xmake/platforms/bsd/config.lua index 3a4912f78..69164b8b4 100644 --- a/xmake/platforms/bsd/config.lua +++ b/xmake/platforms/bsd/config.lua @@ -80,9 +80,9 @@ function _toolchains() local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler diff --git a/xmake/platforms/bsd/load.lua b/xmake/platforms/bsd/load.lua index e1357e717..fcbbc61ff 100644 --- a/xmake/platforms/bsd/load.lua +++ b/xmake/platforms/bsd/load.lua @@ -66,16 +66,16 @@ function main(platform) platform:add("asflags", archflags) -- init flags for golang - platform:set("gc-ldflags", "") + platform:set("gcldflags", "") -- init flags for dlang local dc_archs = { i386 = "-m32", x86_64 = "-m64" } platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "") + platform:add("dcshflags", dc_archs[arch] or "") + platform:add("dcldflags", dc_archs[arch] or "") -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") + platform:set("rcshflags", "") + platform:set("rcldflags", "") end diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua index 6c963188d..26f008970 100644 --- a/xmake/platforms/cygwin/config.lua +++ b/xmake/platforms/cygwin/config.lua @@ -79,9 +79,9 @@ function _toolchains() local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua index 2a7f52aa1..1e3592f45 100644 --- a/xmake/platforms/iphoneos/config.lua +++ b/xmake/platforms/iphoneos/config.lua @@ -53,7 +53,7 @@ function _toolchains() local sc_ld = toolchain("the swift linker") local sc_sh = toolchain("the swift shared library linker") local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh} + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} -- init the c compiler cc:add({name = "clang", cross = cross}) diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/platforms/iphoneos/load.lua index c41dc19d6..7d54e24be 100644 --- a/xmake/platforms/iphoneos/load.lua +++ b/xmake/platforms/iphoneos/load.lua @@ -56,7 +56,7 @@ function main(platform) -- init flags for swift (with platform:add("ldflags and platform:add("shflags) platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua index 489c8d15e..ac9b42931 100644 --- a/xmake/platforms/linux/config.lua +++ b/xmake/platforms/linux/config.lua @@ -80,9 +80,9 @@ function _toolchains() local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua index e1357e717..fcbbc61ff 100644 --- a/xmake/platforms/linux/load.lua +++ b/xmake/platforms/linux/load.lua @@ -66,16 +66,16 @@ function main(platform) platform:add("asflags", archflags) -- init flags for golang - platform:set("gc-ldflags", "") + platform:set("gcldflags", "") -- init flags for dlang local dc_archs = { i386 = "-m32", x86_64 = "-m64" } platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "") + platform:add("dcshflags", dc_archs[arch] or "") + platform:add("dcldflags", dc_archs[arch] or "") -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") + platform:set("rcshflags", "") + platform:set("rcldflags", "") end diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index b440146cc..a5c0893fc 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -62,10 +62,10 @@ function _toolchains() local cu_ld = toolchain("the cuda linker") local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua index a9a7ff1cd..6d2547a75 100644 --- a/xmake/platforms/macosx/load.lua +++ b/xmake/platforms/macosx/load.lua @@ -74,21 +74,21 @@ function main(platform) -- init flags for swift if target_minver and xcode_sdkdir then platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end -- init flags for golang - platform:set("gc-ldflags", "") + platform:set("gcldflags", "") -- init flags for dlang local dc_archs = { i386 = "-m32", x86_64 = "-m64" } platform:add("dcflags", dc_archs[arch] or "") - platform:add("dc-shflags", dc_archs[arch] or "") - platform:add("dc-ldflags", dc_archs[arch] or "" ) + platform:add("dcshflags", dc_archs[arch] or "") + platform:add("dcldflags", dc_archs[arch] or "" ) -- init flags for rust - platform:set("rc-shflags", "") - platform:set("rc-ldflags", "") + platform:set("rcshflags", "") + platform:set("rcldflags", "") end diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua index f5fd3c0a4..dbb1be255 100644 --- a/xmake/platforms/msys/config.lua +++ b/xmake/platforms/msys/config.lua @@ -79,9 +79,9 @@ function _toolchains() local cu_ccbin = toolchain("the cuda host c++ compiler") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, mm = mm, mxx = mxx, - gc = gc, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua index 57504cb60..f16878b2e 100644 --- a/xmake/platforms/watchos/config.lua +++ b/xmake/platforms/watchos/config.lua @@ -52,7 +52,7 @@ function _toolchains() local sc_ld = toolchain("the swift linker") local sc_sh = toolchain("the swift shared library linker") local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["sc-ld"] = sc_ld, ["sc-sh"] = sc_sh} + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} -- init the c compiler cc:add({name = "clang", cross = cross}) diff --git a/xmake/platforms/watchos/load.lua b/xmake/platforms/watchos/load.lua index 78e251728..2e0204358 100644 --- a/xmake/platforms/watchos/load.lua +++ b/xmake/platforms/watchos/load.lua @@ -53,7 +53,7 @@ function main(platform) -- init flags for swift (with platform:add("ldflags and platform:add("shflags) platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-shflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("sc-ldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua index 04b92ce65..c74205efe 100644 --- a/xmake/platforms/windows/config.lua +++ b/xmake/platforms/windows/config.lua @@ -53,9 +53,9 @@ function _toolchains() 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, ["gc-ld"] = gc_ld, ["gc-ar"] = gc_ar, - dc = dc, ["dc-ld"] = dc_ld, ["dc-sh"] = dc_sh, ["dc-ar"] = dc_ar, - rc = rc, ["rc-ld"] = rc_ld, ["rc-sh"] = rc_sh, ["rc-ar"] = rc_ar, + 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, ["cu-ld"] = cu_ld} -- init the c compiler diff --git a/xmake/platforms/windows/load.lua b/xmake/platforms/windows/load.lua index 78217e5f1..710cb8723 100644 --- a/xmake/platforms/windows/load.lua +++ b/xmake/platforms/windows/load.lua @@ -33,6 +33,6 @@ function main(platform) -- init flags for dlang local dc_archs = { x86 = "-m32", x64 = "-m64" } platform:add("dcflags", dc_archs[arch]) - platform:add("dc-shflags", dc_archs[arch]) - platform:add("dc-ldflags", dc_archs[arch]) + platform:add("dcshflags", dc_archs[arch]) + platform:add("dcldflags", dc_archs[arch]) end -- cgit v1.3.1 From ed247a74689d45a4cf9a8a8e4aee64dba741df43 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 21:28:07 +0800 Subject: check tool for toolchain --- xmake/core/platform/platform.lua | 1 - xmake/core/tool/toolchain.lua | 99 ++++++++++++++++++++++++++++++++++++++-- xmake/toolchains/xcode/xmake.lua | 16 +++++++ 3 files changed, 110 insertions(+), 6 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 9a3aff93a..51cbcf33f 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -32,7 +32,6 @@ local toolchain = require("tool/toolchain") local sandbox = require("sandbox/sandbox") local config = require("project/config") local global = require("base/global") -local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 6cfaf5802..6ebae5152 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -28,10 +28,12 @@ local path = require("base/path") local utils = require("base/utils") local table = require("base/table") local global = require("base/global") +local option = require("base/option") local interpreter = require("base/interpreter") local config = require("project/config") local language = require("language/language") local sandbox = require("sandbox/sandbox") +local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance function _instance.new(name, info, rootdir) @@ -84,6 +86,15 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) + local toolpathes = self:get("toolsets." .. toolkind) + if toolpathes then + for _, toolpath in ipairs(toolpathes) do + local program, toolname = self:_checktool(toolkind, toolpath) + if program then + return program, toolname + end + end + end end -- get the toolchain script @@ -91,6 +102,83 @@ function _instance:script(name) return self._INFO:get(name) end +-- get the bin directory +function _instance:bindir() + return config.get("bin") or self:get("bindir") +end + +-- get the tool description from the tool kind +function _instance:_description(toolkind) + local descriptions = self._DESCRIPTIONS + if not descriptions then + descriptions = + { + cc = "the c compiler", + cxx = "the c++ compiler", + ld = "the linker", + sh = "the shared library linker", + ar = "the static library archiver", + ex = "the static library extractor", + strip = "the symbols stripper", + dsymutil = "the symbols generator", + mm = "the objc compiler", + mxx = "the objc++ compiler", + as = "the assember", + sc = "the swift compiler", + scld = "the swift linker", + scsh = "the swift shared library linker", + gc = "the golang compiler", + gcld = "the golang linker", + gcar = "the golang static library archiver", + dc = "the dlang compiler", + dcld = "the dlang linker", + dcsh = "the dlang shared library linker", + dcar = "the dlang static library archiver", + rc = "the rust compiler", + rcld = "the rust linker", + rcsh = "the rust shared library linker", + rcar = "the rust static library archiver", + cu = "the cuda compiler", + culd = "the cuda linker", + cuccbin = "the cuda host c++ compiler", + } + self._DESCRIPTIONS = descriptions + end + return descriptions +end + +-- check the given tool path +function _instance:_checktool(toolkind, toolpath) + + -- get find_tool + local find_tool = self._find_tool + if not find_tool then + find_tool = sandbox_module.import("lib.detect.find_tool", {anonymous = true}) + self._find_tool = find_tool + end + + -- find tool program + local program, toolname + local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) + if tool then + program = tool.program + toolname = tool.name + end + + -- get tool description from the tool kind + local description = self:_description(toolkind) or ("unknown toolkind " .. toolkind) + + -- trace + if option.get("verbose") then + if program then + utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) + else + utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) + end + end + return program, toolname +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -137,13 +225,14 @@ end function toolchain._apis() return { - values = + values = + { + "toolchain.set_bindir" + } + , keyvalues = { -- toolchain.set_xxx - "toolchain.set_cc" - , "toolchain.set_cxx" - , "toolchain.set_ld" - , "toolchain.set_sh" + "toolchain.set_toolsets" } , script = { diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 633f5a45d..1c39a6453 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,3 +21,19 @@ -- define toolchain toolchain("xcode") + -- set toolsets + set_toolsets("cc", "xcrun -sdk macosx clang") + set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("as", "xcrun -sdk macosx clang") + set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") + set_toolsets("ar", "xcrun -sdk macosx ar") + set_toolsets("ex", "xcrun -sdk macosx ar") + set_toolsets("strip", "xcrun -sdk macosx strip") + set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") + set_toolsets("mm", "xcrun -sdk macosx clang") + set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") + set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") + set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- cgit v1.3.1 From 3e1175f04cf35ae186e0c930bdce7aa467bab818 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 21:45:11 +0800 Subject: fix some toolchain bugs --- xmake/core/tool/toolchain.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 6ebae5152..8a62afd8d 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -88,7 +88,7 @@ end function _instance:tool(toolkind) local toolpathes = self:get("toolsets." .. toolkind) if toolpathes then - for _, toolpath in ipairs(toolpathes) do + for _, toolpath in ipairs(table.wrap(toolpathes)) do local program, toolname = self:_checktool(toolkind, toolpath) if program then return program, toolname @@ -144,7 +144,7 @@ function _instance:_description(toolkind) } self._DESCRIPTIONS = descriptions end - return descriptions + return descriptions[toolkind] end -- check the given tool path -- cgit v1.3.1 From a41ba24cf16ee3426c288f569cd41ae8cec4ab6d Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 16 May 2020 21:51:26 +0800 Subject: fix config cache for checking tool --- xmake/core/platform/platform.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 51cbcf33f..d80b72be5 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -366,6 +366,7 @@ function platform.tool(toolkind, plat) if program then config.set(toolkind, program, {force = true, readonly = true}) config.set("__toolname_" .. toolkind, toolname) + config.save() else -- TODO deprecated -- check it first -- cgit v1.3.1 From c0afaacde90abf081bab19279c3ea6d4dbeae86d Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 17 May 2020 21:57:39 +0800 Subject: add toolchain check --- xmake/core/tool/toolchain.lua | 57 +++++++++++++++--------- xmake/platforms/macosx/config.lua | 3 +- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/xcode/check.lua | 28 ++++++++++++ xmake/toolchains/xcode/load.lua | 94 +++++++++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 5 +++ 6 files changed, 167 insertions(+), 22 deletions(-) create mode 100644 xmake/toolchains/xcode/check.lua create mode 100644 xmake/toolchains/xcode/load.lua diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8a62afd8d..246d46a99 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,26 +61,6 @@ end -- get the toolchain configuration function _instance:get(name) - - -- attempt to get the static configure value - local value = self._INFO:get(name) - if value ~= nil then - return value - end - - -- lazy loading toolchain if get other configuration - if not self._LOADED and not self:_is_builtin_conf(name) then - local on_load = self._INFO:get("load") - if on_load then - local ok, errors = sandbox.load(on_load, self) - if not ok then - os.raise(errors) - end - end - self._LOADED = true - end - - -- get other toolchain info return self._INFO:get(name) end @@ -107,6 +87,34 @@ function _instance:bindir() return config.get("bin") or self:get("bindir") end +-- do load +function _instance:_load() + if not self._LOADED then + local on_load = self._INFO:get("load") + if on_load then + local ok, errors = sandbox.load(on_load, self) + if not ok then + os.raise(errors) + end + end + self._LOADED = true + end +end + +-- do check +function _instance:_check() + if not self._CHECKED then + local on_check = self._INFO:get("check") + if on_check then + local ok, errors = sandbox.load(on_check, self) + if not ok then + os.raise(errors) + end + end + self._CHECKED = true + end +end + -- get the tool description from the tool kind function _instance:_description(toolkind) local descriptions = self._DESCRIPTIONS @@ -150,6 +158,9 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) + -- ensure to check this toolchain first + self:_check() + -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -176,6 +187,11 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end + + -- we only load it when checking the given tool successfully + if program then + self:_load() + end return program, toolname end @@ -238,6 +254,7 @@ function toolchain._apis() { -- toolchain.on_xxx "toolchain.on_load" + , "toolchain.on_check" } , dictionary = { diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua index a5c0893fc..a1713a657 100644 --- a/xmake/platforms/macosx/config.lua +++ b/xmake/platforms/macosx/config.lua @@ -146,6 +146,7 @@ end -- check it function main(platform, name) + --[[ -- only check the given config name? if name then local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] @@ -159,6 +160,6 @@ function main(platform, name) -- check xcode check_xcode(config, true) - end + end]] end diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index b7abea032..fc390d953 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -37,7 +37,7 @@ platform("macosx") set_installdir("/usr/local") -- on check project configuration - on_config_check("config") +-- on_config_check("config") -- on check global configuration on_global_check("global") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua new file mode 100644 index 000000000..c10fe48d9 --- /dev/null +++ b/xmake/toolchains/xcode/check.lua @@ -0,0 +1,28 @@ +--!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.project.config") +import("private.platform.check_xcode") + +-- main entry +function main(toolchain) + check_xcode(config, true) +end diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua new file mode 100644 index 000000000..96d459414 --- /dev/null +++ b/xmake/toolchains/xcode/load.lua @@ -0,0 +1,94 @@ +--!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 load.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/toolchains/MacOSX.toolchain/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 1c39a6453..d9b1d9944 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -37,3 +37,8 @@ toolchain("xcode") set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") -- cgit v1.3.1 From 937bd96c26edc111a3226a4feb2a6748041ab461 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:39:36 +0800 Subject: check toolchains for macosx --- xmake/actions/global/main.lua | 5 - xmake/core/platform/platform.lua | 22 +-- .../sandbox/modules/import/core/base/global.lua | 25 --- .../sandbox/modules/import/core/project/config.lua | 7 +- xmake/core/tool/toolchain.lua | 33 ++-- xmake/platforms/android/check.lua | 155 +++++++++++++++++ xmake/platforms/android/config.lua | 155 ----------------- xmake/platforms/android/xmake.lua | 4 +- xmake/platforms/bsd/check.lua | 175 +++++++++++++++++++ xmake/platforms/bsd/config.lua | 175 ------------------- xmake/platforms/bsd/global.lua | 32 ---- xmake/platforms/bsd/xmake.lua | 7 +- xmake/platforms/cross/check.lua | 189 +++++++++++++++++++++ xmake/platforms/cross/config.lua | 189 --------------------- xmake/platforms/cross/xmake.lua | 4 +- xmake/platforms/cygwin/check.lua | 172 +++++++++++++++++++ xmake/platforms/cygwin/config.lua | 172 ------------------- xmake/platforms/cygwin/xmake.lua | 4 +- xmake/platforms/iphoneos/check.lua | 128 ++++++++++++++ xmake/platforms/iphoneos/config.lua | 128 -------------- xmake/platforms/iphoneos/global.lua | 36 ---- xmake/platforms/iphoneos/xmake.lua | 7 +- xmake/platforms/linux/check.lua | 175 +++++++++++++++++++ xmake/platforms/linux/config.lua | 175 ------------------- xmake/platforms/linux/global.lua | 32 ---- xmake/platforms/linux/xmake.lua | 7 +- xmake/platforms/macosx/check.lua | 175 +++++++++++++++++++ xmake/platforms/macosx/config.lua | 165 ------------------ xmake/platforms/macosx/global.lua | 36 ---- xmake/platforms/macosx/xmake.lua | 7 +- xmake/platforms/mingw/check.lua | 128 ++++++++++++++ xmake/platforms/mingw/config.lua | 128 -------------- xmake/platforms/mingw/xmake.lua | 4 +- xmake/platforms/msys/check.lua | 172 +++++++++++++++++++ xmake/platforms/msys/config.lua | 172 ------------------- xmake/platforms/msys/xmake.lua | 4 +- xmake/platforms/sdcc/check.lua | 114 +++++++++++++ xmake/platforms/sdcc/config.lua | 114 ------------- xmake/platforms/sdcc/xmake.lua | 4 +- xmake/platforms/watchos/check.lua | 124 ++++++++++++++ xmake/platforms/watchos/config.lua | 124 -------------- xmake/platforms/watchos/global.lua | 36 ---- xmake/platforms/watchos/xmake.lua | 7 +- xmake/platforms/windows/check.lua | 139 +++++++++++++++ xmake/platforms/windows/config.lua | 139 --------------- xmake/platforms/windows/global.lua | 49 ------ xmake/platforms/windows/xmake.lua | 7 +- xmake/toolchains/xcode/check.lua | 1 + 48 files changed, 1902 insertions(+), 2160 deletions(-) create mode 100644 xmake/platforms/android/check.lua delete mode 100644 xmake/platforms/android/config.lua create mode 100644 xmake/platforms/bsd/check.lua delete mode 100644 xmake/platforms/bsd/config.lua delete mode 100644 xmake/platforms/bsd/global.lua create mode 100644 xmake/platforms/cross/check.lua delete mode 100644 xmake/platforms/cross/config.lua create mode 100644 xmake/platforms/cygwin/check.lua delete mode 100644 xmake/platforms/cygwin/config.lua create mode 100644 xmake/platforms/iphoneos/check.lua delete mode 100644 xmake/platforms/iphoneos/config.lua delete mode 100644 xmake/platforms/iphoneos/global.lua create mode 100644 xmake/platforms/linux/check.lua delete mode 100644 xmake/platforms/linux/config.lua delete mode 100644 xmake/platforms/linux/global.lua create mode 100644 xmake/platforms/macosx/check.lua delete mode 100644 xmake/platforms/macosx/config.lua delete mode 100644 xmake/platforms/macosx/global.lua create mode 100644 xmake/platforms/mingw/check.lua delete mode 100644 xmake/platforms/mingw/config.lua create mode 100644 xmake/platforms/msys/check.lua delete mode 100644 xmake/platforms/msys/config.lua create mode 100644 xmake/platforms/sdcc/check.lua delete mode 100644 xmake/platforms/sdcc/config.lua create mode 100644 xmake/platforms/watchos/check.lua delete mode 100644 xmake/platforms/watchos/config.lua delete mode 100644 xmake/platforms/watchos/global.lua create mode 100644 xmake/platforms/windows/check.lua delete mode 100644 xmake/platforms/windows/config.lua delete mode 100644 xmake/platforms/windows/global.lua diff --git a/xmake/actions/global/main.lua b/xmake/actions/global/main.lua index 720eb0351..9472c9b24 100644 --- a/xmake/actions/global/main.lua +++ b/xmake/actions/global/main.lua @@ -59,11 +59,6 @@ function main() end end - -- check the global configure - if changed or option.get("clean") then - global.check() - end - -- load and check theme local themename = option.get("theme") if themename then diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index d80b72be5..677e36906 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -163,6 +163,14 @@ function _instance:data_add(name, data) self._DATA[name] = table.unwrap(table.join(self._DATA[name] or {}, data)) end +-- do check +function _instance:check() + local on_check = self:script("check") + if on_check then + on_check(self) + end +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -219,8 +227,7 @@ function platform._apis() { -- platform.on_xxx "platform.on_load" - , "platform.on_config_check" - , "platform.on_global_check" + , "platform.on_check" , "platform.on_environment_enter" , "platform.on_environment_leave" } @@ -367,17 +374,6 @@ function platform.tool(toolkind, plat) config.set(toolkind, program, {force = true, readonly = true}) config.set("__toolname_" .. toolkind, toolname) config.save() - else - -- TODO deprecated - -- check it first - local on_check = instance:script("config_check") - if on_check then - on_check(instance, toolkind) - end - - -- get it again - program = config.get(toolkind) - toolname = config.get("__toolname_" .. toolkind) end end diff --git a/xmake/core/sandbox/modules/import/core/base/global.lua b/xmake/core/sandbox/modules/import/core/base/global.lua index 4ea5b2745..9141a2d76 100644 --- a/xmake/core/sandbox/modules/import/core/base/global.lua +++ b/xmake/core/sandbox/modules/import/core/base/global.lua @@ -68,31 +68,6 @@ function sandbox_core_base_global.clear() return global.clear() end --- check the configure -function sandbox_core_base_global.check() - - -- check all platforms with the current host - for _, plat in ipairs(table.wrap(platform.plats())) do - - -- load platform - local instance, errors = platform.load(plat) - if not instance then - raise(errors) - end - - -- belong to the current host? - for _, host in ipairs(table.wrap(instance:hosts())) do - if host == os.host() then - local on_check = instance:script("global_check") - if on_check then - on_check(instance) - end - break - end - end - end -end - -- get all options function sandbox_core_base_global.options() return global.options() diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 449fac71f..c7121a8a4 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -116,12 +116,7 @@ function sandbox_core_project_config.check() -- get the current platform local instance, errors = platform.load() if instance then - - -- do check - local on_check = instance:script("config_check") - if on_check then - on_check(instance) - end + instance:check() else raise(errors) end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 246d46a99..e79a32b22 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -61,6 +61,19 @@ end -- get the toolchain configuration function _instance:get(name) + + -- attempt to get the static configure value + local value = self._INFO:get(name) + if value ~= nil then + return value + end + + -- lazy loading platform if get other configuration + if not self:_is_builtin_conf(name) then + self:_load() + end + + -- get other platform info return self._INFO:get(name) end @@ -102,17 +115,21 @@ function _instance:_load() end -- do check -function _instance:_check() +function _instance:check() + local checkok = true if not self._CHECKED then local on_check = self._INFO:get("check") if on_check then - local ok, errors = sandbox.load(on_check, self) - if not ok then - os.raise(errors) + local ok, results_or_errors = sandbox.load(on_check, self) + if ok then + checkok = results_or_errors + else + os.raise(results_or_errors) end end self._CHECKED = true end + return checkok end -- get the tool description from the tool kind @@ -158,9 +175,6 @@ end -- check the given tool path function _instance:_checktool(toolkind, toolpath) - -- ensure to check this toolchain first - self:_check() - -- get find_tool local find_tool = self._find_tool if not find_tool then @@ -187,11 +201,6 @@ function _instance:_checktool(toolkind, toolpath) utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) end end - - -- we only load it when checking the given tool successfully - if program then - self:_load() - end return program, toolname end diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua new file mode 100644 index 000000000..04d639483 --- /dev/null +++ b/xmake/platforms/android/check.lua @@ -0,0 +1,155 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_ndk") +import("detect.sdks.find_android_sdk") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + 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 ranlib = toolchain("the static library index generator") + local strip = toolchain("the symbols stripper") + local as = toolchain("the assember") + 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 toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, + rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} + + -- init the c compiler + cc:add({name = "gcc", cross = cross}, "clang") + + -- init the c++ compiler + cxx:add({name = "g++", cross = cross}, "clang++") + + -- init the c preprocessor + cpp:add({name = "gcc -E", cross = cross}, "clang -E") + + -- init the assember + as:add({name = "gcc", cross = cross}, "clang") + + -- init the linker + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add("clang++", "clang") + + -- init the shared library linker + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add("clang++", "clang") + + -- init the static library archiver + ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") + + -- init the static library index generator + ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") + + -- 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") + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("android.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armeabi-v7a") + + -- check android sdk + _check_android_sdk() + + -- check ndk + _check_ndk() + + -- check ld and sh, @note toolchains must be initialized after calling check_ndk() + local toolchains = singleton.get("android.toolchains", _toolchains) + check_toolchain(config, "ld", toolchains.ld) + check_toolchain(config, "sh", toolchains.sh) + end +end + diff --git a/xmake/platforms/android/config.lua b/xmake/platforms/android/config.lua deleted file mode 100644 index e99a4d14a..000000000 --- a/xmake/platforms/android/config.lua +++ /dev/null @@ -1,155 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_ndk") -import("detect.sdks.find_android_sdk") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the ndk toolchain -function _check_ndk() - local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) - if ndk then - config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global - config.set("bin", ndk.bindir, {force = true, readonly = true}) - config.set("cross", ndk.cross, {force = true, readonly = true}) - config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- check the android sdk -function _check_android_sdk() - local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) - if sdk then - config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- get gcc toolchain bin directory - local gcc_toolchain_bin = nil - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - gcc_toolchain_bin = path.join(gcc_toolchain, "bin") - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local strip = toolchain("the symbols stripper") - local as = toolchain("the assember") - 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 toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} - - -- init the c compiler - cc:add({name = "gcc", cross = cross}, "clang") - - -- init the c++ compiler - cxx:add({name = "g++", cross = cross}, "clang++") - - -- init the c preprocessor - cpp:add({name = "gcc -E", cross = cross}, "clang -E") - - -- init the assember - as:add({name = "gcc", cross = cross}, "clang") - - -- init the linker - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add("clang++", "clang") - - -- init the shared library linker - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add("clang++", "clang") - - -- init the static library archiver - ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library index generator - ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") - - -- 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") - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("android.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armeabi-v7a") - - -- check android sdk - _check_android_sdk() - - -- check ndk - _check_ndk() - - -- check ld and sh, @note toolchains must be initialized after calling check_ndk() - local toolchains = singleton.get("android.toolchains", _toolchains) - check_toolchain(config, "ld", toolchains.ld) - check_toolchain(config, "sh", toolchains.sh) - end -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 45a4eaf8d..cb7d52594 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -39,8 +39,8 @@ platform("android") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua new file mode 100644 index 000000000..1eb8834ef --- /dev/null +++ b/xmake/platforms/bsd/check.lua @@ -0,0 +1,175 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + 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 cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- 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++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/bsd/config.lua b/xmake/platforms/bsd/config.lua deleted file mode 100644 index 69164b8b4..000000000 --- a/xmake/platforms/bsd/config.lua +++ /dev/null @@ -1,175 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/bsd/global.lua b/xmake/platforms/bsd/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/bsd/global.lua +++ /dev/null @@ -1,32 +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 global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 3ea3ed9f6..d0cacd28a 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -36,11 +36,8 @@ platform("bsd") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua new file mode 100644 index 000000000..833dcb921 --- /dev/null +++ b/xmake/platforms/cross/check.lua @@ -0,0 +1,189 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "none") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get llvm toolchains +function _toolchains_llvm() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + 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 strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", "clang") + + -- init the c preprocessor + cpp:add("$(env CPP)", "clang -E") + + -- init the c++ compiler + cxx:add("$(env CXX)", "clang", "clang++") + + -- init the assember + as:add("$(env AS)", "clang") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") + + -- init the static library archiver + ar:add("$(env AR)", "llvm-ar") + + -- init the static library extractor + ex:add("$(env AR)", "llvm-ar") + + -- init the static library index generator + ranlib:add("$(env RANLIB)", "llvm-ranlib") + + -- init the symbols stripper + strip:add("$(env STRIP)", "llvm-strip") + return toolchains +end + +-- get toolchains +function _toolchains() + + -- get cross prefix + local cross = config.get("cross") or "" + + -- for llvm toolchains? + if cross == "" and config.get("toolchain") == "llvm" then + return _toolchains_llvm() + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + 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 strip = toolchain("the symbols stripper") + local ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library index generator + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/cross/config.lua b/xmake/platforms/cross/config.lua deleted file mode 100644 index b159cf5c1..000000000 --- a/xmake/platforms/cross/config.lua +++ /dev/null @@ -1,189 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "none") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get llvm toolchains -function _toolchains_llvm() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", "clang") - - -- init the c preprocessor - cpp:add("$(env CPP)", "clang -E") - - -- init the c++ compiler - cxx:add("$(env CXX)", "clang", "clang++") - - -- init the assember - as:add("$(env AS)", "clang") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") - - -- init the static library archiver - ar:add("$(env AR)", "llvm-ar") - - -- init the static library extractor - ex:add("$(env AR)", "llvm-ar") - - -- init the static library index generator - ranlib:add("$(env RANLIB)", "llvm-ranlib") - - -- init the symbols stripper - strip:add("$(env STRIP)", "llvm-strip") - return toolchains -end - --- get toolchains -function _toolchains() - - -- get cross prefix - local cross = config.get("cross") or "" - - -- for llvm toolchains? - if cross == "" and config.get("toolchain") == "llvm" then - return _toolchains_llvm() - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library index generator - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index 31e7f6d95..a76dde03c 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -30,8 +30,8 @@ platform("cross") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua new file mode 100644 index 000000000..3b1221387 --- /dev/null +++ b/xmake/platforms/cygwin/check.lua @@ -0,0 +1,172 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + 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 cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- 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++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/cygwin/config.lua b/xmake/platforms/cygwin/config.lua deleted file mode 100644 index 26f008970..000000000 --- a/xmake/platforms/cygwin/config.lua +++ /dev/null @@ -1,172 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index e43c5e35c..32ab7df58 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -36,8 +36,8 @@ platform("cygwin") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua new file mode 100644 index 000000000..94a3a9ae9 --- /dev/null +++ b/xmake/platforms/iphoneos/check.lua @@ -0,0 +1,128 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + + -- init cross + local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cpp = toolchain("the c preprocessor") + local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c preprocessor + cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "arm64") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/iphoneos/config.lua b/xmake/platforms/iphoneos/config.lua deleted file mode 100644 index 1e3592f45..000000000 --- a/xmake/platforms/iphoneos/config.lua +++ /dev/null @@ -1,128 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") - - -- init cross - local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cpp = toolchain("the c preprocessor") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/iphoneos/global.lua b/xmake/platforms/iphoneos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/iphoneos/global.lua +++ /dev/null @@ -1,36 +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 global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 2f6bcf00f..6d2af82ae 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -33,11 +33,8 @@ platform("iphoneos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua new file mode 100644 index 000000000..1671ee0e9 --- /dev/null +++ b/xmake/platforms/linux/check.lua @@ -0,0 +1,175 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.arch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + 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 cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, + mm = mm, mxx = mxx, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add("$(env STRIP)", {name = "strip", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- 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++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("linux.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/linux/config.lua b/xmake/platforms/linux/config.lua deleted file mode 100644 index ac9b42931..000000000 --- a/xmake/platforms/linux/config.lua +++ /dev/null @@ -1,175 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/linux/global.lua b/xmake/platforms/linux/global.lua deleted file mode 100644 index d74d84943..000000000 --- a/xmake/platforms/linux/global.lua +++ /dev/null @@ -1,32 +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 global.lua --- - --- imports -import("core.base.global") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 53517239a..21e4d2e51 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -36,11 +36,8 @@ platform("linux") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua new file mode 100644 index 000000000..ff552ad6b --- /dev/null +++ b/xmake/platforms/macosx/check.lua @@ -0,0 +1,175 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") + +--[[ +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init cross + local cross = "xcrun -sdk macosx " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + 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 cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + cxx:add("clang", "clang++", "gcc", "g++") + + -- init the assember + as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + ld:add("clang++", "g++", "clang", "gcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + sh:add("clang++", "g++", "clang", "gcc") + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") + + -- init the static library extractor + ex:add({name = "ar", cross = cross}, "ar") + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}, "strip") + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add("clang", "clang++", "gcc", "g++") + + -- init the swift compiler and linker + sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") + + -- 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") + cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") + + return toolchains +end]] + +-- check it +function main(platform) + + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end + end + + --[[ + -- only check the given config name? + if name then + local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config) + + -- check xcode + check_xcode(config, true) + end]] +end + diff --git a/xmake/platforms/macosx/config.lua b/xmake/platforms/macosx/config.lua deleted file mode 100644 index a1713a657..000000000 --- a/xmake/platforms/macosx/config.lua +++ /dev/null @@ -1,165 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init cross - local cross = "xcrun -sdk macosx " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add("clang", "clang++", "gcc", "g++") - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add("clang++", "g++", "clang", "gcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add("clang++", "g++", "clang", "gcc") - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross}, "ar") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}, "strip") - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add("clang", "clang++", "gcc", "g++") - - -- init the swift compiler and linker - sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - - -- 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") - cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") - - return toolchains -end - --- check it -function main(platform, name) - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] -end - diff --git a/xmake/platforms/macosx/global.lua b/xmake/platforms/macosx/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/macosx/global.lua +++ /dev/null @@ -1,36 +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 global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index fc390d953..512499c7c 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -36,11 +36,8 @@ platform("macosx") -- set install directory set_installdir("/usr/local") - -- on check project configuration --- on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua new file mode 100644 index 000000000..9905a53cc --- /dev/null +++ b/xmake/platforms/mingw/check.lua @@ -0,0 +1,128 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_mingw") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the mingw toolchain +function _check_mingw() + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- get toolchains +function _toolchains() + + -- get cross + local cross = config.get("cross") + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = config.get("bin") + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + 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 ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local mrc = toolchain("the resource compiler") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "g++", cross = cross}) + + -- init the c preprocessor + cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) + + -- init the resource compiler + mrc:add({name = "windres", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "x86_64") + + -- check mingw + _check_mingw() + end +end + diff --git a/xmake/platforms/mingw/config.lua b/xmake/platforms/mingw/config.lua deleted file mode 100644 index bbfc6f7f9..000000000 --- a/xmake/platforms/mingw/config.lua +++ /dev/null @@ -1,128 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_mingw") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the mingw toolchain -function _check_mingw() - local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) - if mingw then - config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - config.set("cross", mingw.cross, {readonly = true, force = true}) - config.set("bin", mingw.bindir, {readonly = true, force = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local mrc = toolchain("the resource compiler") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the resource compiler - mrc:add({name = "windres", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "x86_64") - - -- check mingw - _check_mingw() - end -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 7b5ad2624..e119f137f 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -33,8 +33,8 @@ platform("mingw") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua new file mode 100644 index 000000000..8c5a2dcdd --- /dev/null +++ b/xmake/platforms/msys/check.lua @@ -0,0 +1,172 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + + -- init the default architecture + config.set("arch", config.get("cross") and "none" or os.subarch()) + + -- trace + print("checking for the architecture ... %s", config.get("arch")) + end +end + +-- get toolchains +function _toolchains() + + -- find cross toolchain + local cross = "" + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + cross = cross_toolchain.cross + end + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + 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 cu_ccbin = toolchain("the cuda host c++ compiler") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, + mm = mm, mxx = mxx, + 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + + -- init the c compiler + cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add("$(env CXX)") + cxx:add({name = "gcc", cross = cross}) + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "g++", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) + + -- init the linker + ld:add("$(env LD)", "$(env CXX)") + ld:add({name = "g++", cross = cross}) + ld:add({name = "gcc", cross = cross}) + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)") + sh:add({name = "g++", cross = cross}) + sh:add({name = "gcc", cross = cross}) + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the static library extractor + ex:add("$(env AR)", {name = "ar", cross = cross}) + + -- init the objc compiler + mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) + + -- init the objc++ compiler + mxx:add("$(env MXX)") + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + mxx:add({name = "gcc", cross = cross}) + mxx:add({name = "g++", cross = cross}) + + -- 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++", "clang") + cu_ld:add("nvcc") + if not cross or cross == "" then + cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") + end + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("msys.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + end +end + diff --git a/xmake/platforms/msys/config.lua b/xmake/platforms/msys/config.lua deleted file mode 100644 index dbb1be255..000000000 --- a/xmake/platforms/msys/config.lua +++ /dev/null @@ -1,172 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("msys.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - end -end - diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index b3abadbf9..69c56db22 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -36,8 +36,8 @@ platform("msys") -- set install directory set_installdir("/usr/local") - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/sdcc/check.lua b/xmake/platforms/sdcc/check.lua new file mode 100644 index 000000000..6532ea00e --- /dev/null +++ b/xmake/platforms/sdcc/check.lua @@ -0,0 +1,114 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("detect.sdks.find_cross_toolchain") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_toolchain") + +-- check the architecture +function _check_arch() + + -- get the architecture + local arch = config.get("arch") + if not arch then + config.set("arch", "stm8") + end +end + +-- check the cross toolchain +function _check_cross_toolchain() + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + if cross_toolchain.bindir and is_host("windows") then + os.addenv("PATH", cross_toolchain.bindir) + end + end +end + +-- get toolchains +function _toolchains() + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ compiler") + local cpp = toolchain("the c preprocessor") + 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 ranlib = toolchain("the static library index generator") + local as = toolchain("the assember") + local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} + + -- init the c compiler + cc:add("$(env CC)", "sdcc") + + -- init the c preprocessor + cpp:add("$(env CPP)", "sdcpp") + + -- init the c++ compiler + cxx:add("$(env CXX)", "sdcc") + + -- init the assember + as:add("$(env AS)", "sdcc") + + -- init the linker + ld:add("$(env LD)", "$(env CXX)", "sdcc") + + -- init the shared library linker + sh:add("$(env SH)", "$(env CXX)", "sdcc") + + -- init the static library archiver + ar:add("$(env AR)", "sdar") + + -- init the static library extractor + ex:add("$(env AR)", "sdar") + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("cross.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + _check_arch() + + -- check cross toolchain + _check_cross_toolchain() + end +end + diff --git a/xmake/platforms/sdcc/config.lua b/xmake/platforms/sdcc/config.lua deleted file mode 100644 index ad2f14626..000000000 --- a/xmake/platforms/sdcc/config.lua +++ /dev/null @@ -1,114 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "stm8") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} - - -- init the c compiler - cc:add("$(env CC)", "sdcc") - - -- init the c preprocessor - cpp:add("$(env CPP)", "sdcpp") - - -- init the c++ compiler - cxx:add("$(env CXX)", "sdcc") - - -- init the assember - as:add("$(env AS)", "sdcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "sdcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "sdcc") - - -- init the static library archiver - ar:add("$(env AR)", "sdar") - - -- init the static library extractor - ex:add("$(env AR)", "sdar") - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/platforms/sdcc/xmake.lua index b06094f9f..ad2f02be9 100644 --- a/xmake/platforms/sdcc/xmake.lua +++ b/xmake/platforms/sdcc/xmake.lua @@ -30,8 +30,8 @@ platform("sdcc") -- set formats set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} - -- on check project configuration - on_config_check("config") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua new file mode 100644 index 000000000..89086d74c --- /dev/null +++ b/xmake/platforms/watchos/check.lua @@ -0,0 +1,124 @@ +--!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 check.lua +-- + +-- imports +import("core.project.config") +import("core.base.singleton") +import("private.platform.toolchain") +import("private.platform.check_arch") +import("private.platform.check_xcode") +import("private.platform.check_toolchain") + +-- get toolchains +function _toolchains() + + -- init architecture + local arch = config.get("arch") + local simulator = (arch == "i386") + + -- init cross + local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " + + -- init toolchains + local cc = toolchain("the c compiler") + local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") + local dsymutil = toolchain("the symbols generator") + local mm = toolchain("the objc compiler") + local mxx = toolchain("the objc++ compiler") + local as = toolchain("the assember") + local sc = toolchain("the swift compiler") + local sc_ld = toolchain("the swift linker") + local sc_sh = toolchain("the swift shared library linker") + local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, + mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} + + -- init the c compiler + cc:add({name = "clang", cross = cross}) + + -- init the c++ compiler + cxx:add({name = "clang", cross = cross}) + cxx:add({name = "clang++", cross = cross}) + + -- init the assember + if simulator then + as:add({name = "clang", cross = cross}) + else + as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) + end + + -- init the linker + ld:add({name = "clang++", cross = cross}) + ld:add({name = "clang", cross = cross}) + + -- init the shared library linker + sh:add({name = "clang++", cross = cross}) + sh:add({name = "clang", cross = cross}) + + -- init the static library archiver + ar:add({name = "ar", cross = cross}) + + -- init the static library extractor + ex:add({name = "ar", cross = cross}) + + -- init the symbols stripper + strip:add({name = "strip", cross = cross}) + + -- init the symbols generator + dsymutil:add({name = "dsymutil", cross = cross}) + + -- init the objc compiler + mm:add({name = "clang", cross = cross}) + + -- init the objc++ compiler + mxx:add({name = "clang", cross = cross}) + mxx:add({name = "clang++", cross = cross}) + + -- init the swift compiler and linker + sc:add({name = "swiftc", cross = cross}) + sc_ld:add({name = "swiftc", cross = cross}) + sc_sh:add({name = "swiftc", cross = cross}) + + return toolchains +end + +-- check it +function main(platform, name) + + -- only check the given config name? + if name then + local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] + if toolchain then + check_toolchain(config, name, toolchain) + end + else + + -- check arch + check_arch(config, "armv7k") + + -- check xcode + check_xcode(config) + end +end + diff --git a/xmake/platforms/watchos/config.lua b/xmake/platforms/watchos/config.lua deleted file mode 100644 index f16878b2e..000000000 --- a/xmake/platforms/watchos/config.lua +++ /dev/null @@ -1,124 +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 config.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") - local simulator = (arch == "i386") - - -- init cross - local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config, "armv7k") - - -- check xcode - check_xcode(config) - end -end - diff --git a/xmake/platforms/watchos/global.lua b/xmake/platforms/watchos/global.lua deleted file mode 100644 index f625eb103..000000000 --- a/xmake/platforms/watchos/global.lua +++ /dev/null @@ -1,36 +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 global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_xcode") - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check xcode - check_xcode(global, true) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 5c2e2a731..1311c47ba 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -33,11 +33,8 @@ platform("watchos") -- set formats set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on load on_load("load") diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua new file mode 100644 index 000000000..55027ff6a --- /dev/null +++ b/xmake/platforms/windows/check.lua @@ -0,0 +1,139 @@ +--!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 check.lua +-- + +-- 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, ["cu-ld"] = 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 + + -- 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) + end + end +end + diff --git a/xmake/platforms/windows/config.lua b/xmake/platforms/windows/config.lua deleted file mode 100644 index c74205efe..000000000 --- a/xmake/platforms/windows/config.lua +++ /dev/null @@ -1,139 +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 config.lua --- - --- 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, ["cu-ld"] = 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 - - -- 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) - end - end -end - diff --git a/xmake/platforms/windows/global.lua b/xmake/platforms/windows/global.lua deleted file mode 100644 index 9ef580bef..000000000 --- a/xmake/platforms/windows/global.lua +++ /dev/null @@ -1,49 +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 global.lua --- - --- imports -import("core.base.global") -import("private.platform.check_arch") -import("private.platform.check_vstudio") - --- clean temporary global configs -function _clean_global() - global.set("arch", nil) - global.set("__vcvarsall", nil) -end - --- check it -function main(platform, name) - - -- we cannot check the global configuration with the given name - if name then - raise("we cannot check global." .. name) - end - - -- check arch - check_arch(global) - - -- check vstudio - check_vstudio(global, {try = true}) - - -- clean temporary global configs - _clean_global() -end - diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 43c7acccb..3bc2bf0cf 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -33,11 +33,8 @@ platform("windows") -- set formats set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} - -- on check project configuration - on_config_check("config") - - -- on check global configuration - on_global_check("global") + -- on check + on_check("check") -- on environment enter on_environment_enter("environment.enter") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index c10fe48d9..0e34232a6 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -25,4 +25,5 @@ import("private.platform.check_xcode") -- main entry function main(toolchain) check_xcode(config, true) + return true end -- cgit v1.3.1 From 8405406c0519338e1cfb75746e4b31ca5b6c3cc7 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:41:04 +0800 Subject: improve to check xcode toolchain --- xmake/platforms/macosx/check.lua | 1 + xmake/toolchains/xcode/check.lua | 26 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index ff552ad6b..2158dc25a 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -155,6 +155,7 @@ function main(platform) table.remove(toolchains, idx) end end + assert(#toolchains > 0, "toolchains not found!") --[[ -- only check the given config name? diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 0e34232a6..925db3870 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -19,11 +19,33 @@ -- -- imports +import("core.base.option") import("core.project.config") -import("private.platform.check_xcode") +import("detect.sdks.find_xcode") -- main entry function main(toolchain) - check_xcode(config, true) + + -- find xcode + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + if xcode then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + else + return false + end + + -- save target minver + local xcode_sdkver = config.get("xcode_sdkver") + local target_minver = config.get("target_minver") + if xcode_sdkver and not target_minver then + target_minver = xcode_sdkver + if is_plat("macosx") then + local macos_ver = macos.version() + if macos_ver then + target_minver = macos_ver:major() .. "." .. macos_ver:minor() + end + end + config.set("target_minver", target_minver) + end return true end -- cgit v1.3.1 From 3537041f82f3c12f6c9312b3325550d1f18eb94e Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:51:09 +0800 Subject: add platform.toolconfig --- xmake/core/package/package.lua | 2 +- xmake/core/platform/platform.lua | 40 ++++++++++++++++++++++ .../modules/import/core/platform/platform.lua | 7 +++- xmake/core/tool/builder.lua | 2 +- xmake/core/tool/compiler.lua | 6 ++-- xmake/core/tool/linker.lua | 8 ++--- .../package/manager/conan/install_package.lua | 2 +- .../modules/private/action/trybuild/autotools.lua | 2 +- xmake/toolchains/xcode/load.lua | 2 +- 9 files changed, 58 insertions(+), 13 deletions(-) diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index b69b4f094..d47f0fc4e 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -492,7 +492,7 @@ function _instance:build_envs(lazy_loading) setmetatable(build_envs, { __index = function (tbl, key) local value = config.get(key) if value == nil then - value = platform.get(key, self:plat()) + value = platform.toolconfig(key, self:plat()) end if value == nil then value = platform.tool(key, self:plat()) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 677e36906..1bb76db92 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -141,6 +141,36 @@ function _instance:tool(toolkind) end end +-- get tool configuration from the toolchains +function _instance:toolconfig(name) + + -- init tool configs + local toolconfigs = self._TOOLCONFIGS + if not toolconfigs then + toolconfigs = {} + self._TOOLCONFIGS = toolconfigs + end + + -- get configuration + local toolconfig = toolconfigs[name] + if toolconfig == nil then + + -- get them from all toolchains + for _, toolchain_inst in ipairs(self:toolchains()) do + local values = toolchain_inst:get(name) + if values then + toolconfig = toolconfig or {} + table.join2(toolconfig, values) + end + end + + -- cache it + toolconfig = toolconfig or false + toolconfigs[name] = toolconfig + end + return toolconfig or nil +end + -- get the platform script function _instance:script(name) return self._INFO:get(name) @@ -388,6 +418,16 @@ function platform.tool(toolkind, plat) return program, toolname end +-- get the given tool configuration +function platform.toolconfig(name, plat) + local instance, errors = platform.load(plat) + if instance then + return instance:toolconfig(name) + else + os.raise(errors) + end +end + -- get the all platforms function platform.plats() diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 2961cb67f..6919010e6 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -50,7 +50,7 @@ function sandbox_core_platform.archs(plat) return platform.archs(plat) end --- get the current platform configure +-- get the current platform configuration function sandbox_core_platform.get(name, plat) return platform.get(name, plat) end @@ -63,5 +63,10 @@ function sandbox_core_platform.tool(toolkind) return platform.tool(toolkind) end +-- get the current platform tool configuration +function sandbox_core_platform.toolconfig(name, plat) + return platform.toolconfig(name, plat) +end + -- return module return sandbox_core_platform diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua index 3c77247c1..042aa5001 100644 --- a/xmake/core/tool/builder.lua +++ b/xmake/core/tool/builder.lua @@ -263,7 +263,7 @@ function builder:_add_flags_from_language(flags, target, getters) end return values end - , platform = platform.get + , platform = platform.toolconfig , target = function (name) -- only for target diff --git a/xmake/core/tool/compiler.lua b/xmake/core/tool/compiler.lua index 0c0a1375a..27c81879c 100644 --- a/xmake/core/tool/compiler.lua +++ b/xmake/core/tool/compiler.lua @@ -47,8 +47,8 @@ function compiler:_add_flags_from_platform(flags, targetkind) if targetkind then local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -140,7 +140,7 @@ function compiler.load(sourcekind, target) for _, flagkind in ipairs(instance:_flagkinds()) do -- add flags for platform, e.g. gcc.cxflags or cxflags - compiler_tool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + compiler_tool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/core/tool/linker.lua b/xmake/core/tool/linker.lua index d5a410b31..b3f91a904 100644 --- a/xmake/core/tool/linker.lua +++ b/xmake/core/tool/linker.lua @@ -44,8 +44,8 @@ function linker:_add_flags_from_platform(flags, targetkind) local toolkind = self:kind() local toolname = self:name() for _, flagkind in ipairs(self:_flagkinds()) do - local toolflags = platform.get(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. toolname .. '.' .. flagkind) - table.join2(flags, toolflags or platform.get(targetkind .. '.' .. toolkind .. 'flags') or platform.get(targetkind .. '.' .. flagkind)) + local toolflags = platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. toolname .. '.' .. flagkind) + table.join2(flags, toolflags or platform.toolconfig(targetkind .. '.' .. toolkind .. 'flags') or platform.toolconfig(targetkind .. '.' .. flagkind)) end end end @@ -186,8 +186,8 @@ function linker.load(targetkind, sourcekinds, target) for _, flagkind in ipairs(instance:_flagkinds()) do -- add special lanugage flags first, e.g. go.gcldflags or gcc.ldflags or gcldflags or ldflags - linkertool:add(toolkind .. 'flags', platform.get(toolname .. '.' .. toolkind .. 'flags') or platform.get(toolkind .. 'flags')) - linkertool:add(flagkind, platform.get(toolname .. '.' .. flagkind) or platform.get(flagkind)) + linkertool:add(toolkind .. 'flags', platform.toolconfig(toolname .. '.' .. toolkind .. 'flags') or platform.toolconfig(toolkind .. 'flags')) + linkertool:add(flagkind, platform.toolconfig(toolname .. '.' .. flagkind) or platform.toolconfig(flagkind)) end -- ok diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua index a74cd8817..201c50841 100644 --- a/xmake/modules/package/manager/conan/install_package.lua +++ b/xmake/modules/package/manager/conan/install_package.lua @@ -30,7 +30,7 @@ import("net.fasturl") function _conan_get_build_env(name, plat) local value = config.get(name) if value == nil then - value = platform.get(name, plat) + value = platform.toolconfig(name, plat) end if value == nil then value = platform.tool(name, plat) diff --git a/xmake/modules/private/action/trybuild/autotools.lua b/xmake/modules/private/action/trybuild/autotools.lua index 5c08c6ae0..bf4c30709 100644 --- a/xmake/modules/private/action/trybuild/autotools.lua +++ b/xmake/modules/private/action/trybuild/autotools.lua @@ -39,7 +39,7 @@ end function _get_buildenv(key) local value = config.get(key) if value == nil then - value = platform.get(key, config.plat()) + value = platform.toolconfig(key, config.plat()) end if value == nil then value = platform.tool(key, config.plat()) diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua index 96d459414..4d4165a7e 100644 --- a/xmake/toolchains/xcode/load.lua +++ b/xmake/toolchains/xcode/load.lua @@ -33,7 +33,7 @@ function main(toolchain) local xcode_sdkver = config.get("xcode_sdkver") local xcode_sdkdir = nil if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/toolchains/MacOSX.toolchain/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" end -- init flags for c/c++ -- cgit v1.3.1 From 9aaf4d1f861acb3167ce101ddbf12a5f57b0392a Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:56:42 +0800 Subject: support iphoneos for xcode toolchain --- xmake/platforms/iphoneos/check.lua | 27 +++++---- xmake/platforms/iphoneos/load.lua | 62 --------------------- xmake/platforms/iphoneos/xmake.lua | 4 +- xmake/platforms/macosx/check.lua | 21 ++----- xmake/platforms/macosx/load.lua | 94 -------------------------------- xmake/platforms/macosx/xmake.lua | 3 - xmake/toolchains/xcode/load.lua | 94 -------------------------------- xmake/toolchains/xcode/load_iphoneos.lua | 62 +++++++++++++++++++++ xmake/toolchains/xcode/load_macosx.lua | 94 ++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 50 +++++++++++------ 10 files changed, 208 insertions(+), 303 deletions(-) delete mode 100644 xmake/platforms/iphoneos/load.lua delete mode 100644 xmake/platforms/macosx/load.lua delete mode 100644 xmake/toolchains/xcode/load.lua create mode 100644 xmake/toolchains/xcode/load_iphoneos.lua create mode 100644 xmake/toolchains/xcode/load_macosx.lua diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index 94a3a9ae9..1a7fbd4e3 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -20,9 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") + +--[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -105,24 +107,21 @@ function _toolchains() sc_sh:add({name = "swiftc", cross = cross}) return toolchains -end +end]] -- check it function main(platform, name) - -- only check the given config name? - if name then - local toolchain = singleton.get("iphoneos.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, "arm64") - -- check arch - check_arch(config, "arm64") - - -- check xcode - check_xcode(config) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/iphoneos/load.lua b/xmake/platforms/iphoneos/load.lua deleted file mode 100644 index 7d54e24be..000000000 --- a/xmake/platforms/iphoneos/load.lua +++ /dev/null @@ -1,62 +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 architecture - local arch = config.get("arch") or "arm64" - local simulator = (arch == "i386" or arch == "x86_64") - - -- init platform name - local platname = simulator and "iPhoneSimulator" or "iPhoneOS" - - -- init target minimal version - local target_minver = config.get("target_minver") - if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then - target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets - end - local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver - - -- init the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 6d2af82ae..ff5ba2204 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,8 +36,8 @@ platform("iphoneos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 2158dc25a..1166c3205 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -20,11 +20,11 @@ -- imports import("core.project.config") +import("private.platform.check_arch") --[[ import("core.base.singleton") import("private.platform.toolchain") -import("private.platform.check_arch") import("private.platform.check_xcode") import("private.platform.check_toolchain") @@ -148,6 +148,9 @@ end]] -- check it function main(platform) + -- check arch + check_arch(config) + -- check toolchains local toolchains = platform:toolchains() for idx, toolchain in irpairs(toolchains) do @@ -156,21 +159,5 @@ function main(platform) end end assert(#toolchains > 0, "toolchains not found!") - - --[[ - -- only check the given config name? - if name then - local toolchain = singleton.get("macosx.toolchains." .. (config.get("arch") or os.arch()), _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - check_arch(config) - - -- check xcode - check_xcode(config, true) - end]] end diff --git a/xmake/platforms/macosx/load.lua b/xmake/platforms/macosx/load.lua deleted file mode 100644 index 6d2547a75..000000000 --- a/xmake/platforms/macosx/load.lua +++ /dev/null @@ -1,94 +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() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch) - platform:add("ldflags", "-arch " .. arch) - if target_minver then - platform:add("cxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("mxflags", "-mmacosx-version-min=" .. target_minver) - platform:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - platform:add("cxflags", "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - platform:add("cxflags", "-I/usr/local/include") - platform:add("cxflags", "-I/usr/include") - platform:add("ldflags", "-L/usr/local/lib") - platform:add("ldflags", "-L/usr/lib") - end - platform:add("ldflags", "-stdlib=libc++") - platform:add("ldflags", "-lz") - platform:add("shflags", platform:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm - platform:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") - platform:set("fasm.asflags", "") - platform:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - platform:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - platform:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 512499c7c..9fd14a82f 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -39,9 +39,6 @@ platform("macosx") -- on check on_check("check") - -- on load - on_load("load") - -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") set_toolchains("xcode") diff --git a/xmake/toolchains/xcode/load.lua b/xmake/toolchains/xcode/load.lua deleted file mode 100644 index 4d4165a7e..000000000 --- a/xmake/toolchains/xcode/load.lua +++ /dev/null @@ -1,94 +0,0 @@ ---!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 load.lua --- - --- imports -import("core.project.config") - --- main entry -function main(toolchain) - - -- init flags for architecture - local arch = config.get("arch") or os.arch() - local target_minver = config.get("target_minver") - - -- init flags for the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = nil - if xcode_dir and xcode_sdkver then - xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" - end - - -- init flags for c/c++ - toolchain:add("cxflags", "-arch " .. arch) - toolchain:add("ldflags", "-arch " .. arch) - if target_minver then - toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) - toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) - end - if xcode_sdkdir then - toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) - toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) - else - toolchain:add("cxflags", "-I/usr/local/include") - toolchain:add("cxflags", "-I/usr/include") - toolchain:add("ldflags", "-L/usr/local/lib") - toolchain:add("ldflags", "-L/usr/lib") - end - toolchain:add("ldflags", "-stdlib=libc++") - toolchain:add("ldflags", "-lz") - toolchain:add("shflags", toolchain:get("ldflags")) - - -- init flags for objc/c++ (with ldflags and shflags) - toolchain:add("mxflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") - toolchain:add("asflags", "-arch " .. arch) - if xcode_sdkdir then - toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) - end - - -- init flags for swift - if target_minver and xcode_sdkdir then - toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] -end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua new file mode 100644 index 000000000..3aeb78672 --- /dev/null +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -0,0 +1,62 @@ +--!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 load_iphoneos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") or "arm64" + local simulator = (arch == "i386" or arch == "x86_64") + + -- init platform name + local platname = simulator and "iPhoneSimulator" or "iPhoneOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then + target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets + end + local target_minver_flags = (simulator and "-mios-simulator-version-min=" or "-miphoneos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua new file mode 100644 index 000000000..b735b8d77 --- /dev/null +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -0,0 +1,94 @@ +--!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 load_macosx.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init flags for architecture + local arch = config.get("arch") or os.arch() + local target_minver = config.get("target_minver") + + -- init flags for the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = nil + if xcode_dir and xcode_sdkver then + xcode_sdkdir = xcode_dir .. "/Contents/Developer/platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" + end + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch) + toolchain:add("ldflags", "-arch " .. arch) + if target_minver then + toolchain:add("cxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("mxflags", "-mmacosx-version-min=" .. target_minver) + toolchain:add("ldflags", "-mmacosx-version-min=" .. target_minver) + end + if xcode_sdkdir then + toolchain:add("cxflags", "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-isysroot " .. xcode_sdkdir) + else + toolchain:add("cxflags", "-I/usr/local/include") + toolchain:add("cxflags", "-I/usr/include") + toolchain:add("ldflags", "-L/usr/local/lib") + toolchain:add("ldflags", "-L/usr/lib") + end + toolchain:add("ldflags", "-stdlib=libc++") + toolchain:add("ldflags", "-lz") + toolchain:add("shflags", toolchain:get("ldflags")) + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("mxflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for asm +-- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") +-- toolchain:set("fasm.asflags", "") + toolchain:add("asflags", "-arch " .. arch) + if xcode_sdkdir then + toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) + end + + -- init flags for swift + if target_minver and xcode_sdkdir then + toolchain:add("scflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + end + + --[[ + -- init flags for golang + toolchain:set("gcldflags", "") + + -- init flags for dlang + local dc_archs = { i386 = "-m32", x86_64 = "-m64" } + toolchain:add("dcflags", dc_archs[arch] or "") + toolchain:add("dcshflags", dc_archs[arch] or "") + toolchain:add("dcldflags", dc_archs[arch] or "" ) + + -- init flags for rust + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "")]] +end diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index d9b1d9944..4f45f6d60 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,24 +21,40 @@ -- define toolchain toolchain("xcode") - -- set toolsets - set_toolsets("cc", "xcrun -sdk macosx clang") - set_toolsets("cxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("as", "xcrun -sdk macosx clang") - set_toolsets("ld", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("sh", "xcrun -sdk macosx clang++", "xcrun -sdk macosx clang") - set_toolsets("ar", "xcrun -sdk macosx ar") - set_toolsets("ex", "xcrun -sdk macosx ar") - set_toolsets("strip", "xcrun -sdk macosx strip") - set_toolsets("dsymutil", "xcrun -sdk macosx dsymutil", "dsymutil") - set_toolsets("mm", "xcrun -sdk macosx clang") - set_toolsets("mxx", "xcrun -sdk macosx clang", "xcrun -sdk macosx clang++") - set_toolsets("sc", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scld", "xcrun -sdk macosx swiftc", "swiftc") - set_toolsets("scsh", "xcrun -sdk macosx swiftc", "swiftc") - -- check toolchain on_check("check") -- load toolchain - on_load("load") + on_load(function (toolchain) + + -- get cross + local cross + if is_plat("macosx") then + cross = "xcrun -sdk macosx " + elseif is_plat("iphoneos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386" or arch == "x86_64") + cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + else + raise("unknown platform for xcode!") + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "as", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "strip", cross .. "strip") + toolchain:set("toolsets", "dsymutil", cross .. "dsymutil", "dsymutil") + toolchain:set("toolsets", "mm", cross .. "clang") + toolchain:set("toolsets", "mxx", cross .. "clang", cross .. "clang++") + toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") + toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + + -- load configurations + import("load_" .. get_config("plat"))(toolchain) + end) -- cgit v1.3.1 From 93db858087c1bdeba2585f2de409e53a8d8e8fbd Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:57:44 +0800 Subject: support watchos for xcode toolchain --- xmake/platforms/watchos/load.lua | 59 --------------------------------- xmake/platforms/watchos/xmake.lua | 4 +-- xmake/toolchains/xcode/load_macosx.lua | 16 --------- xmake/toolchains/xcode/load_watchos.lua | 59 +++++++++++++++++++++++++++++++++ xmake/toolchains/xcode/xmake.lua | 4 +++ 5 files changed, 65 insertions(+), 77 deletions(-) delete mode 100644 xmake/platforms/watchos/load.lua create mode 100644 xmake/toolchains/xcode/load_watchos.lua diff --git a/xmake/platforms/watchos/load.lua b/xmake/platforms/watchos/load.lua deleted file mode 100644 index 2e0204358..000000000 --- a/xmake/platforms/watchos/load.lua +++ /dev/null @@ -1,59 +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 architecture - local arch = config.get("arch") - local simulator = arch == "i386" - - -- init platform name - local platname = simulator and "WatchSimulator" or "WatchOS" - - -- init target minimal version - local target_minver = config.get("target_minver") - local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver - - -- init the xcode sdk directory - local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver") - local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) - - -- init flags for c/c++ - platform:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - platform:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for objc/c++ - platform:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for asm - platform:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) - - -- init flags for swift (with platform:add("ldflags and platform:add("shflags) - platform:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) - platform:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) -end - diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 1311c47ba..1356af3ab 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -36,8 +36,8 @@ platform("watchos") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("xcode") -- set menu set_menu { diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index b735b8d77..5cebd96bb 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -64,8 +64,6 @@ function main(toolchain) end -- init flags for asm --- toolchain:add("yasm.asflags", arch == "x86_64" and "macho64" or "macho32") --- toolchain:set("fasm.asflags", "") toolchain:add("asflags", "-arch " .. arch) if xcode_sdkdir then toolchain:add("asflags", "-isysroot " .. xcode_sdkdir) @@ -77,18 +75,4 @@ function main(toolchain) toolchain:add("scshflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) toolchain:add("scldflags", format("-target %s-apple-macosx%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) end - - --[[ - -- init flags for golang - toolchain:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - toolchain:add("dcflags", dc_archs[arch] or "") - toolchain:add("dcshflags", dc_archs[arch] or "") - toolchain:add("dcldflags", dc_archs[arch] or "" ) - - -- init flags for rust - toolchain:set("rcshflags", "") - toolchain:set("rcldflags", "")]] end diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua new file mode 100644 index 000000000..5048f4bb7 --- /dev/null +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -0,0 +1,59 @@ +--!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 load_watchos.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- init architecture + local arch = config.get("arch") + local simulator = arch == "i386" + + -- init platform name + local platname = simulator and "WatchSimulator" or "WatchOS" + + -- init target minimal version + local target_minver = config.get("target_minver") + local target_minver_flags = (simulator and "-mwatchos-simulator-version-min=" or "-mwatchos-version-min=") .. target_minver + + -- init the xcode sdk directory + local xcode_dir = config.get("xcode") + local xcode_sdkver = config.get("xcode_sdkver") + local xcode_sdkdir = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode_dir, platname, platname, xcode_sdkver) + + -- init flags for c/c++ + toolchain:add("cxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("ldflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + toolchain:add("shflags", "-arch " .. arch, "-ObjC", "-lstdc++", "-fobjc-link-runtime", target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for objc/c++ + toolchain:add("mxflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for asm + toolchain:add("asflags", "-arch " .. arch, target_minver_flags, "-isysroot " .. xcode_sdkdir) + + -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) + toolchain:add("scflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scshflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) + toolchain:add("scldflags", format("-target %s-apple-ios%s", arch, target_minver) , "-sdk " .. xcode_sdkdir) +end + diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 4f45f6d60..f20fabe1f 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -35,6 +35,10 @@ toolchain("xcode") local arch = get_config("arch") or os.arch() local simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " + elseif is_plat("watchos") then + local arch = get_config("arch") or os.arch() + local simulator = (arch == "i386") + cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") end -- cgit v1.3.1 From 3c304c6ae85fe66c2f2144e447d31a68b45cf349 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:58:22 +0800 Subject: improve to check iphoneos and watchos --- xmake/platforms/iphoneos/check.lua | 89 +-------------------------- xmake/platforms/macosx/check.lua | 123 ------------------------------------- xmake/platforms/watchos/check.lua | 105 +++---------------------------- 3 files changed, 11 insertions(+), 306 deletions(-) diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index 1a7fbd4e3..ad0110b39 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -22,95 +22,8 @@ import("core.project.config") import("private.platform.check_arch") ---[[ -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") - - -- init cross - local cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cpp = toolchain("the c preprocessor") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cpp = cpp, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add({name = "clang -arch " .. arch .. " -E", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end]] - -- check it -function main(platform, name) +function main(platform) -- check arch check_arch(config, "arm64") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 1166c3205..df2f072ec 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,129 +22,6 @@ import("core.project.config") import("private.platform.check_arch") ---[[ -import("core.base.singleton") -import("private.platform.toolchain") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init cross - local cross = "xcrun -sdk macosx " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh, - 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add("clang", "clang++", "gcc", "g++") - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add("clang++", "g++", "clang", "gcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add("clang++", "g++", "clang", "gcc") - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}, "ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross}, "ar") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}, "strip") - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}, "dsymutil") - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, "clang", "gcc") - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add("clang", "clang++", "gcc", "g++") - - -- init the swift compiler and linker - sc:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_ld:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - sc_sh:add("$(env SC)", {name = "swiftc", cross = cross}, "swiftc") - - -- 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") - cu_ccbin:add("$(env CXX)", "$(env CC)", "clang", "gcc") - - return toolchains -end]] - -- check it function main(platform) diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua index 89086d74c..e4e36f092 100644 --- a/xmake/platforms/watchos/check.lua +++ b/xmake/platforms/watchos/check.lua @@ -20,105 +20,20 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_xcode") -import("private.platform.check_toolchain") - --- get toolchains -function _toolchains() - - -- init architecture - local arch = config.get("arch") - local simulator = (arch == "i386") - - -- init cross - local cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local dsymutil = toolchain("the symbols generator") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - local as = toolchain("the assember") - local sc = toolchain("the swift compiler") - local sc_ld = toolchain("the swift linker") - local sc_sh = toolchain("the swift shared library linker") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, dsymutil = dsymutil, - mm = mm, mxx = mxx, sc = sc, ["scld"] = sc_ld, ["scsh"] = sc_sh} - - -- init the c compiler - cc:add({name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - if simulator then - as:add({name = "clang", cross = cross}) - else - as:add({name = "clang", cross = path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross)}) - end - - -- init the linker - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add({name = "ar", cross = cross}) - - -- init the static library extractor - ex:add({name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add({name = "strip", cross = cross}) - - -- init the symbols generator - dsymutil:add({name = "dsymutil", cross = cross}) - - -- init the objc compiler - mm:add({name = "clang", cross = cross}) - - -- init the objc++ compiler - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - - -- init the swift compiler and linker - sc:add({name = "swiftc", cross = cross}) - sc_ld:add({name = "swiftc", cross = cross}) - sc_sh:add({name = "swiftc", cross = cross}) - - return toolchains -end -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("watchos.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else +function main(platform) - -- check arch - check_arch(config, "armv7k") + -- check arch + check_arch(config, "armv7k") - -- check xcode - check_xcode(config) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end - -- cgit v1.3.1 From 7d9b0c0be46aa7ed53578e4f39717cfac76aa1eb Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:58:30 +0800 Subject: remove check_xcode module --- xmake/modules/private/platform/check_xcode.lua | 58 -------------------------- 1 file changed, 58 deletions(-) delete mode 100644 xmake/modules/private/platform/check_xcode.lua diff --git a/xmake/modules/private/platform/check_xcode.lua b/xmake/modules/private/platform/check_xcode.lua deleted file mode 100644 index e0188beb4..000000000 --- a/xmake/modules/private/platform/check_xcode.lua +++ /dev/null @@ -1,58 +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 check_xcode.lua --- - --- imports -import("core.base.option") -import("detect.sdks.find_xcode") - --- check the xcode application directory -function main(config, optional) - - -- find xcode - local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) - if xcode then - - -- save it (maybe to global) - config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - - elseif not optional then - - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --xcode=xxx") - cprint("or - xmake global --xcode=xxx") - raise() - end - - -- save target minver - local xcode_sdkver = config.get("xcode_sdkver") - local target_minver = config.get("target_minver") - if xcode_sdkver and not target_minver then - target_minver = xcode_sdkver - if is_plat("macosx") then - local macos_ver = macos.version() - if macos_ver then - target_minver = macos_ver:major() .. "." .. macos_ver:minor() - end - end - config.set("target_minver", target_minver) - end -end - -- cgit v1.3.1 From fb7bc83c06972744d6f2c5139b5bc079e06b7b11 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 22:59:45 +0800 Subject: add as to xcode toolchain --- xmake/toolchains/xcode/xmake.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index f20fabe1f..aed4a44e9 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -28,16 +28,16 @@ toolchain("xcode") on_load(function (toolchain) -- get cross - local cross + local cross, arch, simulator if is_plat("macosx") then cross = "xcrun -sdk macosx " elseif is_plat("iphoneos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386" or arch == "x86_64") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " elseif is_plat("watchos") then - local arch = get_config("arch") or os.arch() - local simulator = (arch == "i386") + arch = get_config("arch") or os.arch() + simulator = (arch == "i386") cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else raise("unknown platform for xcode!") @@ -46,7 +46,6 @@ toolchain("xcode") -- set toolsets toolchain:set("toolsets", "cc", cross .. "clang") toolchain:set("toolsets", "cxx", cross .. "clang", cross .. "clang++") - toolchain:set("toolsets", "as", cross .. "clang") toolchain:set("toolsets", "ld", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "sh", cross .. "clang++", cross .. "clang") toolchain:set("toolsets", "ar", cross .. "ar") @@ -58,6 +57,16 @@ toolchain("xcode") toolchain:set("toolsets", "sc", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scld", cross .. "swiftc", "swiftc") toolchain:set("toolsets", "scsh", cross .. "swiftc", "swiftc") + if arch then + toolchain:set("toolsets", "cpp", cross .. "clang -arch " .. arch .. " -E") + end + if is_plat("macosx") then + toolchain:set("toolsets", "as", cross .. "clang") + elseif simulator then + toolchain:set("toolsets", "as", cross .. "clang") + else + toolchain:set("toolsets", "as", path.join(os.programdir(), "scripts", "gas-preprocessor.pl " .. cross) .. "clang") + end -- load configurations import("load_" .. get_config("plat"))(toolchain) -- cgit v1.3.1 From 694bff5b15ada2850b21ce0588d6963654ab0dc2 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 18 May 2020 23:54:35 +0800 Subject: add clang/gcc toolchains --- xmake/core/tool/toolchain.lua | 2 +- xmake/platforms/macosx/check.lua | 21 +++++++++++++++++++-- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/clang/xmake.lua | 39 +++++++++++++++++++++++++++++++++++++++ xmake/toolchains/gcc/xmake.lua | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 xmake/toolchains/clang/xmake.lua create mode 100644 xmake/toolchains/gcc/xmake.lua diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index e79a32b22..8f524b623 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -296,7 +296,7 @@ function toolchain.load(name, plat) end -- get cache key - local cachekey = plat .. "_" .. (config.get("arch") or os.arch()) + local cachekey = name .. "_" .. plat .. "_" .. (config.get("arch") or os.arch()) -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index df2f072ec..08e04d7d6 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,6 +22,12 @@ import("core.project.config") import("private.platform.check_arch") +-- is basic toolchain? +function _is_basic_toolchain(toolchain) + local name = toolchain:name() + return name == "xcode" or name == "clang" or name == "gcc" +end + -- check it function main(platform) @@ -30,9 +36,20 @@ function main(platform) -- check toolchains local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then + local idx = 1 + local num = #toolchains + local has_basic = false + while idx <= num do + local toolchain = toolchains[idx] + -- we need remove other same basic toolchains if basic toolchain found + if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then table.remove(toolchains, idx) + num = num - 1 + else + if _is_basic_toolchain(toolchain) then + has_basic = true + end + idx = idx + 1 end end assert(#toolchains > 0, "toolchains not found!") diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 9fd14a82f..4cd22a2fd 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -41,7 +41,7 @@ platform("macosx") -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("xcode") + set_toolchains("xcode", "clang", "gcc") -- set menu set_menu { diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua new file mode 100644 index 000000000..d4c1c3798 --- /dev/null +++ b/xmake/toolchains/clang/xmake.lua @@ -0,0 +1,39 @@ +--!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("clang") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "ar") + set_toolsets("ex", "ex") + set_toolsets("strip", "strip") + set_toolsets("mm", "clang") + set_toolsets("mxx", "clang", "clang++") + set_toolsets("as", "clang") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("clang") + end) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua new file mode 100644 index 000000000..08bb2d062 --- /dev/null +++ b/xmake/toolchains/gcc/xmake.lua @@ -0,0 +1,39 @@ +--!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("gcc") + + -- set toolsets + set_toolsets("cc", "gcc") + set_toolsets("cxx", "gcc", "g++") + set_toolsets("ld", "g++", "gcc") + set_toolsets("sh", "g++", "gcc") + set_toolsets("ar", "ar") + set_toolsets("ex", "ex") + set_toolsets("strip", "strip") + set_toolsets("mm", "gcc") + set_toolsets("mxx", "gcc", "g++") + set_toolsets("as", "gcc") + + -- check toolchain + on_check(function (toolchain) + return import("lib.detect.find_tool")("gcc") + end) -- cgit v1.3.1 From 5dfb51f3e1c06c07097158153f39c45830029685 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 22:35:36 +0800 Subject: add envs toolchain --- xmake/core/platform/platform.lua | 34 ++++++++++++++++++++++++++-------- xmake/core/tool/toolchain.lua | 9 +++++++++ xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/envs/xmake.lua | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 xmake/toolchains/envs/xmake.lua diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1bb76db92..3e3b537d1 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -129,16 +129,34 @@ end -- get the program and name of the given tool kind function _instance:tool(toolkind) - local toolchains = self:toolchains() - for idx, toolchain_inst in ipairs(toolchains) do - local program, toolname = toolchain_inst:tool(toolkind) - if program then - -- move this toolchain to head - table.remove(toolchains, idx) - table.insert(toolchains, 1, toolchain_inst) - return program, toolname + + -- init tools + local tools = self._TOOLS + if not tools then + tools = {} + self._TOOLS = tools + end + + -- get tool program + local program, toolname + local toolinfo = tools[toolkind] + if toolinfo == nil then + toolinfo = {} + local toolchains = self:toolchains() + for idx, toolchain_inst in ipairs(toolchains) do + program, toolname = toolchain_inst:tool(toolkind) + if program then + toolinfo[1] = program + toolinfo[2] = toolname + break + end end + tools[toolkind] = toolinfo + else + program = toolinfo[1] + toolname = toolinfo[2] end + return program, toolname end -- get tool configuration from the toolchains diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8f524b623..d915ffcf8 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -182,6 +182,15 @@ function _instance:_checktool(toolkind, toolpath) self._find_tool = find_tool end + -- do filter for toolpath variables, e.g. set_toolsets("cc", "$(env CC)") + local sandbox_inst = sandbox.instance() + if sandbox_inst then + local filter = sandbox_inst:filter() + if filter then + toolpath = filter:handle(toolpath) + end + end + -- find tool program local program, toolname local tool = find_tool(toolpath, {program = toolpath, pathes = self:bindir()}) diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 4cd22a2fd..85e646851 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -41,7 +41,7 @@ platform("macosx") -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("xcode", "clang", "gcc") + set_toolchains("envs", "xcode", "clang", "gcc") -- set menu set_menu { diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua new file mode 100644 index 000000000..401f6d72b --- /dev/null +++ b/xmake/toolchains/envs/xmake.lua @@ -0,0 +1,40 @@ +--!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("envs") + + -- set toolsets + set_toolsets("cc", "$(env CC)") + set_toolsets("cxx", "$(env CXX)") + set_toolsets("ld", "$(env LD)") + set_toolsets("sh", "$(env SH)") + set_toolsets("ar", "$(env AR)") + set_toolsets("ex", "$(env EX)", "$(env AR)") + set_toolsets("strip", "$(env STRIP)") + set_toolsets("ranlib","$(env RANLIB)") + set_toolsets("mm", "$(env MM)") + set_toolsets("mxx", "$(env MXX)") + set_toolsets("as", "$(env AS)") + set_toolsets("dc", "$(env DC") + set_toolsets("sc", "$(env SC)") + set_toolsets("gc", "$(env GC)") + set_toolsets("rc", "$(env RC)") + -- cgit v1.3.1 From 6ee9db874fcfeb94fcc06982f132ea469ec98e0e Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 22:39:51 +0800 Subject: add dlang toolchain --- xmake/core/tool/toolchain.lua | 9 +++++++-- xmake/modules/core/tools/dmd.lua | 23 +++++++++++++++++++---- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/dlang/xmake.lua | 36 ++++++++++++++++++++++++++++++++++++ xmake/toolchains/envs/xmake.lua | 2 +- 5 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 xmake/toolchains/dlang/xmake.lua diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index d915ffcf8..032445b3d 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -187,7 +187,12 @@ function _instance:_checktool(toolkind, toolpath) if sandbox_inst then local filter = sandbox_inst:filter() if filter then - toolpath = filter:handle(toolpath) + local value = filter:handle(toolpath) + if value and value:trim() ~= "" then + toolpath = value + else + return + end end end @@ -207,7 +212,7 @@ function _instance:_checktool(toolkind, toolpath) if program then utils.cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) else - utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) + utils.cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, toolpath) end end return program, toolname diff --git a/xmake/modules/core/tools/dmd.lua b/xmake/modules/core/tools/dmd.lua index 4d74c21ae..378c68642 100644 --- a/xmake/modules/core/tools/dmd.lua +++ b/xmake/modules/core/tools/dmd.lua @@ -134,15 +134,30 @@ end -- make the rpathdir flag function nf_rpathdir(self, dir) - local flag = "-L-rpath=" .. os.args(dir) - if self:has_flags(flag) then - return flag + dir = path.translate(dir) + if self:has_flags("-L-rpath=" .. dir, "ldflags") then + return "-L-rpath=" .. os.args(dir:gsub("@[%w_]+", function (name) + local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} + return maps[name] + end)) + + elseif self:has_flags("-L-rpath -L" .. dir, "ldflags") then + return "-L-rpath -L" .. os.args(dir:gsub("%$ORIGIN", "@loader_path")) end end -- make the link arguments list function linkargv(self, objectfiles, targetkind, targetfile, flags) - return self:program(), table.join(flags, "-of" .. targetfile, objectfiles) + + -- add rpath for dylib (macho), e.g. -install_name @rpath/file.dylib + local flags_extra = {} + if targetkind == "shared" and is_plat("macosx") then + table.insert(flags_extra, "-L-install_name") + table.insert(flags_extra, "-L@rpath/" .. path.filename(targetfile)) + end + + -- init arguments + return self:program(), table.join(flags, flags_extra, "-of" .. targetfile, objectfiles) end -- link the target file diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 85e646851..aef9fb37e 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -41,7 +41,7 @@ platform("macosx") -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("envs", "xcode", "clang", "gcc") + set_toolchains("envs", "xcode", "clang", "gcc", "dlang") -- set menu set_menu { diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua new file mode 100644 index 000000000..1ce144f8e --- /dev/null +++ b/xmake/toolchains/dlang/xmake.lua @@ -0,0 +1,36 @@ +--!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("dlang") + + -- set toolsets + set_toolsets("dc", "dmd", "ldc2", "gdc") + set_toolsets("dcld", "dmd", "ldc2", "gdc") + set_toolsets("dcsh", "dmd", "ldc2", "gdc") + set_toolsets("dcar", "dmd", "ldc2", "gdc") + + -- on load + on_load(function (toolchain) + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + toolchain:add("dcflags", march) + toolchain:add("dcshflags", march) + toolchain:add("dcldflags", march) + end) diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua index 401f6d72b..1fc043025 100644 --- a/xmake/toolchains/envs/xmake.lua +++ b/xmake/toolchains/envs/xmake.lua @@ -33,7 +33,7 @@ toolchain("envs") set_toolsets("mm", "$(env MM)") set_toolsets("mxx", "$(env MXX)") set_toolsets("as", "$(env AS)") - set_toolsets("dc", "$(env DC") + set_toolsets("dc", "$(env DC)") set_toolsets("sc", "$(env SC)") set_toolsets("gc", "$(env GC)") set_toolsets("rc", "$(env RC)") -- cgit v1.3.1 From 40f43fdf131b55639a8149a021394106eb8aef34 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 22:41:11 +0800 Subject: add go and rust toolchains --- xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/dlang/xmake.lua | 2 +- xmake/toolchains/go/xmake.lua | 28 ++++++++++++++++++++++++++++ xmake/toolchains/rust/xmake.lua | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 xmake/toolchains/go/xmake.lua create mode 100644 xmake/toolchains/rust/xmake.lua diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index aef9fb37e..887577575 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -41,7 +41,7 @@ platform("macosx") -- set toolchains -- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("envs", "xcode", "clang", "gcc", "dlang") + set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua index 1ce144f8e..984dae6df 100644 --- a/xmake/toolchains/dlang/xmake.lua +++ b/xmake/toolchains/dlang/xmake.lua @@ -22,7 +22,7 @@ toolchain("dlang") -- set toolsets - set_toolsets("dc", "dmd", "ldc2", "gdc") + set_toolsets("dc", "dmd", "ldc2", "gdc") set_toolsets("dcld", "dmd", "ldc2", "gdc") set_toolsets("dcsh", "dmd", "ldc2", "gdc") set_toolsets("dcar", "dmd", "ldc2", "gdc") diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua new file mode 100644 index 000000000..f7451a781 --- /dev/null +++ b/xmake/toolchains/go/xmake.lua @@ -0,0 +1,28 @@ +--!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("go") + + -- set toolsets + set_toolsets("gc", "go", "gccgo") + set_toolsets("gcld", "go", "gccgo") + set_toolsets("gcar", "go", "gccgo") + diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua new file mode 100644 index 000000000..dca2325bb --- /dev/null +++ b/xmake/toolchains/rust/xmake.lua @@ -0,0 +1,33 @@ +--!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("rust") + + -- set toolsets + set_toolsets("rc", "rustc") + set_toolsets("rcld", "rustc") + set_toolsets("rcsh", "rustc") + set_toolsets("rcar", "rustc") + + -- on load + on_load(function (toolchain) + -- TODO for android ndk + end) -- cgit v1.3.1 From 5ae55ab1f4233bd5a5f065a07763c1192b91341c Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 22:43:07 +0800 Subject: add cuda toolchain --- xmake/languages/cuda/xmake.lua | 4 ++-- xmake/platforms/bsd/check.lua | 2 +- xmake/platforms/cygwin/check.lua | 2 +- xmake/platforms/linux/check.lua | 2 +- xmake/platforms/macosx/xmake.lua | 3 +-- xmake/platforms/msys/check.lua | 2 +- xmake/platforms/windows/check.lua | 2 +- xmake/toolchains/cuda/xmake.lua | 28 ++++++++++++++++++++++++++++ xmake/toolchains/dlang/xmake.lua | 8 ++++---- xmake/toolchains/envs/xmake.lua | 3 --- xmake/toolchains/go/xmake.lua | 6 +++--- xmake/toolchains/rust/xmake.lua | 8 ++++---- 12 files changed, 47 insertions(+), 23 deletions(-) create mode 100644 xmake/toolchains/cuda/xmake.lua diff --git a/xmake/languages/cuda/xmake.lua b/xmake/languages/cuda/xmake.lua index 60f36f098..535d652f2 100644 --- a/xmake/languages/cuda/xmake.lua +++ b/xmake/languages/cuda/xmake.lua @@ -28,7 +28,7 @@ language("cuda") set_sourceflags {cu = "cuflags"} -- set target kinds - set_targetkinds {gpucode = "cu-ld", binary = "ld", static = "ar", shared = "sh"} + set_targetkinds {gpucode = "culd", binary = "ld", static = "ar", shared = "sh"} -- set target flags set_targetflags {gpucode = "culdflags", binary = "ldflags", static = "arflags", shared = "shflags"} @@ -140,7 +140,7 @@ language("cuda") {category = "Cross Complation Configuration/Compiler Configuration" } , {nil, "cu", "kv", nil, "The Cuda Compiler" } , {nil, "cu-ccbin", "kv", nil, "The Cuda Host C++ Compiler" } - , {nil, "cu-ld", "kv", nil, "The Cuda Linker" } + , {nil, "culd", "kv", nil, "The Cuda Linker" } , {category = "Cross Complation Configuration/Compiler Flags Configuration" } , {nil, "cuflags", "kv", nil, "The Cuda Compiler Flags" } diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 1eb8834ef..2422f3eb7 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -83,7 +83,7 @@ function _toolchains() 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + cu = cu, ["culd"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua index 3b1221387..22d8809ad 100644 --- a/xmake/platforms/cygwin/check.lua +++ b/xmake/platforms/cygwin/check.lua @@ -82,7 +82,7 @@ function _toolchains() 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + cu = cu, ["culd"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index 1671ee0e9..0fee59e6d 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -83,7 +83,7 @@ function _toolchains() 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + cu = cu, ["culd"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 887577575..8939fbc86 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -40,8 +40,7 @@ platform("macosx") on_check("check") -- set toolchains --- set_toolchains("custom", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") - set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go") + set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") -- set menu set_menu { diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua index 8c5a2dcdd..927e51e5d 100644 --- a/xmake/platforms/msys/check.lua +++ b/xmake/platforms/msys/check.lua @@ -82,7 +82,7 @@ function _toolchains() 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, ["cu-ld"] = cu_ld, ["cu-ccbin"] = cu_ccbin} + cu = cu, ["culd"] = cu_ld, ["cu-ccbin"] = cu_ccbin} -- init the c compiler cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua index 55027ff6a..4503a35db 100644 --- a/xmake/platforms/windows/check.lua +++ b/xmake/platforms/windows/check.lua @@ -56,7 +56,7 @@ function _toolchains() 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, ["cu-ld"] = cu_ld} + cu = cu, ["culd"] = cu_ld} -- init the c compiler cc:add("cl.exe") diff --git a/xmake/toolchains/cuda/xmake.lua b/xmake/toolchains/cuda/xmake.lua new file mode 100644 index 000000000..884851581 --- /dev/null +++ b/xmake/toolchains/cuda/xmake.lua @@ -0,0 +1,28 @@ +--!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("cuda") + + -- set toolsets + set_toolsets("cu", "nvcc", "clang") + set_toolsets("culd", "nvcc") + set_toolsets("cu-ccbin", "$(env CXX)", "$(env CC)", "clang", "gcc") + diff --git a/xmake/toolchains/dlang/xmake.lua b/xmake/toolchains/dlang/xmake.lua index 984dae6df..783530b90 100644 --- a/xmake/toolchains/dlang/xmake.lua +++ b/xmake/toolchains/dlang/xmake.lua @@ -22,10 +22,10 @@ toolchain("dlang") -- set toolsets - set_toolsets("dc", "dmd", "ldc2", "gdc") - set_toolsets("dcld", "dmd", "ldc2", "gdc") - set_toolsets("dcsh", "dmd", "ldc2", "gdc") - set_toolsets("dcar", "dmd", "ldc2", "gdc") + set_toolsets("dc", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcld", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcsh", "$(env DC)", "dmd", "ldc2", "gdc") + set_toolsets("dcar", "$(env DC)", "dmd", "ldc2", "gdc") -- on load on_load(function (toolchain) diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua index 1fc043025..899802b8e 100644 --- a/xmake/toolchains/envs/xmake.lua +++ b/xmake/toolchains/envs/xmake.lua @@ -33,8 +33,5 @@ toolchain("envs") set_toolsets("mm", "$(env MM)") set_toolsets("mxx", "$(env MXX)") set_toolsets("as", "$(env AS)") - set_toolsets("dc", "$(env DC)") set_toolsets("sc", "$(env SC)") - set_toolsets("gc", "$(env GC)") - set_toolsets("rc", "$(env RC)") diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua index f7451a781..a5400302b 100644 --- a/xmake/toolchains/go/xmake.lua +++ b/xmake/toolchains/go/xmake.lua @@ -22,7 +22,7 @@ toolchain("go") -- set toolsets - set_toolsets("gc", "go", "gccgo") - set_toolsets("gcld", "go", "gccgo") - set_toolsets("gcar", "go", "gccgo") + set_toolsets("gc", "$(env GC)", "go", "gccgo") + set_toolsets("gcld", "$(env GC)", "go", "gccgo") + set_toolsets("gcar", "$(env GC)", "go", "gccgo") diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua index dca2325bb..6c6e70bfb 100644 --- a/xmake/toolchains/rust/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -22,10 +22,10 @@ toolchain("rust") -- set toolsets - set_toolsets("rc", "rustc") - set_toolsets("rcld", "rustc") - set_toolsets("rcsh", "rustc") - set_toolsets("rcar", "rustc") + set_toolsets("rc", "$(env RC)", "rustc") + set_toolsets("rcld", "$(env RC)", "rustc") + set_toolsets("rcsh", "$(env RC)", "rustc") + set_toolsets("rcar", "$(env RC)", "rustc") -- on load on_load(function (toolchain) -- cgit v1.3.1 From 2b50cfa31f9d4c979b868fcadbf1112597dad8c1 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 22:49:53 +0800 Subject: add yasm toolchain --- tests/projects/yasm/src/main.S | 18 ++++++++++++++++++ tests/projects/yasm/xmake.lua | 3 +++ xmake/toolchains/yasm/xmake.lua | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 tests/projects/yasm/src/main.S create mode 100644 tests/projects/yasm/xmake.lua create mode 100644 xmake/toolchains/yasm/xmake.lua diff --git a/tests/projects/yasm/src/main.S b/tests/projects/yasm/src/main.S new file mode 100644 index 000000000..822d9bf4c --- /dev/null +++ b/tests/projects/yasm/src/main.S @@ -0,0 +1,18 @@ +;asm00.s + +section .data + msg db 'Hello world!' + nl db 0x0a + msgLen equ $-msg +section .text +global _start +_start: + mov rax, 1 + mov rdi, 1 + mov rsi, qword msg + mov rdx, qword msgLen + syscall + + mov rax, 60 + mov rdi, 0 + syscall diff --git a/tests/projects/yasm/xmake.lua b/tests/projects/yasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/yasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/xmake/toolchains/yasm/xmake.lua b/xmake/toolchains/yasm/xmake.lua new file mode 100644 index 000000000..4f0d43a37 --- /dev/null +++ b/xmake/toolchains/yasm/xmake.lua @@ -0,0 +1,36 @@ +--!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("yasm") + + -- set toolsets + set_toolsets("as", "yasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux") then + toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows") then + toolchain:add("yasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) -- cgit v1.3.1 From 737e0081819f9337a60b5019b2445a12091e9e41 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:01:22 +0800 Subject: add ld tool --- xmake/modules/core/tools/ld.lua | 99 ++++++++++++++++++++++++++++++++++ xmake/modules/detect/tools/find_ld.lua | 46 ++++++++++++++++ 2 files changed, 145 insertions(+) create mode 100644 xmake/modules/core/tools/ld.lua create mode 100644 xmake/modules/detect/tools/find_ld.lua diff --git a/xmake/modules/core/tools/ld.lua b/xmake/modules/core/tools/ld.lua new file mode 100644 index 000000000..6894d21b8 --- /dev/null +++ b/xmake/modules/core/tools/ld.lua @@ -0,0 +1,99 @@ +--!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 ld.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("core.project.project") +import("core.language.language") + +-- init it +function init(self) + + -- init shflags + self:set("shflags", "-shared") + + -- add -fPIC for shared + if not is_plat("windows", "mingw") then + self:add("shflags", "-fPIC") + self:add("shared.cxflags", "-fPIC") + end +end + +-- make the strip flag +function nf_strip(self, level) + local maps = + { + debug = "-S" + , all = "-s" + } + + local plat = config.plat() + if plat == "macosx" or plat == "iphoneos" then + maps.all = "-Wl,-x" + maps.debug = "-Wl,-S" + end + return maps[level] +end + +-- make the link flag +function nf_link(self, lib) + return "-l" .. lib +end + +-- make the syslink flag +function nf_syslink(self, lib) + return nf_link(self, lib) +end + +-- make the linkdir flag +function nf_linkdir(self, dir) + return "-L" .. os.args(path.translate(dir)) +end + +-- make the link arguments list +function linkargv(self, objectfiles, targetkind, targetfile, flags, opt) + + -- init arguments + local argv = table.join("-o", targetfile, objectfiles, flags) + + -- too long arguments for windows? + if is_host("windows") then + opt = opt or {} + local args = os.args(argv, {escape = true}) + if #args > 1024 and not opt.rawargs then + local argsfile = os.tmpfile(args) .. ".args.txt" + io.writefile(argsfile, args) + argv = {"@" .. argsfile} + end + end + return self:program(), argv +end + +-- link the target file +function link(self, objectfiles, targetkind, targetfile, flags) + + -- ensure the target directory + os.mkdir(path.directory(targetfile)) + + -- link it + os.runv(linkargv(self, objectfiles, targetkind, targetfile, flags)) +end + diff --git a/xmake/modules/detect/tools/find_ld.lua b/xmake/modules/detect/tools/find_ld.lua new file mode 100644 index 000000000..7b015e043 --- /dev/null +++ b/xmake/modules/detect/tools/find_ld.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 find_ld.lua +-- + +-- imports +import("core.tool.compiler") +import("lib.detect.find_program") + +-- find ar +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local ar = find_ld() +-- local ar, version = find_ld({program = "ld", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + opt.norun = true + + -- find program + return find_program(opt.program or "ld", opt) +end -- cgit v1.3.1 From 678fcb59c1dbf71e4cfc8bce8f7e9b65349c6a5f Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:04:36 +0800 Subject: improve yasm test --- tests/projects/yasm/src/main.S | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/projects/yasm/src/main.S b/tests/projects/yasm/src/main.S index 822d9bf4c..800722a44 100644 --- a/tests/projects/yasm/src/main.S +++ b/tests/projects/yasm/src/main.S @@ -1,18 +1,20 @@ -;asm00.s +bits 64 + +extern _puts section .data - msg db 'Hello world!' - nl db 0x0a - msgLen equ $-msg + +message: + db 'hello xmake!', 0 + section .text -global _start -_start: - mov rax, 1 - mov rdi, 1 - mov rsi, qword msg - mov rdx, qword msgLen - syscall - mov rax, 60 - mov rdi, 0 - syscall +global _main +_main: + push rbp + mov rbp, rsp + lea rdi, [rel message] + call _puts + xor rax, rax + pop rbp + ret -- cgit v1.3.1 From 1c9411e8147751592dae6e67834772151a90b383 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:09:15 +0800 Subject: add nasm toolchain --- tests/projects/nasm/src/main.S | 21 +++++ tests/projects/nasm/xmake.lua | 3 + xmake/modules/core/tools/nasm.lua | 139 +++++++++++++++++++++++++++++++ xmake/modules/detect/tools/find_nasm.lua | 54 ++++++++++++ xmake/platforms/macosx/xmake.lua | 2 +- xmake/toolchains/nasm/xmake.lua | 36 ++++++++ xmake/toolchains/yasm/xmake.lua | 4 +- 7 files changed, 256 insertions(+), 3 deletions(-) create mode 100644 tests/projects/nasm/src/main.S create mode 100644 tests/projects/nasm/xmake.lua create mode 100644 xmake/modules/core/tools/nasm.lua create mode 100644 xmake/modules/detect/tools/find_nasm.lua create mode 100644 xmake/toolchains/nasm/xmake.lua diff --git a/tests/projects/nasm/src/main.S b/tests/projects/nasm/src/main.S new file mode 100644 index 000000000..5b3a93699 --- /dev/null +++ b/tests/projects/nasm/src/main.S @@ -0,0 +1,21 @@ +global _main + + +section .text + +_main: + mov rax, 0x2000004 ; write + mov rdi, 1 ; stdout + mov rsi, msg + mov rdx, msg.len + syscall + + mov rax, 0x2000001 ; exit + mov rdi, 0 + syscall + + +section .data + +msg: db "hello xmake!", 10 +.len: equ $ - msg diff --git a/tests/projects/nasm/xmake.lua b/tests/projects/nasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/nasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/xmake/modules/core/tools/nasm.lua b/xmake/modules/core/tools/nasm.lua new file mode 100644 index 000000000..a02091f07 --- /dev/null +++ b/xmake/modules/core/tools/nasm.lua @@ -0,0 +1,139 @@ +--!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 nasm.lua +-- + +-- imports +import("core.base.option") + +-- init it +function init(self) + + -- init flags map + self:set("mapflags", + { + -- symbols + ["-g"] = "" + , ["-fvisibility=.*"] = "" + + -- warnings + , ["-Wall"] = "" -- = "-Wall" will enable too more warnings + , ["-W1"] = "" + , ["-W2"] = "" + , ["-W3"] = "" + , ["-Werror"] = "" + , ["%-Wno%-error=.*"] = "" + + -- others + , ["-ftrapv"] = "" + , ["-fsanitize=address"] = "" + }) +end + +-- make the warning flag +function nf_warning(self, level) + + -- the maps + local maps = + { + none = "-w" + } + + -- make it + return maps[level] +end + +-- make the define flag +function nf_define(self, macro) + return "-D" .. macro +end + +-- make the undefine flag +function nf_undefine(self, macro) + return "-U" .. macro +end + +-- make the includedir flag +function nf_includedir(self, dir) + return "-I" .. os.args(dir) +end + +-- make the compile arguments list +function _compargv1(self, sourcefile, objectfile, flags) + return self:program(), table.join(flags, "-o", objectfile, sourcefile) +end + +-- compile the source file +function _compile1(self, sourcefile, objectfile, dependinfo, flags) + + -- ensure the object directory + os.mkdir(path.directory(objectfile)) + + -- compile it + local outdata, errdata = try + { + function () + return os.iorunv(_compargv1(self, sourcefile, objectfile, flags)) + end, + catch + { + function (errors) + + -- try removing the old object file for forcing to rebuild this source file + os.tryrm(objectfile) + + -- raise compiling errors + raise(tostring(errors)) + end + }, + finally + { + function (ok, outdata, errdata) + + -- show warnings? + if ok and errdata and (option.get("diagnosis") or option.get("warning")) then + errdata = errdata:trim() + if #errdata > 0 then + cprint("${color.warning}%s", errdata) + end + end + end + } + } +end + +-- make the compile arguments list +function compargv(self, sourcefiles, objectfile, flags) + + -- only support single source file now + assert(type(sourcefiles) ~= "table", "'object:sources' not support!") + + -- for only single source file + return _compargv1(self, sourcefiles, objectfile, flags) +end + +-- compile the source file +function compile(self, sourcefiles, objectfile, dependinfo, flags) + + -- only support single source file now + assert(type(sourcefiles) ~= "table", "'object:sources' not support!") + + -- for only single source file + _compile1(self, sourcefiles, objectfile, dependinfo, flags) +end + diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua new file mode 100644 index 000000000..40b710d2e --- /dev/null +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -0,0 +1,54 @@ +--!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 find_nasm.lua +-- + +-- imports +import("lib.detect.find_program") +import("lib.detect.find_programver") + +-- find nasm +-- +-- @param opt the argument options, e.g. {version = true} +-- +-- @return program, version +-- +-- @code +-- +-- local nasm = find_nasm() +-- local nasm, version = find_nasm({program = "nasm", version = true}) +-- +-- @endcode +-- +function main(opt) + + -- init options + opt = opt or {} + + -- find program + local program = find_program(opt.program or "nasm", opt) + + -- find program version + local version = nil + if program and opt and opt.version then + version = find_programver(program, opt) + end + + -- ok? + return program, version +end diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 8939fbc86..4537e419d 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -40,7 +40,7 @@ platform("macosx") on_check("check") -- set toolchains - set_toolchains("envs", "xcode", "clang", "gcc", "dlang", "rust", "go", "cuda") + set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/toolchains/nasm/xmake.lua b/xmake/toolchains/nasm/xmake.lua new file mode 100644 index 000000000..fe9beb8b6 --- /dev/null +++ b/xmake/toolchains/nasm/xmake.lua @@ -0,0 +1,36 @@ +--!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("nasm") + + -- set toolsets + set_toolsets("as", "nasm") + + -- on load + on_load(function (toolchain) + if is_plat("macosx") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") + elseif is_plat("linux", "bsd") then + toolchain:add("nasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") + elseif is_plat("windows", "mingw", "msys", "cygwin") then + toolchain:add("nasm.asflags", "-f", is_arch("x64") and "win64" or "win32") + end + end) diff --git a/xmake/toolchains/yasm/xmake.lua b/xmake/toolchains/yasm/xmake.lua index 4f0d43a37..a99a15cc6 100644 --- a/xmake/toolchains/yasm/xmake.lua +++ b/xmake/toolchains/yasm/xmake.lua @@ -28,9 +28,9 @@ toolchain("yasm") on_load(function (toolchain) if is_plat("macosx") then toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "macho64" or "macho32") - elseif is_plat("linux") then + elseif is_plat("linux", "bsd") then toolchain:add("yasm.asflags", "-f", is_arch("x86_64") and "elf64" or "elf32") - elseif is_plat("windows") then + elseif is_plat("windows", "mingw", "msys", "cygwin") then toolchain:add("yasm.asflags", "-f", is_arch("x64") and "win64" or "win32") end end) -- cgit v1.3.1 From ea6b12de91048a1fe404bbad8b14ed2a148730a7 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:10:25 +0800 Subject: add fasm toolchain --- tests/projects/fasm/src/main.S | 28 ++++++++++++++++++++++++++++ tests/projects/fasm/xmake.lua | 3 +++ xmake/toolchains/fasm/xmake.lua | 31 +++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 tests/projects/fasm/src/main.S create mode 100644 tests/projects/fasm/xmake.lua create mode 100644 xmake/toolchains/fasm/xmake.lua diff --git a/tests/projects/fasm/src/main.S b/tests/projects/fasm/src/main.S new file mode 100644 index 000000000..90f4b88b4 --- /dev/null +++ b/tests/projects/fasm/src/main.S @@ -0,0 +1,28 @@ +format MZ + +entry main:start ; program entry point +stack 100h ; stack size + +segment main ; main program segment + + start: + mov ax,text + mov ds,ax + + mov dx,hello + call extra:write_text + + mov ax,4C00h + int 21h + +segment text + + hello db 'Hello world!',24h + +segment extra + + write_text: + mov ah,9 + int 21h + retf + diff --git a/tests/projects/fasm/xmake.lua b/tests/projects/fasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/fasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/xmake/toolchains/fasm/xmake.lua b/xmake/toolchains/fasm/xmake.lua new file mode 100644 index 000000000..cf61cc2ab --- /dev/null +++ b/xmake/toolchains/fasm/xmake.lua @@ -0,0 +1,31 @@ +--!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("fasm") + + -- set toolsets + set_toolsets("as", "fasm") + + -- on load + on_load(function (toolchain) + -- reset asflags for fasm + toolchain:add("fasm.asflags", "") + end) -- cgit v1.3.1 From 26880aba618ec5aab600170f1d695d34ee742068 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:12:09 +0800 Subject: add gas tests --- tests/projects/asm/fasm/src/main.S | 28 ++++++++++++++++++++++++++++ tests/projects/asm/fasm/xmake.lua | 3 +++ tests/projects/asm/gas/src/main.S | 9 +++++++++ tests/projects/asm/gas/xmake.lua | 3 +++ tests/projects/asm/nasm/src/main.S | 21 +++++++++++++++++++++ tests/projects/asm/nasm/xmake.lua | 3 +++ tests/projects/asm/yasm/src/main.S | 20 ++++++++++++++++++++ tests/projects/asm/yasm/xmake.lua | 3 +++ tests/projects/fasm/src/main.S | 28 ---------------------------- tests/projects/fasm/xmake.lua | 3 --- tests/projects/nasm/src/main.S | 21 --------------------- tests/projects/nasm/xmake.lua | 3 --- tests/projects/yasm/src/main.S | 20 -------------------- tests/projects/yasm/xmake.lua | 3 --- 14 files changed, 90 insertions(+), 78 deletions(-) create mode 100644 tests/projects/asm/fasm/src/main.S create mode 100644 tests/projects/asm/fasm/xmake.lua create mode 100644 tests/projects/asm/gas/src/main.S create mode 100644 tests/projects/asm/gas/xmake.lua create mode 100644 tests/projects/asm/nasm/src/main.S create mode 100644 tests/projects/asm/nasm/xmake.lua create mode 100644 tests/projects/asm/yasm/src/main.S create mode 100644 tests/projects/asm/yasm/xmake.lua delete mode 100644 tests/projects/fasm/src/main.S delete mode 100644 tests/projects/fasm/xmake.lua delete mode 100644 tests/projects/nasm/src/main.S delete mode 100644 tests/projects/nasm/xmake.lua delete mode 100644 tests/projects/yasm/src/main.S delete mode 100644 tests/projects/yasm/xmake.lua diff --git a/tests/projects/asm/fasm/src/main.S b/tests/projects/asm/fasm/src/main.S new file mode 100644 index 000000000..90f4b88b4 --- /dev/null +++ b/tests/projects/asm/fasm/src/main.S @@ -0,0 +1,28 @@ +format MZ + +entry main:start ; program entry point +stack 100h ; stack size + +segment main ; main program segment + + start: + mov ax,text + mov ds,ax + + mov dx,hello + call extra:write_text + + mov ax,4C00h + int 21h + +segment text + + hello db 'Hello world!',24h + +segment extra + + write_text: + mov ah,9 + int 21h + retf + diff --git a/tests/projects/asm/fasm/xmake.lua b/tests/projects/asm/fasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/fasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/gas/src/main.S b/tests/projects/asm/gas/src/main.S new file mode 100644 index 000000000..9c242f4a1 --- /dev/null +++ b/tests/projects/asm/gas/src/main.S @@ -0,0 +1,9 @@ + .global main + + .text +main: # This is called by C library's startup code + mov $message, %rdi # First integer (or pointer) parameter in %rdi + call puts # puts(message) + ret # Return to C library code +message: + .asciz "Hola, mundo" # asciz puts a 0 byte at the end diff --git a/tests/projects/asm/gas/xmake.lua b/tests/projects/asm/gas/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/gas/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S new file mode 100644 index 000000000..5b3a93699 --- /dev/null +++ b/tests/projects/asm/nasm/src/main.S @@ -0,0 +1,21 @@ +global _main + + +section .text + +_main: + mov rax, 0x2000004 ; write + mov rdi, 1 ; stdout + mov rsi, msg + mov rdx, msg.len + syscall + + mov rax, 0x2000001 ; exit + mov rdi, 0 + syscall + + +section .data + +msg: db "hello xmake!", 10 +.len: equ $ - msg diff --git a/tests/projects/asm/nasm/xmake.lua b/tests/projects/asm/nasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/nasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/asm/yasm/src/main.S b/tests/projects/asm/yasm/src/main.S new file mode 100644 index 000000000..800722a44 --- /dev/null +++ b/tests/projects/asm/yasm/src/main.S @@ -0,0 +1,20 @@ +bits 64 + +extern _puts + +section .data + +message: + db 'hello xmake!', 0 + +section .text + +global _main +_main: + push rbp + mov rbp, rsp + lea rdi, [rel message] + call _puts + xor rax, rax + pop rbp + ret diff --git a/tests/projects/asm/yasm/xmake.lua b/tests/projects/asm/yasm/xmake.lua new file mode 100644 index 000000000..f728b2ca1 --- /dev/null +++ b/tests/projects/asm/yasm/xmake.lua @@ -0,0 +1,3 @@ +target("test") + set_kind("binary") + add_files("src/*.S") diff --git a/tests/projects/fasm/src/main.S b/tests/projects/fasm/src/main.S deleted file mode 100644 index 90f4b88b4..000000000 --- a/tests/projects/fasm/src/main.S +++ /dev/null @@ -1,28 +0,0 @@ -format MZ - -entry main:start ; program entry point -stack 100h ; stack size - -segment main ; main program segment - - start: - mov ax,text - mov ds,ax - - mov dx,hello - call extra:write_text - - mov ax,4C00h - int 21h - -segment text - - hello db 'Hello world!',24h - -segment extra - - write_text: - mov ah,9 - int 21h - retf - diff --git a/tests/projects/fasm/xmake.lua b/tests/projects/fasm/xmake.lua deleted file mode 100644 index f728b2ca1..000000000 --- a/tests/projects/fasm/xmake.lua +++ /dev/null @@ -1,3 +0,0 @@ -target("test") - set_kind("binary") - add_files("src/*.S") diff --git a/tests/projects/nasm/src/main.S b/tests/projects/nasm/src/main.S deleted file mode 100644 index 5b3a93699..000000000 --- a/tests/projects/nasm/src/main.S +++ /dev/null @@ -1,21 +0,0 @@ -global _main - - -section .text - -_main: - mov rax, 0x2000004 ; write - mov rdi, 1 ; stdout - mov rsi, msg - mov rdx, msg.len - syscall - - mov rax, 0x2000001 ; exit - mov rdi, 0 - syscall - - -section .data - -msg: db "hello xmake!", 10 -.len: equ $ - msg diff --git a/tests/projects/nasm/xmake.lua b/tests/projects/nasm/xmake.lua deleted file mode 100644 index f728b2ca1..000000000 --- a/tests/projects/nasm/xmake.lua +++ /dev/null @@ -1,3 +0,0 @@ -target("test") - set_kind("binary") - add_files("src/*.S") diff --git a/tests/projects/yasm/src/main.S b/tests/projects/yasm/src/main.S deleted file mode 100644 index 800722a44..000000000 --- a/tests/projects/yasm/src/main.S +++ /dev/null @@ -1,20 +0,0 @@ -bits 64 - -extern _puts - -section .data - -message: - db 'hello xmake!', 0 - -section .text - -global _main -_main: - push rbp - mov rbp, rsp - lea rdi, [rel message] - call _puts - xor rax, rax - pop rbp - ret diff --git a/tests/projects/yasm/xmake.lua b/tests/projects/yasm/xmake.lua deleted file mode 100644 index f728b2ca1..000000000 --- a/tests/projects/yasm/xmake.lua +++ /dev/null @@ -1,3 +0,0 @@ -target("test") - set_kind("binary") - add_files("src/*.S") -- cgit v1.3.1 From 3531c0cb2c7f2f84f37e3c4ac42ad142d7a74bf0 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 19 May 2020 23:13:00 +0800 Subject: add envs to iphoneos/watchos --- xmake/platforms/iphoneos/xmake.lua | 2 +- xmake/platforms/watchos/xmake.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index ff5ba2204..d0d57f5da 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -37,7 +37,7 @@ platform("iphoneos") on_check("check") -- set toolchains - set_toolchains("xcode") + set_toolchains("envs", "xcode") -- set menu set_menu { diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 1356af3ab..9215e2b96 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -37,7 +37,7 @@ platform("watchos") on_check("check") -- set toolchains - set_toolchains("xcode") + set_toolchains("envs", "xcode") -- set menu set_menu { -- cgit v1.3.1 From 42d26ba464c91d368eb6fdc44377561213f5ca3b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:06:51 +0800 Subject: add ndk toolchain --- xmake/platforms/android/check.lua | 135 ++------------- xmake/platforms/android/load.lua | 320 ----------------------------------- xmake/platforms/android/xmake.lua | 4 +- xmake/toolchains/ndk/check.lua | 57 +++++++ xmake/toolchains/ndk/load.lua | 340 ++++++++++++++++++++++++++++++++++++++ xmake/toolchains/ndk/xmake.lua | 28 ++++ xmake/toolchains/rust/xmake.lua | 5 - 7 files changed, 437 insertions(+), 452 deletions(-) delete mode 100644 xmake/platforms/android/load.lua create mode 100644 xmake/toolchains/ndk/check.lua create mode 100644 xmake/toolchains/ndk/load.lua create mode 100644 xmake/toolchains/ndk/xmake.lua diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua index 04d639483..c262e1bed 100644 --- a/xmake/platforms/android/check.lua +++ b/xmake/platforms/android/check.lua @@ -20,136 +20,21 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_ndk") -import("detect.sdks.find_android_sdk") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the ndk toolchain -function _check_ndk() - local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) - if ndk then - config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) -- maybe to global - config.set("bin", ndk.bindir, {force = true, readonly = true}) - config.set("cross", ndk.cross, {force = true, readonly = true}) - config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- check the android sdk -function _check_android_sdk() - local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) - if sdk then - config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) -- maybe to global - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- get gcc toolchain bin directory - local gcc_toolchain_bin = nil - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - gcc_toolchain_bin = path.join(gcc_toolchain, "bin") - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local strip = toolchain("the symbols stripper") - local as = toolchain("the assember") - 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 toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip, - rc = rc, ["rcld"] = rc_ld, ["rcsh"] = rc_sh, ["rcar"] = rc_ar} - - -- init the c compiler - cc:add({name = "gcc", cross = cross}, "clang") - - -- init the c++ compiler - cxx:add({name = "g++", cross = cross}, "clang++") - - -- init the c preprocessor - cpp:add({name = "gcc -E", cross = cross}, "clang -E") - - -- init the assember - as:add({name = "gcc", cross = cross}, "clang") - - -- init the linker - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add("clang++", "clang") - - -- init the shared library linker - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add("clang++", "clang") - - -- init the static library archiver - ar:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library extractor - ex:add({name = "ar", cross = cross, pathes = gcc_toolchain_bin}, "llvm-ar") - - -- init the static library index generator - ranlib:add({name = "ranlib", cross = cross, pathes = gcc_toolchain_bin}, "ranlib") - - -- init the symbols stripper - strip:add({name = "strip", cross = cross, pathes = gcc_toolchain_bin}, "strip") - - -- 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") - - return toolchains -end -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("android.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else +function main(platform) - -- check arch - check_arch(config, "armeabi-v7a") + -- check arch + check_arch(config, "armeabi-v7a") - -- check android sdk - _check_android_sdk() - - -- check ndk - _check_ndk() - - -- check ld and sh, @note toolchains must be initialized after calling check_ndk() - local toolchains = singleton.get("android.toolchains", _toolchains) - check_toolchain(config, "ld", toolchains.ld) - check_toolchain(config, "sh", toolchains.sh) + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/android/load.lua b/xmake/platforms/android/load.lua deleted file mode 100644 index 773d69fcc..000000000 --- a/xmake/platforms/android/load.lua +++ /dev/null @@ -1,320 +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 - local arm32 = false - local arch = config.get("arch") - platform:add("ldflags", "-llog") - platform:add("shflags", "-llog") - if arch and (arch == "armeabi" or arch == "armeabi-v7a" or arch == "armv5te" or arch == "armv7-a") then -- armv5te/armv7-a are deprecated - arm32 = true - platform:add("cxflags", "-mthumb") - platform:add("asflags", "-mthumb") - platform:add("ldflags", "-mthumb") - platform:add("shflags", "-mthumb") - end - - -- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin - local isllvm = false - local bindir = config.get("bin") - if bindir and bindir:find("llvm", 1, true) then - isllvm = true - end - - -- init architecture - if isllvm then - - -- add target - local targets = - { - ["armv5te"] = "armv5te-none-linux-androideabi" -- deprecated - , ["armeabi"] = "armv5te-none-linux-androideabi" -- removed in ndk r17 - , ["armv7-a"] = "armv7-none-linux-androideabi" -- deprecated - , ["armeabi-v7a"] = "armv7-none-linux-androideabi" - , ["arm64-v8a"] = "aarch64-none-linux-android" - , ["i386"] = "i686-none-linux-android" -- deprecated - , ["x86"] = "i686-none-linux-android" - , ["x86_64"] = "x86_64-none-linux-android" - , ["mips"] = "mipsel-none-linux-android" -- removed in ndk r17 - , ["mips64"] = "mips64el-none-linux-android" -- removed in ndk r17 - } - assert(targets[arch], "unknown arch(%s) for android!", arch) - platform:add("cxflags", "-target " .. targets[arch]) - platform:add("asflags", "-target " .. targets[arch]) - platform:add("ldflags", "-target " .. targets[arch]) - platform:add("shflags", "-target " .. targets[arch]) - - -- add gcc toolchain - local gcc_toolchain = config.get("gcc_toolchain") - if gcc_toolchain then - platform:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("asflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) - platform:add("shflags", "-gcc-toolchain " .. gcc_toolchain) - end - else - local march = arch - if arch == "arm64-v8a" then - march = "armv8-a" - else - march = "armv5te" - end - -- old version ndk - platform:add("cxflags", "-march=" .. march) - platform:add("asflags", "-march=" .. march) - platform:add("ldflags", "-march=" .. march) - platform:add("shflags", "-march=" .. march) - end - - -- init cxflags for the target kind: binary - platform:add("binary.cxflags", "-fPIE", "-pie") - - -- add flags for the sdk directory of ndk - local ndk = config.get("ndk") - local ndkver = config.get("ndkver") - local ndk_sdkver = config.get("ndk_sdkver") - if ndk and ndk_sdkver then - - -- the sysroot archs - local sysroot_archs = - { - ["armv5te"] = "arch-arm" -- deprecated - , ["armv7-a"] = "arch-arm" -- deprecated - , ["armeabi"] = "arch-arm" -- removed in ndk r17 - , ["armeabi-v7a"] = "arch-arm" - , ["arm64-v8a"] = "arch-arm64" - , i386 = "arch-x86" -- deprecated - , x86 = "arch-x86" - , x86_64 = "arch-x86_64" - , mips = "arch-mips" -- removed in ndk r17 - , mips64 = "arch-mips64" -- removed in ndk r17 - } - local sysroot_arch = sysroot_archs[arch] - - -- add sysroot - -- - -- @see https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md - -- - -- Before NDK r14, we had a set of libc headers for each API version. - -- In many cases these headers were incorrect. Many exposed APIs that didn‘t exist, and others didn’t expose APIs that did. - -- - -- In NDK r14 (as an opt in feature) we unified these into a single set of headers, called unified headers. - -- This single header path is used for every platform level. API level guards are handled with #ifdef. - -- These headers can be found in prebuilts/ndk/headers. - -- - -- Unified headers are built directly from the Android platform, so they are up to date and correct (or at the very least, - -- any bugs in the NDK headers will also be a bug in the platform headers, which means we're much more likely to find them). - -- - -- In r15 unified headers are used by default. In r16, the old headers have been removed. - -- - local ndk_sdkdir = path.translate(format("%s/platforms/android-%d", ndk, ndk_sdkver)) - local ndk_sysroot_be_r14 = path.join(ndk, "sysroot") - if os.isdir(ndk_sysroot_be_r14) then - - -- the triples - local triples = - { - ["armv5te"] = "arm-linux-androideabi" -- deprecated - , ["armv7-a"] = "arm-linux-androideabi" -- deprecated - , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 - , ["armeabi-v7a"] = "arm-linux-androideabi" - , ["arm64-v8a"] = "aarch64-linux-android" - , i386 = "i686-linux-android" -- deprecated - , x86 = "i686-linux-android" - , x86_64 = "x86_64-linux-android" - , mips = "mips-linux-android" -- removed in ndk r17 - , mips64 = "mips64-linux-android" -- removed in ndk r17 - } - platform:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver) - platform:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver) - platform:add("cflags", "--sysroot=" .. ndk_sysroot_be_r14) - platform:add("cxxflags","--sysroot=" .. ndk_sysroot_be_r14) - platform:add("asflags", "--sysroot=" .. ndk_sysroot_be_r14) - platform:add("cflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) - platform:add("cxxflags","-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) - platform:add("asflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) - else - if sysroot_arch then - platform:add("cflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("cxxflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("asflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - end - end - if sysroot_arch then - platform:add("ldflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - platform:add("shflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) - end - - -- add "-fPIE -pie" to ldflags - platform:add("ldflags", "-fPIE") - platform:add("ldflags", "-pie") - - -- get llvm c++ stl sdk directory - local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) - - -- get gnu c++ stl sdk directory - local cxxstl_sdkdir_gnustl = nil - if config.get("ndk_toolchains_ver") then - cxxstl_sdkdir_gnustl = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, config.get("ndk_toolchains_ver"))) - end - - -- get stlport c++ sdk directory - local cxxstl_sdkdir_stlport = path.translate(format("%s/sources/cxx-stl/stlport", ndk)) - - -- get c++ stl sdk directory - local cxxstl_sdkdir = nil - local ndk_cxxstl = config.get("ndk_cxxstl") - if ndk_cxxstl then - -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared - if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then - cxxstl_sdkdir = cxxstl_sdkdir_llvmstl - elseif ndk_cxxstl:startswith("gnustl") then - cxxstl_sdkdir = cxxstl_sdkdir_gnustl - elseif ndk_cxxstl:startswith("stlport") then - cxxstl_sdkdir = cxxstl_sdkdir_stlport - end - else - if isllvm then - ndk_cxxstl = "c++_static" - cxxstl_sdkdir = cxxstl_sdkdir_llvmstl - end - if (cxxstl_sdkdir == nil or not os.isdir(cxxstl_sdkdir)) and cxxstl_sdkdir_gnustl then -- <= ndk r16 - ndk_cxxstl = "gnustl_static" - cxxstl_sdkdir = cxxstl_sdkdir_gnustl - end - end - - -- only for c++ stl - if config.get("ndk_stdcxx") and cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then - - -- the toolchains archs - local toolchains_archs = - { - ["armv5te"] = "armeabi" -- deprecated - , ["armv7-a"] = "armeabi-v7a" -- deprecated - , ["armeabi"] = "armeabi" -- removed in ndk r17 - , ["armeabi-v7a"] = "armeabi-v7a" - , ["arm64-v8a"] = "arm64-v8a" - , i386 = "x86" -- deprecated - , x86 = "x86" - , x86_64 = "x86_64" - , mips = "mips" -- removed in ndk r17 - , mips64 = "mips64" -- removed in ndk r17 - } - local toolchains_arch = toolchains_archs[arch] - - -- add c++ stl include and link directories - if toolchains_arch then - platform:add("ldflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) - platform:add("shflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) - end - if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then - platform:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) - if toolchains_arch then - platform:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) - end - local abi_path = path.join(ndk, "sources", "cxx-stl", "llvm-libc++abi") - local before_r13 = path.join(abi_path, "libcxxabi") - local after_r13 = path.join(abi_path, "include") - if os.isdir(before_r13) then - platform:add("cxxflags", "-I" .. before_r13) - elseif os.isdir(after_r13) then - platform:add("cxxflags", "-I" .. after_r13) - end - elseif ndk_cxxstl:startswith("gnustl") then - platform:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) - if toolchains_arch then - platform:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) - end - elseif ndk_cxxstl:startswith("stlport") then - platform:add("cxxflags", format("-I%s/stlport", cxxstl_sdkdir)) - end - - -- add c++ stl links - if ndk_cxxstl == "c++_static" or ndk_cxxstl == "llvmstl_static" then - platform:add("ldflags", "-lc++_static", "-lc++abi") - platform:add("shflags", "-lc++_static", "-lc++abi") - if arm32 then - platform:add("ldflags", "-lunwind", "-latomic") - platform:add("shflags", "-lunwind", "-latomic") - end - elseif ndk_cxxstl == "c++_shared" or ndk_cxxstl == "llvmstl_shared" then - platform:add("ldflags", "-lc++_shared", "-lc++abi") - platform:add("shflags", "-lc++_shared", "-lc++abi") - if arm32 then - platform:add("ldflags", "-lunwind", "-latomic") - platform:add("shflags", "-lunwind", "-latomic") - end - elseif ndk_cxxstl == "gnustl_static" then - platform:add("ldflags", "-lgnustl_static") - platform:add("shflags", "-lgnustl_static") - elseif ndk_cxxstl == "gnustl_shared" then - platform:add("ldflags", "-lgnustl_shared") - platform:add("shflags", "-lgnustl_shared") - elseif ndk_cxxstl == "stlport_static" then - platform:add("ldflags", "-lstlport_static") - platform:add("shflags", "-lstlport_static") - elseif ndk_cxxstl == "stlport_shared" then - platform:add("ldflags", "-lstlport_shared") - platform:add("shflags", "-lstlport_shared") - end - - -- fix 'ld: error: cannot find -lc++' for clang++.exe on r20/windows - -- @see https://github.com/xmake-io/xmake/issues/684 - if ndkver and ndkver >= 20 and (ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl")) then - platform:add("ldflags", "-nostdlib++") - platform:add("shflags", "-nostdlib++") - end - end - end - - -- init targets for rust - local targets_rust = - { - ["armv5te"] = "arm-linux-androideabi" -- deprecated - , ["armv7-a"] = "arm-linux-androideabi" -- deprecated - , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 - , ["armeabi-v7a"] = "arm-linux-androideabi" - , ["arm64-v8a"] = "aarch64-linux-android" - } - - -- init flags for rust - if targets_rust[arch] then - platform:add("rcflags", "--target=" .. targets_rust[arch]) - end - platform:add("rcshflags", "-C link-args=\"" .. (table.concat(platform:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) - platform:add("rcldflags", "-C link-args=\"" .. (table.concat(platform:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) - local sh = config.get("sh") - if sh then - platform:add("rcshflags", "-C linker=" .. sh) - end - local ld = config.get("ld") - if ld then - platform:add("rcldflags", "-C linker=" .. ld) - end -end - - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index cb7d52594..4644af7a4 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -42,8 +42,8 @@ platform("android") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "ndk", "rust") -- set menu set_menu { diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua new file mode 100644 index 000000000..fe9d7629f --- /dev/null +++ b/xmake/toolchains/ndk/check.lua @@ -0,0 +1,57 @@ +--!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_ndk") +import("detect.sdks.find_android_sdk") + +-- check the ndk toolchain +function _check_ndk() + local ndk = find_ndk(config.get("ndk"), {force = true, verbose = true}) + if ndk then + config.set("ndk", ndk.sdkdir, {force = true, readonly = true}) + config.set("bin", ndk.bindir, {force = true, readonly = true}) + config.set("cross", ndk.cross, {force = true, readonly = true}) + config.set("gcc_toolchain", ndk.gcc_toolchain, {force = true, readonly = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --ndk=xxx") + cprint("or - xmake global --ndk=xxx") + raise() + end +end + +-- check the android sdk +function _check_android_sdk() + local sdk = find_android_sdk(config.get("android_sdk"), {force = true, verbose = true}) + if sdk then + config.set("sdk", sdk.sdkdir, {force = true, readonly = true}) + end +end + +-- main entry +function main(toolchain) + _check_android_sdk() + _check_ndk() + return true +end diff --git a/xmake/toolchains/ndk/load.lua b/xmake/toolchains/ndk/load.lua new file mode 100644 index 000000000..b2b0ae95f --- /dev/null +++ b/xmake/toolchains/ndk/load.lua @@ -0,0 +1,340 @@ +--!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 load.lua +-- + +-- imports +import("core.project.config") + +-- main entry +function main(toolchain) + + -- get cross + local cross = config.get("cross") or "" + + -- get gcc toolchain bin directory + local gcc_toolchain_bin = nil + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + gcc_toolchain_bin = path.join(gcc_toolchain, "bin") + end + + -- set toolsets + toolchain:set("toolsets", "cc", "clang", cross .. "gcc") + toolchain:set("toolsets", "cxx", "clang++", cross .. "g++") + toolchain:set("toolsets", "cpp", "clang -E", cross .. "gcc -E") + toolchain:set("toolsets", "as", "clang", cross .. "gcc") + toolchain:set("toolsets", "ld", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", "clang++", "clang", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ex", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ar") or (cross .. "ar"), "llvm-ar") + toolchain:set("toolsets", "ranlib", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "ranlib") or (cross .. "ranlib")) + toolchain:set("toolsets", "strip", gcc_toolchain_bin and path.join(gcc_toolchain_bin, cross .. "strip") or (cross .. "strip")) + + -- init flags + local arm32 = false + local arch = config.get("arch") + toolchain:add("ldflags", "-llog") + toolchain:add("shflags", "-llog") + if arch and (arch == "armeabi" or arch == "armeabi-v7a" or arch == "armv5te" or arch == "armv7-a") then -- armv5te/armv7-a are deprecated + arm32 = true + toolchain:add("cxflags", "-mthumb") + toolchain:add("asflags", "-mthumb") + toolchain:add("ldflags", "-mthumb") + toolchain:add("shflags", "-mthumb") + end + + -- use llvm directory? e.g. android-ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin + local isllvm = false + local bindir = config.get("bin") + if bindir and bindir:find("llvm", 1, true) then + isllvm = true + end + + -- init architecture + if isllvm then + + -- add target + local targets = + { + ["armv5te"] = "armv5te-none-linux-androideabi" -- deprecated + , ["armeabi"] = "armv5te-none-linux-androideabi" -- removed in ndk r17 + , ["armv7-a"] = "armv7-none-linux-androideabi" -- deprecated + , ["armeabi-v7a"] = "armv7-none-linux-androideabi" + , ["arm64-v8a"] = "aarch64-none-linux-android" + , ["i386"] = "i686-none-linux-android" -- deprecated + , ["x86"] = "i686-none-linux-android" + , ["x86_64"] = "x86_64-none-linux-android" + , ["mips"] = "mipsel-none-linux-android" -- removed in ndk r17 + , ["mips64"] = "mips64el-none-linux-android" -- removed in ndk r17 + } + assert(targets[arch], "unknown arch(%s) for android!", arch) + toolchain:add("cxflags", "-target " .. targets[arch]) + toolchain:add("asflags", "-target " .. targets[arch]) + toolchain:add("ldflags", "-target " .. targets[arch]) + toolchain:add("shflags", "-target " .. targets[arch]) + + -- add gcc toolchain + local gcc_toolchain = config.get("gcc_toolchain") + if gcc_toolchain then + toolchain:add("cxflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("asflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("ldflags", "-gcc-toolchain " .. gcc_toolchain) + toolchain:add("shflags", "-gcc-toolchain " .. gcc_toolchain) + end + else + local march = arch + if arch == "arm64-v8a" then + march = "armv8-a" + else + march = "armv5te" + end + -- old version ndk + toolchain:add("cxflags", "-march=" .. march) + toolchain:add("asflags", "-march=" .. march) + toolchain:add("ldflags", "-march=" .. march) + toolchain:add("shflags", "-march=" .. march) + end + + -- init cxflags for the target kind: binary + toolchain:add("binary.cxflags", "-fPIE", "-pie") + + -- add flags for the sdk directory of ndk + local ndk = config.get("ndk") + local ndkver = config.get("ndkver") + local ndk_sdkver = config.get("ndk_sdkver") + if ndk and ndk_sdkver then + + -- the sysroot archs + local sysroot_archs = + { + ["armv5te"] = "arch-arm" -- deprecated + , ["armv7-a"] = "arch-arm" -- deprecated + , ["armeabi"] = "arch-arm" -- removed in ndk r17 + , ["armeabi-v7a"] = "arch-arm" + , ["arm64-v8a"] = "arch-arm64" + , i386 = "arch-x86" -- deprecated + , x86 = "arch-x86" + , x86_64 = "arch-x86_64" + , mips = "arch-mips" -- removed in ndk r17 + , mips64 = "arch-mips64" -- removed in ndk r17 + } + local sysroot_arch = sysroot_archs[arch] + + -- add sysroot + -- + -- @see https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md + -- + -- Before NDK r14, we had a set of libc headers for each API version. + -- In many cases these headers were incorrect. Many exposed APIs that didn‘t exist, and others didn’t expose APIs that did. + -- + -- In NDK r14 (as an opt in feature) we unified these into a single set of headers, called unified headers. + -- This single header path is used for every platform level. API level guards are handled with #ifdef. + -- These headers can be found in prebuilts/ndk/headers. + -- + -- Unified headers are built directly from the Android platform, so they are up to date and correct (or at the very least, + -- any bugs in the NDK headers will also be a bug in the platform headers, which means we're much more likely to find them). + -- + -- In r15 unified headers are used by default. In r16, the old headers have been removed. + -- + local ndk_sdkdir = path.translate(format("%s/platforms/android-%d", ndk, ndk_sdkver)) + local ndk_sysroot_be_r14 = path.join(ndk, "sysroot") + if os.isdir(ndk_sysroot_be_r14) then + + -- the triples + local triples = + { + ["armv5te"] = "arm-linux-androideabi" -- deprecated + , ["armv7-a"] = "arm-linux-androideabi" -- deprecated + , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "arm-linux-androideabi" + , ["arm64-v8a"] = "aarch64-linux-android" + , i386 = "i686-linux-android" -- deprecated + , x86 = "i686-linux-android" + , x86_64 = "x86_64-linux-android" + , mips = "mips-linux-android" -- removed in ndk r17 + , mips64 = "mips64-linux-android" -- removed in ndk r17 + } + toolchain:add("cxflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("asflags", "-D__ANDROID_API__=" .. ndk_sdkver) + toolchain:add("cflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cxxflags","--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("asflags", "--sysroot=" .. ndk_sysroot_be_r14) + toolchain:add("cflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("cxxflags","-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + toolchain:add("asflags", "-isystem " .. path.join(ndk_sysroot_be_r14, "usr", "include", triples[arch])) + else + if sysroot_arch then + toolchain:add("cflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("cxxflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("asflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + end + end + if sysroot_arch then + toolchain:add("ldflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + toolchain:add("shflags", format("--sysroot=%s/%s", ndk_sdkdir, sysroot_arch)) + end + + -- add "-fPIE -pie" to ldflags + toolchain:add("ldflags", "-fPIE") + toolchain:add("ldflags", "-pie") + + -- get llvm c++ stl sdk directory + local cxxstl_sdkdir_llvmstl = path.translate(format("%s/sources/cxx-stl/llvm-libc++", ndk)) + + -- get gnu c++ stl sdk directory + local cxxstl_sdkdir_gnustl = nil + if config.get("ndk_toolchains_ver") then + cxxstl_sdkdir_gnustl = path.translate(format("%s/sources/cxx-stl/gnu-libstdc++/%s", ndk, config.get("ndk_toolchains_ver"))) + end + + -- get stlport c++ sdk directory + local cxxstl_sdkdir_stlport = path.translate(format("%s/sources/cxx-stl/stlport", ndk)) + + -- get c++ stl sdk directory + local cxxstl_sdkdir = nil + local ndk_cxxstl = config.get("ndk_cxxstl") + if ndk_cxxstl then + -- we uses c++_static/c++_shared instead of llvmstl_static/llvmstl_shared + if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then + cxxstl_sdkdir = cxxstl_sdkdir_llvmstl + elseif ndk_cxxstl:startswith("gnustl") then + cxxstl_sdkdir = cxxstl_sdkdir_gnustl + elseif ndk_cxxstl:startswith("stlport") then + cxxstl_sdkdir = cxxstl_sdkdir_stlport + end + else + if isllvm then + ndk_cxxstl = "c++_static" + cxxstl_sdkdir = cxxstl_sdkdir_llvmstl + end + if (cxxstl_sdkdir == nil or not os.isdir(cxxstl_sdkdir)) and cxxstl_sdkdir_gnustl then -- <= ndk r16 + ndk_cxxstl = "gnustl_static" + cxxstl_sdkdir = cxxstl_sdkdir_gnustl + end + end + + -- only for c++ stl + if config.get("ndk_stdcxx") and cxxstl_sdkdir and os.isdir(cxxstl_sdkdir) then + + -- the toolchains archs + local toolchains_archs = + { + ["armv5te"] = "armeabi" -- deprecated + , ["armv7-a"] = "armeabi-v7a" -- deprecated + , ["armeabi"] = "armeabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "armeabi-v7a" + , ["arm64-v8a"] = "arm64-v8a" + , i386 = "x86" -- deprecated + , x86 = "x86" + , x86_64 = "x86_64" + , mips = "mips" -- removed in ndk r17 + , mips64 = "mips64" -- removed in ndk r17 + } + local toolchains_arch = toolchains_archs[arch] + + -- add c++ stl include and link directories + if toolchains_arch then + toolchain:add("ldflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + toolchain:add("shflags", format("-L%s/libs/%s", cxxstl_sdkdir, toolchains_arch)) + end + if ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl") then + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + if toolchains_arch then + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + end + local abi_path = path.join(ndk, "sources", "cxx-stl", "llvm-libc++abi") + local before_r13 = path.join(abi_path, "libcxxabi") + local after_r13 = path.join(abi_path, "include") + if os.isdir(before_r13) then + toolchain:add("cxxflags", "-I" .. before_r13) + elseif os.isdir(after_r13) then + toolchain:add("cxxflags", "-I" .. after_r13) + end + elseif ndk_cxxstl:startswith("gnustl") then + toolchain:add("cxxflags", format("-I%s/include", cxxstl_sdkdir)) + if toolchains_arch then + toolchain:add("cxxflags", format("-I%s/libs/%s/include", cxxstl_sdkdir, toolchains_arch)) + end + elseif ndk_cxxstl:startswith("stlport") then + toolchain:add("cxxflags", format("-I%s/stlport", cxxstl_sdkdir)) + end + + -- add c++ stl links + if ndk_cxxstl == "c++_static" or ndk_cxxstl == "llvmstl_static" then + toolchain:add("ldflags", "-lc++_static", "-lc++abi") + toolchain:add("shflags", "-lc++_static", "-lc++abi") + if arm32 then + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") + end + elseif ndk_cxxstl == "c++_shared" or ndk_cxxstl == "llvmstl_shared" then + toolchain:add("ldflags", "-lc++_shared", "-lc++abi") + toolchain:add("shflags", "-lc++_shared", "-lc++abi") + if arm32 then + toolchain:add("ldflags", "-lunwind", "-latomic") + toolchain:add("shflags", "-lunwind", "-latomic") + end + elseif ndk_cxxstl == "gnustl_static" then + toolchain:add("ldflags", "-lgnustl_static") + toolchain:add("shflags", "-lgnustl_static") + elseif ndk_cxxstl == "gnustl_shared" then + toolchain:add("ldflags", "-lgnustl_shared") + toolchain:add("shflags", "-lgnustl_shared") + elseif ndk_cxxstl == "stlport_static" then + toolchain:add("ldflags", "-lstlport_static") + toolchain:add("shflags", "-lstlport_static") + elseif ndk_cxxstl == "stlport_shared" then + toolchain:add("ldflags", "-lstlport_shared") + toolchain:add("shflags", "-lstlport_shared") + end + + -- fix 'ld: error: cannot find -lc++' for clang++.exe on r20/windows + -- @see https://github.com/xmake-io/xmake/issues/684 + if ndkver and ndkver >= 20 and (ndk_cxxstl:startswith("c++") or ndk_cxxstl:startswith("llvmstl")) then + toolchain:add("ldflags", "-nostdlib++") + toolchain:add("shflags", "-nostdlib++") + end + end + end + + -- init targets for rust + local targets_rust = + { + ["armv5te"] = "arm-linux-androideabi" -- deprecated + , ["armv7-a"] = "arm-linux-androideabi" -- deprecated + , ["armeabi"] = "arm-linux-androideabi" -- removed in ndk r17 + , ["armeabi-v7a"] = "arm-linux-androideabi" + , ["arm64-v8a"] = "aarch64-linux-android" + } + + -- init flags for rust + if targets_rust[arch] then + toolchain:add("rcflags", "--target=" .. targets_rust[arch]) + end + toolchain:add("rcshflags", "-C link-args=\"" .. (table.concat(toolchain:get("shflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + toolchain:add("rcldflags", "-C link-args=\"" .. (table.concat(toolchain:get("ldflags"), " "):gsub("%-march=.-%s", "") .. "\"")) + local sh = toolchain:tool("sh") -- @note we cannot use `config.get("sh")`, because we need check sh first + if sh then + toolchain:add("rcshflags", "-C linker=" .. sh) + end + local ld = toolchain:tool("ld") + if ld then + toolchain:add("rcldflags", "-C linker=" .. ld) + end +end diff --git a/xmake/toolchains/ndk/xmake.lua b/xmake/toolchains/ndk/xmake.lua new file mode 100644 index 000000000..931df3753 --- /dev/null +++ b/xmake/toolchains/ndk/xmake.lua @@ -0,0 +1,28 @@ +--!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("ndk") + + -- check toolchain + on_check("check") + + -- load toolchain + on_load("load") diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua index 6c6e70bfb..6eba85440 100644 --- a/xmake/toolchains/rust/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -26,8 +26,3 @@ toolchain("rust") set_toolsets("rcld", "$(env RC)", "rustc") set_toolsets("rcsh", "$(env RC)", "rustc") set_toolsets("rcar", "$(env RC)", "rustc") - - -- on load - on_load(function (toolchain) - -- TODO for android ndk - end) -- cgit v1.3.1 From dc156eb40a6aa5f3a564ccbb82bd8319274bfb0c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:09:01 +0800 Subject: fix find_ndk --- xmake/modules/detect/sdks/find_ndk.lua | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/xmake/modules/detect/sdks/find_ndk.lua b/xmake/modules/detect/sdks/find_ndk.lua index 7dee10690..f0ee66676 100644 --- a/xmake/modules/detect/sdks/find_ndk.lua +++ b/xmake/modules/detect/sdks/find_ndk.lua @@ -101,7 +101,7 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) -- find ndk root directory sdkdir = _find_ndkdir(sdkdir) if not sdkdir then - return {} + return end -- get cross @@ -142,14 +142,11 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) bindir = find_directory("bin", path.join(sdkdir, "toolchains", gcc_toolchain_subdir, "prebuilt", "*")) end if not bindir then - return {} + return end -- find the sdk version local sdkver = ndk_sdkver or _find_ndk_sdkver(sdkdir, bindir, arch) - if not sdkver then - return {} - end -- find the gcc toolchain local gcc_toolchain = find_directory("bin", path.join(sdkdir, "toolchains", gcc_toolchain_subdir, "prebuilt", "*")) @@ -159,9 +156,6 @@ function _find_ndk(sdkdir, arch, ndk_sdkver, ndk_toolchains_ver) -- find the toolchains version local toolchains_ver = ndk_toolchains_ver or _find_ndk_toolchains_ver(gcc_toolchain or bindir) - if not toolchains_ver then - return {} - end -- get ndk version, e.g. r16b, .. local ndkver = nil -- cgit v1.3.1 From 86598231b463786d3a20bdb267e54f352f3c1b63 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:22:40 +0800 Subject: add mingw toolchain --- xmake/modules/detect/sdks/find_mingw.lua | 2 +- xmake/platforms/mingw/check.lua | 108 +++---------------------------- xmake/platforms/mingw/load.lua | 52 --------------- xmake/platforms/mingw/xmake.lua | 4 +- xmake/toolchains/mingw/check.lua | 40 ++++++++++++ xmake/toolchains/mingw/xmake.lua | 70 ++++++++++++++++++++ xmake/toolchains/ndk/check.lua | 1 - 7 files changed, 123 insertions(+), 154 deletions(-) delete mode 100644 xmake/platforms/mingw/load.lua create mode 100644 xmake/toolchains/mingw/check.lua create mode 100644 xmake/toolchains/mingw/xmake.lua diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index a8c22a9ee..06723859c 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -54,7 +54,7 @@ function _find_mingw(sdkdir, bindir, cross) -- find mingw root directory sdkdir = _find_mingwdir(sdkdir) if not sdkdir then - return {} + return end -- select cross on macos, e.g x86_64-w64-mingw32- or i686-w64-mingw32- diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua index 9905a53cc..a44983421 100644 --- a/xmake/platforms/mingw/check.lua +++ b/xmake/platforms/mingw/check.lua @@ -20,109 +20,21 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_mingw") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the mingw toolchain -function _check_mingw() - local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) - if mingw then - config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) - config.set("cross", mingw.cross, {readonly = true, force = true}) - config.set("bin", mingw.bindir, {readonly = true, force = true}) - else - -- failed - cprint("${bright color.error}please run:") - cprint(" - xmake config --ndk=xxx") - cprint("or - xmake global --ndk=xxx") - raise() - end -end - --- get toolchains -function _toolchains() - - -- get cross - local cross = config.get("cross") - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local mrc = toolchain("the resource compiler") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, mrc = mrc} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the resource compiler - mrc:add({name = "windres", cross = cross}) - - return toolchains -end -- check it -function main(platform, name) +function main(platform) - -- only check the given config name? - if name then - local toolchain = singleton.get("mingw.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, "x86_64") - -- check arch - check_arch(config, "x86_64") - - -- check mingw - _check_mingw() + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/mingw/load.lua b/xmake/platforms/mingw/load.lua deleted file mode 100644 index 653527e6d..000000000 --- a/xmake/platforms/mingw/load.lua +++ /dev/null @@ -1,52 +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 archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) - end - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") - - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end -end - diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index e119f137f..1c19443b8 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -36,8 +36,8 @@ platform("mingw") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "mingw") -- set menu set_menu { diff --git a/xmake/toolchains/mingw/check.lua b/xmake/toolchains/mingw/check.lua new file mode 100644 index 000000000..0bf65a0ce --- /dev/null +++ b/xmake/toolchains/mingw/check.lua @@ -0,0 +1,40 @@ +--!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.project.config") +import("detect.sdks.find_mingw") + +-- check the mingw toolchain +function main(toolchain) + local mingw = find_mingw(config.get("mingw"), {verbose = true, bindir = config.get("bin"), cross = config.get("cross")}) + if mingw then + config.set("mingw", mingw.sdkdir, {force = true, readonly = true}) + config.set("cross", mingw.cross, {readonly = true, force = true}) + config.set("bin", mingw.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}please run:") + cprint(" - xmake config --mingw=xxx") + cprint("or - xmake global --mingw=xxx") + raise() + end + return true +end diff --git a/xmake/toolchains/mingw/xmake.lua b/xmake/toolchains/mingw/xmake.lua new file mode 100644 index 000000000..10a9b2ffa --- /dev/null +++ b/xmake/toolchains/mingw/xmake.lua @@ -0,0 +1,70 @@ +--!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("mingw") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross + local cross = config.get("cross") or "" + + -- TODO add to environment module + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "g++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E") + toolchain:set("toolsets", "as", cross .. "gcc") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "mrc", cross .. "windres") + + -- init flags for architecture + local archflags = nil + local arch = config.get("arch") + if arch then + if arch == "x86_64" then archflags = "-m64" + elseif arch == "i386" then archflags = "-m32" + else archflags = "-arch " .. arch + end + end + if archflags then + toolchain:add("cxflags", archflags) + toolchain:add("asflags", archflags) + toolchain:add("ldflags", archflags) + toolchain:add("shflags", archflags) + end + end) diff --git a/xmake/toolchains/ndk/check.lua b/xmake/toolchains/ndk/check.lua index fe9d7629f..4cd4eea11 100644 --- a/xmake/toolchains/ndk/check.lua +++ b/xmake/toolchains/ndk/check.lua @@ -19,7 +19,6 @@ -- -- imports -import("core.base.option") import("core.project.config") import("detect.sdks.find_ndk") import("detect.sdks.find_android_sdk") -- cgit v1.3.1 From 04493b00d03e87e3c2af7d9f58bb43edb77eb410 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:30:23 +0800 Subject: add cross and llvm toolchains --- xmake/core/platform/platform.lua | 3 +- xmake/core/tool/toolchain.lua | 6 ++ xmake/platforms/cross/check.lua | 160 +++------------------------------------ xmake/platforms/cross/load.lua | 46 ----------- xmake/platforms/cross/xmake.lua | 4 +- xmake/toolchains/cross/check.lua | 41 ++++++++++ xmake/toolchains/cross/xmake.lua | 66 ++++++++++++++++ xmake/toolchains/envs/xmake.lua | 4 +- xmake/toolchains/llvm/check.lua | 41 ++++++++++ xmake/toolchains/llvm/xmake.lua | 60 +++++++++++++++ 10 files changed, 229 insertions(+), 202 deletions(-) delete mode 100644 xmake/platforms/cross/load.lua create mode 100644 xmake/toolchains/cross/check.lua create mode 100644 xmake/toolchains/cross/xmake.lua create mode 100644 xmake/toolchains/llvm/check.lua create mode 100644 xmake/toolchains/llvm/xmake.lua diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 3e3b537d1..1ca688636 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -110,8 +110,7 @@ function _instance:toolchains() local names = {} if config.get("toolchain") then table.insert(names, config.get("toolchain")) - end - if self._INFO:get("toolchains") then + elseif self._INFO:get("toolchains") then table.join2(names, self._INFO:get("toolchains")) end toolchains = {} diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 032445b3d..78da9ea7f 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -100,6 +100,11 @@ function _instance:bindir() return config.get("bin") or self:get("bindir") end +-- get the sdk directory +function _instance:sdkdir() + return config.get("sdk") or self:get("sdkdir") +end + -- do load function _instance:_load() if not self._LOADED then @@ -267,6 +272,7 @@ function toolchain._apis() values = { "toolchain.set_bindir" + , "toolchain.set_sdkdir" } , keyvalues = { diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua index 833dcb921..0c95f43c9 100644 --- a/xmake/platforms/cross/check.lua +++ b/xmake/platforms/cross/check.lua @@ -20,11 +20,6 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") -- check the architecture function _check_arch() @@ -36,154 +31,19 @@ function _check_arch() end end --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get llvm toolchains -function _toolchains_llvm() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", "clang") - - -- init the c preprocessor - cpp:add("$(env CPP)", "clang -E") - - -- init the c++ compiler - cxx:add("$(env CXX)", "clang", "clang++") - - -- init the assember - as:add("$(env AS)", "clang") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "clang++", "clang") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "clang++", "clang") - - -- init the static library archiver - ar:add("$(env AR)", "llvm-ar") - - -- init the static library extractor - ex:add("$(env AR)", "llvm-ar") - - -- init the static library index generator - ranlib:add("$(env RANLIB)", "llvm-ranlib") - - -- init the symbols stripper - strip:add("$(env STRIP)", "llvm-strip") - return toolchains -end - --- get toolchains -function _toolchains() - - -- get cross prefix - local cross = config.get("cross") or "" - - -- for llvm toolchains? - if cross == "" and config.get("toolchain") == "llvm" then - return _toolchains_llvm() - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 strip = toolchain("the symbols stripper") - local ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib, strip = strip} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c preprocessor - cpp:add("$(env CPP)", {name = "gcc -E", cross = cross}, {name = "clang -E", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library index generator - ranlib:add("$(env RANLIB)", {name = "ranlib", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - return toolchains -end - -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else +function main(platform) - -- check arch - _check_arch() + -- check arch + _check_arch() - -- check cross toolchain - _check_cross_toolchain() + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/cross/load.lua b/xmake/platforms/cross/load.lua deleted file mode 100644 index 2bc56f971..000000000 --- a/xmake/platforms/cross/load.lua +++ /dev/null @@ -1,46 +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 linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- add bin search library for loading some dependent .dll files windows - local bindir = config.get("bin") - if bindir and is_host("windows") then - os.addenv("PATH", bindir) - end -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index a76dde03c..e46f2fb06 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -33,7 +33,7 @@ platform("cross") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross") diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua new file mode 100644 index 000000000..6a5bd874d --- /dev/null +++ b/xmake/toolchains/cross/check.lua @@ -0,0 +1,41 @@ +--!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.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}cross toolchain not found, please run:") + cprint(" - xmake config --sdk=xxx") + cprint("or - xmake global --sdk=xxx") + raise() + end + return cross_toolchain +end diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua new file mode 100644 index 000000000..78be10f98 --- /dev/null +++ b/xmake/toolchains/cross/xmake.lua @@ -0,0 +1,66 @@ +--!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("cross") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- imports + import("core.project.config") + + -- get cross prefix + local cross = config.get("cross") or "" + + -- set toolsets + toolchain:set("toolsets", "cc", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "cxx", cross .. "gcc", cross .. "clang", cross .. "g++", cross .. "clang++") + toolchain:set("toolsets", "cpp", cross .. "gcc -E", cross .. "clang -E") + toolchain:set("toolsets", "as", cross .. "gcc", cross .. "clang") + toolchain:set("toolsets", "ld", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "sh", cross .. "g++", cross .. "gcc", cross .. "clang++", cross .. "clang") + toolchain:set("toolsets", "ar", cross .. "ar") + toolchain:set("toolsets", "ex", cross .. "ar") + toolchain:set("toolsets", "ranlib", cross .. "ranlib") + toolchain:set("toolsets", "strip", cross .. "strip") + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) diff --git a/xmake/toolchains/envs/xmake.lua b/xmake/toolchains/envs/xmake.lua index 899802b8e..f5dda488b 100644 --- a/xmake/toolchains/envs/xmake.lua +++ b/xmake/toolchains/envs/xmake.lua @@ -24,8 +24,8 @@ toolchain("envs") -- set toolsets set_toolsets("cc", "$(env CC)") set_toolsets("cxx", "$(env CXX)") - set_toolsets("ld", "$(env LD)") - set_toolsets("sh", "$(env SH)") + set_toolsets("ld", "$(env LD)", "$(env CXX)") + set_toolsets("sh", "$(env SH)", "$(env LD)", "$(env CXX)") set_toolsets("ar", "$(env AR)") set_toolsets("ex", "$(env EX)", "$(env AR)") set_toolsets("strip", "$(env STRIP)") diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua new file mode 100644 index 000000000..6a5bd874d --- /dev/null +++ b/xmake/toolchains/llvm/check.lua @@ -0,0 +1,41 @@ +--!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.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + + -- find cross toolchain + local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + -- failed + cprint("${bright color.error}cross toolchain not found, please run:") + cprint(" - xmake config --sdk=xxx") + cprint("or - xmake global --sdk=xxx") + raise() + end + return cross_toolchain +end diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua new file mode 100644 index 000000000..d04234809 --- /dev/null +++ b/xmake/toolchains/llvm/xmake.lua @@ -0,0 +1,60 @@ +--!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("llvm") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- set toolsets + toolchain:set("toolsets", "cc", "clang") + toolchain:set("toolsets", "cxx", "clang", "clang++") + toolchain:set("toolsets", "cpp", "clang -E") + toolchain:set("toolsets", "as", "clang") + toolchain:set("toolsets", "ld", "clang++", "clang") + toolchain:set("toolsets", "sh", "clang++", "clang") + toolchain:set("toolsets", "ar", "llvm-ar") + toolchain:set("toolsets", "ex", "llvm-ar") + toolchain:set("toolsets", "ranlib", "llvm-ranlib") + toolchain:set("toolsets", "strip", "llvm-strip") + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add bin search library for loading some dependent .dll files windows + local bindir = toolchain:bindir() + if bindir and is_host("windows") then + os.addenv("PATH", bindir) + end + end) -- cgit v1.3.1 From 1c7e32dea671abf42fc097db7141bd52a1fbfb19 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:36:09 +0800 Subject: improve linux platform --- xmake/platforms/linux/check.lua | 155 +++------------------------------------ xmake/platforms/linux/load.lua | 81 -------------------- xmake/platforms/linux/xmake.lua | 4 +- xmake/toolchains/clang/xmake.lua | 30 ++++++++ xmake/toolchains/gcc/xmake.lua | 30 ++++++++ xmake/toolchains/go/xmake.lua | 5 ++ xmake/toolchains/rust/xmake.lua | 6 ++ 7 files changed, 83 insertions(+), 228 deletions(-) delete mode 100644 xmake/platforms/linux/load.lua diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index 0fee59e6d..c435b7ad9 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -20,156 +20,21 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - 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, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end -- check it -function main(platform, name) +function main(platform) - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, os.arch()) - -- check arch - _check_arch() + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/linux/load.lua b/xmake/platforms/linux/load.lua deleted file mode 100644 index fcbbc61ff..000000000 --- a/xmake/platforms/linux/load.lua +++ /dev/null @@ -1,81 +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) - - -- cross toolchains? - if config.get("cross") or config.get("bin") or config.get("sdk") then - - -- init linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- ok - return - end - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - end - end - - -- init flags for c/c++ - platform:add("cxflags", archflags, "-I/usr/local/include", "-I/usr/include") - platform:add("ldflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - platform:add("shflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", archflags) - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "elf64" or "elf32") - platform:add("asflags", archflags) - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "") - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 21e4d2e51..250441a68 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -39,8 +39,8 @@ platform("linux") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") -- set menu set_menu { diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index d4c1c3798..5d495fff5 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -37,3 +37,33 @@ toolchain("clang") on_check(function (toolchain) return import("lib.detect.find_tool")("clang") end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index 08bb2d062..ba1ef6989 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -37,3 +37,33 @@ toolchain("gcc") on_check(function (toolchain) return import("lib.detect.find_tool")("gcc") end) + + -- on load + on_load(function (toolchain) + + -- get march + local march = is_arch("x86_64", "x64") and "-m64" or "-m32" + + -- init flags for c/c++ + toolchain:add("cxflags", march) + toolchain:add("ldflags", march) + toolchain:add("shflags", march) + if not is_plat("windows") and os.isdir("/usr") then + for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + end + for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + end + + -- init flags for objc/c++ (with ldflags and shflags) + toolchain:add("mxflags", march) + + -- init flags for asm + toolchain:add("asflags", march) + end) diff --git a/xmake/toolchains/go/xmake.lua b/xmake/toolchains/go/xmake.lua index a5400302b..402e5cc04 100644 --- a/xmake/toolchains/go/xmake.lua +++ b/xmake/toolchains/go/xmake.lua @@ -26,3 +26,8 @@ toolchain("go") set_toolsets("gcld", "$(env GC)", "go", "gccgo") set_toolsets("gcar", "$(env GC)", "go", "gccgo") + -- on load + on_load(function (toolchain) + toolchain:set("gcldflags", "") + end) + diff --git a/xmake/toolchains/rust/xmake.lua b/xmake/toolchains/rust/xmake.lua index 6eba85440..43684a5bb 100644 --- a/xmake/toolchains/rust/xmake.lua +++ b/xmake/toolchains/rust/xmake.lua @@ -26,3 +26,9 @@ toolchain("rust") set_toolsets("rcld", "$(env RC)", "rustc") set_toolsets("rcsh", "$(env RC)", "rustc") set_toolsets("rcar", "$(env RC)", "rustc") + + -- on load + on_load(function (toolchain) + toolchain:set("rcshflags", "") + toolchain:set("rcldflags", "") + end) -- cgit v1.3.1 From f518249b35a6eda0f73bb82ec346c2ddfa77fc64 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 00:36:29 +0800 Subject: improve bsd platform --- xmake/platforms/bsd/check.lua | 155 +++--------------------------------------- xmake/platforms/bsd/load.lua | 81 ---------------------- xmake/platforms/bsd/xmake.lua | 4 +- 3 files changed, 12 insertions(+), 228 deletions(-) delete mode 100644 xmake/platforms/bsd/load.lua diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 2422f3eb7..c435b7ad9 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -20,156 +20,21 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.arch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 strip = toolchain("the symbols stripper") - local mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, strip = strip, - mm = mm, mxx = mxx, - 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, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - cxx:add({name = "g++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the symbols stripper - strip:add("$(env STRIP)", {name = "strip", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - return toolchains -end -- check it -function main(platform, name) +function main(platform) - -- only check the given config name? - if name then - local toolchain = singleton.get("linux.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else + -- check arch + check_arch(config, os.arch()) - -- check arch - _check_arch() + -- check toolchains + local toolchains = platform:toolchains() + for idx, toolchain in irpairs(toolchains) do + if not toolchain:check() then + table.remove(toolchains, idx) + end end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/bsd/load.lua b/xmake/platforms/bsd/load.lua deleted file mode 100644 index fcbbc61ff..000000000 --- a/xmake/platforms/bsd/load.lua +++ /dev/null @@ -1,81 +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) - - -- cross toolchains? - if config.get("cross") or config.get("bin") or config.get("sdk") then - - -- init linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- ok - return - end - - -- init flags for architecture - local archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - end - end - - -- init flags for c/c++ - platform:add("cxflags", archflags, "-I/usr/local/include", "-I/usr/include") - platform:add("ldflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - platform:add("shflags", archflags, "-L/usr/local/lib", "-L/usr/lib") - - -- init flags for objc/c++ (with ldflags and shflags) - platform:add("mxflags", archflags) - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "elf64" or "elf32") - platform:add("asflags", archflags) - - -- init flags for golang - platform:set("gcldflags", "") - - -- init flags for dlang - local dc_archs = { i386 = "-m32", x86_64 = "-m64" } - platform:add("dcflags", dc_archs[arch] or "") - platform:add("dcshflags", dc_archs[arch] or "") - platform:add("dcldflags", dc_archs[arch] or "") - - -- init flags for rust - platform:set("rcshflags", "") - platform:set("rcldflags", "") -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index d0cacd28a..e829d0514 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -39,8 +39,8 @@ platform("bsd") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") -- set menu set_menu { -- cgit v1.3.1 From 5627a51d82327a2d694be53d1587e6a10671278c Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:36:58 +0800 Subject: improve linux/bsd platforms --- xmake/platforms/bsd/check.lua | 21 +++++++++++++++++++-- xmake/platforms/linux/check.lua | 21 +++++++++++++++++++-- xmake/platforms/linux/xmake.lua | 2 +- xmake/toolchains/cross/check.lua | 16 ++++++++++------ 4 files changed, 49 insertions(+), 11 deletions(-) diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index c435b7ad9..3cd6b8980 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -22,6 +22,12 @@ import("core.project.config") import("private.platform.check_arch") +-- is basic toolchain? +function _is_basic_toolchain(toolchain) + local name = toolchain:name() + return name == "clang" or name == "gcc" +end + -- check it function main(platform) @@ -30,9 +36,20 @@ function main(platform) -- check toolchains local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then + local idx = 1 + local num = #toolchains + local has_basic = false + while idx <= num do + local toolchain = toolchains[idx] + -- we need remove other same basic toolchains if basic toolchain found + if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then table.remove(toolchains, idx) + num = num - 1 + else + if _is_basic_toolchain(toolchain) then + has_basic = true + end + idx = idx + 1 end end assert(#toolchains > 0, "toolchains not found!") diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index c435b7ad9..a851256e5 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -22,6 +22,12 @@ import("core.project.config") import("private.platform.check_arch") +-- is basic toolchain? +function _is_basic_toolchain(toolchain) + local name = toolchain:name() + return name == "cross" or name == "clang" or name == "gcc" +end + -- check it function main(platform) @@ -30,9 +36,20 @@ function main(platform) -- check toolchains local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then + local idx = 1 + local num = #toolchains + local has_basic = false + while idx <= num do + local toolchain = toolchains[idx] + -- we need remove other same basic toolchains if basic toolchain found + if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then table.remove(toolchains, idx) + num = num - 1 + else + if _is_basic_toolchain(toolchain) then + has_basic = true + end + idx = idx + 1 end end assert(#toolchains > 0, "toolchains not found!") diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 250441a68..0b13c1a5b 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -40,7 +40,7 @@ platform("linux") on_check("check") -- set toolchains - set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") + set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") -- set menu set_menu { diff --git a/xmake/toolchains/cross/check.lua b/xmake/toolchains/cross/check.lua index 6a5bd874d..34b62ccc0 100644 --- a/xmake/toolchains/cross/check.lua +++ b/xmake/toolchains/cross/check.lua @@ -25,17 +25,21 @@ import("detect.sdks.find_cross_toolchain") -- check the cross toolchain function main(toolchain) + -- is cross? + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + local cross = config.get("cross") + if not sdkdir and not bindir and not cross then + return + end + -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir, cross = cross}) if cross_toolchain then config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) else - -- failed - cprint("${bright color.error}cross toolchain not found, please run:") - cprint(" - xmake config --sdk=xxx") - cprint("or - xmake global --sdk=xxx") - raise() + raise("cross toolchain not found!") end return cross_toolchain end -- cgit v1.3.1 From a5a4b0ac5b9674ac00049cc1f4ff8f11d5268f6b Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:44:16 +0800 Subject: set standalone toolchain --- tests/projects/asm/nasm/src/main.S | 1 - xmake/actions/config/xmake.lua | 2 +- xmake/core/platform/platform.lua | 25 +++++++++++++++++-------- xmake/core/tool/toolchain.lua | 13 ++++++++++++- xmake/modules/detect/tools/find_fasm.lua | 1 + xmake/modules/detect/tools/find_nasm.lua | 1 + xmake/platforms/bsd/check.lua | 16 +++++----------- xmake/platforms/linux/check.lua | 16 +++++----------- xmake/platforms/macosx/check.lua | 16 +++++----------- xmake/toolchains/clang/xmake.lua | 3 +++ xmake/toolchains/cross/xmake.lua | 3 +++ xmake/toolchains/gcc/xmake.lua | 3 +++ xmake/toolchains/llvm/xmake.lua | 3 +++ xmake/toolchains/xcode/xmake.lua | 3 +++ 14 files changed, 62 insertions(+), 44 deletions(-) diff --git a/tests/projects/asm/nasm/src/main.S b/tests/projects/asm/nasm/src/main.S index 5b3a93699..e96a8d2c9 100644 --- a/tests/projects/asm/nasm/src/main.S +++ b/tests/projects/asm/nasm/src/main.S @@ -1,6 +1,5 @@ global _main - section .text _main: diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 4953fc718..3b02846d1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -156,7 +156,7 @@ task("config") , " - sdk/bin" , " - sdk/lib" , " - sdk/include" } - , {nil, "toolchain", "kv", nil, "The Cross Toolchain Name" + , {nil, "toolchain", "kv", nil, "The Toolchain Name" , "e.g." , " - llvm" } diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 1ca688636..328bcce75 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -107,19 +107,28 @@ end function _instance:toolchains() local toolchains = self._TOOLCHAINS if not toolchains then - local names = {} - if config.get("toolchain") then - table.insert(names, config.get("toolchain")) - elseif self._INFO:get("toolchains") then - table.join2(names, self._INFO:get("toolchains")) - end + + -- get the given toolchain toolchains = {} - for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, self:name()) + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) if not toolchain_inst then os.raise(errors) end table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst + end + + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + for _, name in ipairs(self._INFO:get("toolchains")) do + local toolchain_inst, errors = toolchain.load(name, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + end end self._TOOLCHAINS = toolchains end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 78da9ea7f..f5d6ada4f 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -77,6 +77,16 @@ function _instance:get(name) return self._INFO:get(name) end +-- get toolchain kind +function _instance:kind() + return self._INFO:get("kind") +end + +-- is standalone toolchain? +function _instance:standalone() + return self:kind() == "standalone" +end + -- get the program and name of the given tool kind function _instance:tool(toolkind) local toolpathes = self:get("toolsets." .. toolkind) @@ -271,7 +281,8 @@ function toolchain._apis() { values = { - "toolchain.set_bindir" + "toolchain.set_kind" + , "toolchain.set_bindir" , "toolchain.set_sdkdir" } , keyvalues = diff --git a/xmake/modules/detect/tools/find_fasm.lua b/xmake/modules/detect/tools/find_fasm.lua index 5ebf9e699..0b555a406 100644 --- a/xmake/modules/detect/tools/find_fasm.lua +++ b/xmake/modules/detect/tools/find_fasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.norun = true -- find program local program = find_program(opt.program or "fasm", opt) diff --git a/xmake/modules/detect/tools/find_nasm.lua b/xmake/modules/detect/tools/find_nasm.lua index 40b710d2e..68936502e 100644 --- a/xmake/modules/detect/tools/find_nasm.lua +++ b/xmake/modules/detect/tools/find_nasm.lua @@ -39,6 +39,7 @@ function main(opt) -- init options opt = opt or {} + opt.check = "-v" -- find program local program = find_program(opt.program or "nasm", opt) diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 3cd6b8980..71d2e555c 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- 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 _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index a851256e5..71d2e555c 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "cross" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- 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 _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua index 08e04d7d6..b4eb3b73b 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -22,12 +22,6 @@ import("core.project.config") import("private.platform.check_arch") --- is basic toolchain? -function _is_basic_toolchain(toolchain) - local name = toolchain:name() - return name == "xcode" or name == "clang" or name == "gcc" -end - -- check it function main(platform) @@ -38,16 +32,16 @@ function main(platform) local toolchains = platform:toolchains() local idx = 1 local num = #toolchains - local has_basic = false + local standalone = false while idx <= num do local toolchain = toolchains[idx] - -- we need remove other same basic toolchains if basic toolchain found - if (has_basic and _is_basic_toolchain(toolchain)) or not toolchain:check() then + -- 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 _is_basic_toolchain(toolchain) then - has_basic = true + if toolchain:standalone() then + standalone = true end idx = idx + 1 end diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index 5d495fff5..ca84a94be 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("clang") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "clang") diff --git a/xmake/toolchains/cross/xmake.lua b/xmake/toolchains/cross/xmake.lua index 78be10f98..1cf211646 100644 --- a/xmake/toolchains/cross/xmake.lua +++ b/xmake/toolchains/cross/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("cross") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index ba1ef6989..77f2ef228 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("gcc") + + -- mark as standalone toolchain + set_kind("standalone") -- set toolsets set_toolsets("cc", "gcc") diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index d04234809..4c6c4748b 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -20,6 +20,9 @@ -- define toolchain toolchain("llvm") + + -- mark as standalone toolchain + set_kind("standalone") -- check toolchain on_check("check") diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index aed4a44e9..74462908c 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -21,6 +21,9 @@ -- define toolchain toolchain("xcode") + -- mark as standalone toolchain + set_kind("standalone") + -- check toolchain on_check("check") -- cgit v1.3.1 From edfbe8654b25fa4ac5455f7dfc2c4a49de8dd121 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:44:51 +0800 Subject: support mingw for linux --- xmake/modules/detect/sdks/find_mingw.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/modules/detect/sdks/find_mingw.lua b/xmake/modules/detect/sdks/find_mingw.lua index 06723859c..6aa5e3f2a 100644 --- a/xmake/modules/detect/sdks/find_mingw.lua +++ b/xmake/modules/detect/sdks/find_mingw.lua @@ -33,6 +33,8 @@ function _find_mingwdir(sdkdir) if not sdkdir then if is_host("macosx") then sdkdir = "/usr/local/opt/mingw-w64" + elseif is_host("linux") then + sdkdir = "/usr" end end @@ -58,7 +60,7 @@ function _find_mingw(sdkdir, bindir, cross) end -- select cross on macos, e.g x86_64-w64-mingw32- or i686-w64-mingw32- - if is_host("macosx") and not cross then + if is_host("macosx", "linux") and not cross then local arch = config.get("arch") if not arch or arch == "i386" then cross = "i686-*-" -- cgit v1.3.1 From 59caa4b16d0f8ab122338d7dfbcd461cc6017324 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:46:16 +0800 Subject: improve llvm toolchain on linux --- xmake/toolchains/llvm/check.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua index 6a5bd874d..04d4d6dec 100644 --- a/xmake/toolchains/llvm/check.lua +++ b/xmake/toolchains/llvm/check.lua @@ -25,17 +25,22 @@ import("detect.sdks.find_cross_toolchain") -- check the cross toolchain function main(toolchain) + -- get sdk directory + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + if not sdkdir and not bindir then + if is_plat("linux") and os.isfile("/usr/bin/llvm-ar") then + sdkdir = "/usr" + end + end + -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) if cross_toolchain then config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) else - -- failed - cprint("${bright color.error}cross toolchain not found, please run:") - cprint(" - xmake config --sdk=xxx") - cprint("or - xmake global --sdk=xxx") - raise() + raise("llvm toolchain not found!") end return cross_toolchain end -- cgit v1.3.1 From eff77a9a787016605baf133bc1a582ef8437a7fa Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 22:57:42 +0800 Subject: add vs toolchain --- xmake/platforms/windows/check.lua | 132 +++++++------------------------------- xmake/platforms/windows/load.lua | 38 ----------- xmake/platforms/windows/xmake.lua | 4 +- xmake/toolchains/vs/check.lua | 97 ++++++++++++++++++++++++++++ xmake/toolchains/vs/xmake.lua | 46 +++++++++++++ 5 files changed, 167 insertions(+), 150 deletions(-) delete mode 100644 xmake/platforms/windows/load.lua create mode 100644 xmake/toolchains/vs/check.lua create mode 100644 xmake/toolchains/vs/xmake.lua 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 - - -- 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) +function main(platform) + + -- check arch + check_arch(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) -- cgit v1.3.1 From addd29396de0952b78cc69c4510b7be0f7886c1f Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 23:17:55 +0800 Subject: improve envs --- xmake/core/platform/environment.lua | 92 +++++++++++--------------- xmake/core/platform/platform.lua | 20 +++++- xmake/core/tool/toolchain.lua | 25 ++----- xmake/platforms/windows/environment/enter.lua | 95 --------------------------- xmake/platforms/windows/environment/leave.lua | 44 ------------- xmake/platforms/windows/xmake.lua | 6 -- xmake/toolchains/vs/check.lua | 11 +++- xmake/toolchains/vs/load.lua | 90 +++++++++++++++++++++++++ xmake/toolchains/vs/xmake.lua | 17 +---- 9 files changed, 159 insertions(+), 241 deletions(-) delete mode 100644 xmake/platforms/windows/environment/enter.lua delete mode 100644 xmake/platforms/windows/environment/leave.lua create mode 100644 xmake/toolchains/vs/load.lua diff --git a/xmake/core/platform/environment.lua b/xmake/core/platform/environment.lua index acc383f19..f76568cb7 100644 --- a/xmake/core/platform/environment.lua +++ b/xmake/core/platform/environment.lua @@ -23,6 +23,7 @@ local environment = environment or {} -- load modules local os = require("base/os") +local table = require("base/table") local global = require("base/global") local platform_core = require("platform/platform") local sandbox = require("sandbox/sandbox") @@ -32,97 +33,80 @@ local import = require("sandbox/modules/import") -- enter the toolchains environment function environment._enter_toolchains() - -- save the toolchains environment - environment._PATH = os.getenv("PATH") + -- get the current platform + local platform, errors = platform_core.load() + if not platform then + return false, errors + end -- add $programdir/winenv/bin to $path + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") if os.host() == "windows" then os.addenv("PATH", path.join(os.programdir(), "winenv", "bin")) end + + -- add the runenvs of toolchains + for name, values in pairs(platform:runenvs()) do + if not oldenvs[name] then + oldenvs[name] = os.getenv(name) + end + os.addenv(name, table.unpack(table.wrap(values))) + end + environment._OLDENVS_TOOLCHAINS = oldenvs + return true end -- leave the toolchains environment function environment._leave_toolchains() - - -- leave the toolchains environment - os.setenv("PATH", environment._PATH) + local oldenvs = environment._OLDENVS_TOOLCHAINS + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end + return true end -- enter the running environment function environment._enter_run() - - -- save the running environment - environment._PATH = os.getenv("PATH") - environment._LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") + oldenvs.LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH") + environment._OLDENVS_RUN = oldenvs + return true end -- leave the running environment function environment._leave_run() - - -- leave the running environment - os.setenv("PATH", environment._PATH) - os.setenv("LD_LIBRARY_PATH", environment._LD_LIBRARY_PATH) + local oldenvs = environment._OLDENVS_RUN + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end + return true end -- enter the environment for the current platform function environment.enter(name) - - -- get the current platform - local platform, errors = platform_core.load() - if not platform then - return false, errors - end - - -- the maps local maps = {toolchains = environment._enter_toolchains, run = environment._enter_run} - - -- enter the common environment local func = maps[name] if func then - func() - end - - -- enter the environment of the given platform - local on_enter = platform:script("environment_enter") - if on_enter then - local ok, errors = sandbox.load(on_enter, platform, name) + local ok, errors = func() if not ok then return false, errors end end - - -- ok return true end -- leave the environment for the current platform function environment.leave(name) - - -- get the current platform - local platform, errors = platform_core.load() - if not platform then - return false, errors - end - - -- leave the environment of the given platform - local on_leave = platform:script("environment_leave") - if on_leave then - local ok, errors = sandbox.load(on_leave, platform, name) - if not ok then - return false, errors - end - end - - -- the maps local maps = {toolchains = environment._leave_toolchains, run = environment._leave_run} - - -- leave the common environment local func = maps[name] if func then - func() + local ok, errors = func() + if not ok then + return false, errors + end end - - -- ok return true end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 328bcce75..c20da127e 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -103,6 +103,24 @@ function _instance:archs() return self._INFO:get("archs") end +-- get runenvs of toolchains +function _instance:runenvs() + local runenvs = self._RUNENVS + if not runenvs then + runenvs = {} + for _, toolchain_inst in ipairs(self:toolchains()) do + local toolchain_runenvs = toolchain_inst:get("runenvs") + if toolchain_runenvs then + for name, values in pairs(toolchain_runenvs) do + runenvs[name] = table.join2(table.wrap(runenvs[name]), values) + end + end + end + self._RUNENVS = runenvs + end + return runenvs +end + -- get the toolchains function _instance:toolchains() local toolchains = self._TOOLCHAINS @@ -284,8 +302,6 @@ function platform._apis() -- platform.on_xxx "platform.on_load" , "platform.on_check" - , "platform.on_environment_enter" - , "platform.on_environment_leave" } , dictionary = { diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index f5d6ada4f..97fb512a1 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -68,10 +68,8 @@ function _instance:get(name) return value end - -- lazy loading platform if get other configuration - if not self:_is_builtin_conf(name) then - self:_load() - end + -- lazy loading platform + self:_load() -- get other platform info return self._INFO:get(name) @@ -233,23 +231,6 @@ function _instance:_checktool(toolkind, toolpath) return program, toolname end --- is builtin configuration? -function _instance:_is_builtin_conf(name) - - local builtin_configs = self._BUILTIN_CONFIGS - if not builtin_configs then - builtin_configs = {} - for apiname, _ in pairs(toolchain._interpreter():apis("toolchain")) do - local pos = apiname:find('_', 1, true) - if pos then - builtin_configs[apiname:sub(pos + 1)] = true - end - end - self._BUILTIN_CONFIGS = builtin_configs - end - return builtin_configs[name] -end - -- the interpreter function toolchain._interpreter() @@ -289,6 +270,8 @@ function toolchain._apis() { -- toolchain.set_xxx "toolchain.set_toolsets" + -- toolchain.add_xxx + , "toolchain.add_runenvs" } , script = { diff --git a/xmake/platforms/windows/environment/enter.lua b/xmake/platforms/windows/environment/enter.lua deleted file mode 100644 index 827898222..000000000 --- a/xmake/platforms/windows/environment/enter.lua +++ /dev/null @@ -1,95 +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 enter.lua --- - --- imports -import("core.project.config") -import("core.base.global") -import("detect.sdks.find_vstudio") - --- enter the given environment -function _enter(platform, name) - - -- get vcvarsall - local vcvarsall = config.get("__vcvarsall") or global.get("__vcvarsall") - if not vcvarsall then - return - end - - -- get arch - local arch = config.get("arch") or global.get("arch") or "" - - -- get vs environment for the current arch - local vsenv = vcvarsall[arch] or {} - - -- switch vstudio environment if vs_sdkver has been changed - local switch_vsenv = false - local vs = config.get("vs") - local vs_sdkver = config.get("vs_sdkver") - if vs and vs_sdkver and vsenv.WindowsSDKVersion and vs_sdkver ~= vsenv.WindowsSDKVersion then - switch_vsenv = true - end - if switch_vsenv then - -- find vstudio - local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = vs_sdkver}) - if vstudio then - vcvarsall = (vstudio[vs] or {}).vcvarsall or {} - vsenv = vcvarsall[arch] or {} - if vsenv and vsenv.path and vsenv.include and vsenv.lib then - config.set("__vcvarsall", vcvarsall) - end - end - end - - -- get the pathes for the vs environment - local old = nil - local new = vsenv[name] - if new then - - -- get the current pathes - old = os.getenv(name) or "" - - -- append the current pathes - new = new .. ";" .. old - - -- update the pathes for the environment - os.setenv(name, new) - end - - -- save the previous environment - platform:data_set("windows.environment." .. name, old) -end - --- enter the toolchains environment -function _enter_toolchains(platform) - _enter(platform, "path") - _enter(platform, "lib") - _enter(platform, "include") - _enter(platform, "libpath") -end - --- enter environment -function main(platform, name) - local maps = {toolchains = _enter_toolchains} - local func = maps[name] - if func then - func(platform) - end -end - diff --git a/xmake/platforms/windows/environment/leave.lua b/xmake/platforms/windows/environment/leave.lua deleted file mode 100644 index 8547cfd66..000000000 --- a/xmake/platforms/windows/environment/leave.lua +++ /dev/null @@ -1,44 +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 leave.lua --- - --- leave the given environment -function _leave(platform, name) - local old = platform:data("windows.environment." .. name) - if old then - os.setenv(name, old) - end -end - --- leave the toolchains environment -function _leave_toolchains(platform) - _leave(platform, "path") - _leave(platform, "lib") - _leave(platform, "include") - _leave(platform, "libpath") -end - --- leave environment -function main(platform, name) - local maps = {toolchains = _leave_toolchains} - local func = maps[name] - if func then - func(platform) - end -end diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index dd0c37679..dd4e4da6f 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -36,12 +36,6 @@ platform("windows") -- on check on_check("check") - -- on environment enter - on_environment_enter("environment.enter") - - -- on environment leave - on_environment_leave("environment.leave") - -- set toolchains set_toolchains("vs", "yasm", "nasm", "cuda", "dlang", "rust", "go") diff --git a/xmake/toolchains/vs/check.lua b/xmake/toolchains/vs/check.lua index 1e9a97d48..57220f73b 100644 --- a/xmake/toolchains/vs/check.lua +++ b/xmake/toolchains/vs/check.lua @@ -23,7 +23,6 @@ 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() @@ -60,13 +59,19 @@ function _check_vsenv() config.set("__vcvarsall", vcvarsall) -- check compiler - environment.enter("toolchains") + local oldenvs = {} + oldenvs.PATH = os.getenv("PATH") + oldenvs.LIB = os.getenv("LIB") + os.setenv("PATH", vsenv.path .. ';' .. (oldenvs.PATH or "")) + os.setenv("LIB", vsenv.lib .. ';' .. (oldenvs.LIB or "")) local program = nil local tool = find_tool("cl.exe", {force = true}) if tool then program = tool.program end - environment.leave("toolchains") + for name, values in pairs(oldenvs) do + os.setenv(name, values) + end -- ok? if program then diff --git a/xmake/toolchains/vs/load.lua b/xmake/toolchains/vs/load.lua new file mode 100644 index 000000000..855869a0b --- /dev/null +++ b/xmake/toolchains/vs/load.lua @@ -0,0 +1,90 @@ +--!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 load.lua +-- + +-- imports +import("core.base.option") +import("core.project.config") +import("detect.sdks.find_vstudio") + +-- add the given vs environment +function _add_vsenv(toolchain, name) + + -- get vcvarsall + local vcvarsall = config.get("__vcvarsall") + if not vcvarsall then + return + end + + -- get arch + local arch = config.get("arch") or "" + + -- get vs environment for the current arch + local vsenv = vcvarsall[arch] or {} + + -- switch vstudio environment if vs_sdkver has been changed + local switch_vsenv = false + local vs = config.get("vs") + local vs_sdkver = config.get("vs_sdkver") + if vs and vs_sdkver and vsenv.WindowsSDKVersion and vs_sdkver ~= vsenv.WindowsSDKVersion then + switch_vsenv = true + end + if switch_vsenv then + -- find vstudio + local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = vs_sdkver}) + if vstudio then + vcvarsall = (vstudio[vs] or {}).vcvarsall or {} + vsenv = vcvarsall[arch] or {} + if vsenv and vsenv.path and vsenv.include and vsenv.lib then + config.set("__vcvarsall", vcvarsall) + end + end + end + + -- get the pathes for the vs environment + local new = vsenv[name] + if new then + toolchain:add("runenvs", name:upper(), path.splitenv(new)) + end +end + +-- main entry +function main(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") + + -- add vs environments + _add_vsenv(toolchain, "path") + _add_vsenv(toolchain, "lib") + _add_vsenv(toolchain, "include") + _add_vsenv(toolchain, "libpath") +end + diff --git a/xmake/toolchains/vs/xmake.lua b/xmake/toolchains/vs/xmake.lua index a2b1c71db..cc717de9f 100644 --- a/xmake/toolchains/vs/xmake.lua +++ b/xmake/toolchains/vs/xmake.lua @@ -28,19 +28,4 @@ toolchain("vs") 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) + on_load("load") -- cgit v1.3.1 From 6a2e838a6fb0a5cb957766aa2f11f94f65f73f43 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 23:47:07 +0800 Subject: improve msys platform --- xmake/platforms/msys/check.lua | 165 ++++++----------------------------------- xmake/platforms/msys/load.lua | 46 ------------ xmake/platforms/msys/xmake.lua | 4 +- 3 files changed, 24 insertions(+), 191 deletions(-) delete mode 100644 xmake/platforms/msys/load.lua diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua index 927e51e5d..8cd3cfbe0 100644 --- a/xmake/platforms/msys/check.lua +++ b/xmake/platforms/msys/check.lua @@ -20,153 +20,32 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - 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, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("msys.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) +function main(platform) + + -- check arch + check_arch(config, config.get("cross") and "none" or os.subarch()) + + -- 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 - else - - -- check arch - _check_arch() end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/msys/load.lua b/xmake/platforms/msys/load.lua deleted file mode 100644 index c101640b5..000000000 --- a/xmake/platforms/msys/load.lua +++ /dev/null @@ -1,46 +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 archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) - end - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") -end - diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index 69c56db22..2a171e83b 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -39,6 +39,6 @@ platform("msys") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross", "gcc", "clang", "yasm") -- cgit v1.3.1 From c6d413d07d771ed199b1b4d747625a6a7059fdca Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 23:49:37 +0800 Subject: fix load toolchain --- xmake/core/tool/toolchain.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 97fb512a1..368a25b20 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -115,10 +115,12 @@ end -- do load function _instance:_load() - if not self._LOADED then + if not self._LOADED and not self._LOADING then local on_load = self._INFO:get("load") if on_load then + self._LOADING = true local ok, errors = sandbox.load(on_load, self) + self._LOADING = false if not ok then os.raise(errors) end -- cgit v1.3.1 From a896b35be6d07660cf65c1885a41edd568e5fdf0 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 23:50:04 +0800 Subject: improve cygwin platform --- xmake/platforms/cygwin/check.lua | 165 ++++++--------------------------------- xmake/platforms/cygwin/load.lua | 46 ----------- xmake/platforms/cygwin/xmake.lua | 4 +- 3 files changed, 24 insertions(+), 191 deletions(-) delete mode 100644 xmake/platforms/cygwin/load.lua diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua index 22d8809ad..8cd3cfbe0 100644 --- a/xmake/platforms/cygwin/check.lua +++ b/xmake/platforms/cygwin/check.lua @@ -20,153 +20,32 @@ -- imports import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", config.get("cross") and "none" or os.subarch()) - - -- trace - print("checking for the architecture ... %s", config.get("arch")) - end -end - --- get toolchains -function _toolchains() - - -- find cross toolchain - local cross = "" - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - cross = cross_toolchain.cross - end - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ 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 mm = toolchain("the objc compiler") - local mxx = toolchain("the objc++ compiler") - 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 cu_ccbin = toolchain("the cuda host c++ compiler") - local toolchains = {cc = cc, cxx = cxx, as = as, ld = ld, sh = sh, ar = ar, ex = ex, - mm = mm, mxx = mxx, - 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, ["cu-ccbin"] = cu_ccbin} - - -- init the c compiler - cc:add("$(env CC)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the c++ compiler - cxx:add("$(env CXX)") - cxx:add({name = "gcc", cross = cross}) - cxx:add({name = "clang", cross = cross}) - cxx:add({name = "g++", cross = cross}) - cxx:add({name = "clang++", cross = cross}) - - -- init the assember - as:add("$(env AS)", {name = "gcc", cross = cross}, {name = "clang", cross = cross}) - - -- init the linker - ld:add("$(env LD)", "$(env CXX)") - ld:add({name = "g++", cross = cross}) - ld:add({name = "gcc", cross = cross}) - ld:add({name = "clang++", cross = cross}) - ld:add({name = "clang", cross = cross}) - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)") - sh:add({name = "g++", cross = cross}) - sh:add({name = "gcc", cross = cross}) - sh:add({name = "clang++", cross = cross}) - sh:add({name = "clang", cross = cross}) - - -- init the static library archiver - ar:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the static library extractor - ex:add("$(env AR)", {name = "ar", cross = cross}) - - -- init the objc compiler - mm:add("$(env MM)", {name = "clang", cross = cross}, {name = "gcc", cross = cross}) - - -- init the objc++ compiler - mxx:add("$(env MXX)") - mxx:add({name = "clang", cross = cross}) - mxx:add({name = "clang++", cross = cross}) - mxx:add({name = "gcc", cross = cross}) - mxx:add({name = "g++", cross = cross}) - - -- 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++", "clang") - cu_ld:add("nvcc") - if not cross or cross == "" then - cu_ccbin:add("$(env CXX)", "$(env CC)", "gcc", "clang", "g++", "clang++") - end - - return toolchains -end -- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cygwin.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) +function main(platform) + + -- check arch + check_arch(config, config.get("cross") and "none" or os.subarch()) + + -- 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 - else - - -- check arch - _check_arch() end + assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/cygwin/load.lua b/xmake/platforms/cygwin/load.lua deleted file mode 100644 index c101640b5..000000000 --- a/xmake/platforms/cygwin/load.lua +++ /dev/null @@ -1,46 +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 archflags = nil - local arch = config.get("arch") - if arch then - if arch == "x86_64" then archflags = "-m64" - elseif arch == "i386" then archflags = "-m32" - else archflags = "-arch " .. arch - end - end - if archflags then - platform:add("cxflags", archflags) - platform:add("asflags", archflags) - platform:add("ldflags", archflags) - platform:add("shflags", archflags) - end - - -- init flags for asm - platform:add("yasm.asflags", "-f", arch == "x86_64" and "win64" or "win32") -end - diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index 32ab7df58..14b608732 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -39,6 +39,6 @@ platform("cygwin") -- on check on_check("check") - -- on load - on_load("load") + -- set toolchains + set_toolchains("envs", "cross", "gcc", "clang", "yasm") -- cgit v1.3.1 From 13373f2c9b1a80a8c766006a73f28e6adf83b929 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 20 May 2020 23:54:42 +0800 Subject: improve to check vs --- xmake/platforms/windows/xmake.lua | 2 +- xmake/toolchains/vs/check.lua | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index dd4e4da6f..19ee3bb7a 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -37,7 +37,7 @@ platform("windows") on_check("check") -- set toolchains - set_toolchains("vs", "yasm", "nasm", "cuda", "dlang", "rust", "go") + set_toolchains("vs", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- set menu set_menu { diff --git a/xmake/toolchains/vs/check.lua b/xmake/toolchains/vs/check.lua index 57220f73b..12fac2aa0 100644 --- a/xmake/toolchains/vs/check.lua +++ b/xmake/toolchains/vs/check.lua @@ -83,7 +83,7 @@ function _check_vsenv() end -- check the visual studio -function main() +function _check_vstudio() local vs = _check_vsenv() if vs then config.set("vs", vs, {readonly = true, force = true}) @@ -100,3 +100,14 @@ function main() return vs end +-- main entry +function main() + -- @see https://github.com/xmake-io/xmake/pull/679 + 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 + return _check_vstudio(config) + end +end + -- cgit v1.3.1 From 7053cde611448bba096b6a97527af5f5a50439c1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 00:43:47 +0800 Subject: add sdcc toolchain --- xmake/toolchains/llvm/xmake.lua | 24 ++++++++-------- xmake/toolchains/sdcc/check.lua | 37 ++++++++++++++++++++++++ xmake/toolchains/sdcc/xmake.lua | 62 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+), 12 deletions(-) create mode 100644 xmake/toolchains/sdcc/check.lua create mode 100644 xmake/toolchains/sdcc/xmake.lua diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua index 4c6c4748b..53132de83 100644 --- a/xmake/toolchains/llvm/xmake.lua +++ b/xmake/toolchains/llvm/xmake.lua @@ -23,6 +23,18 @@ toolchain("llvm") -- mark as standalone toolchain set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "clang") + set_toolsets("cxx", "clang", "clang++") + set_toolsets("cpp", "clang -E") + set_toolsets("as", "clang") + set_toolsets("ld", "clang++", "clang") + set_toolsets("sh", "clang++", "clang") + set_toolsets("ar", "llvm-ar") + set_toolsets("ex", "llvm-ar") + set_toolsets("ranlib", "llvm-ranlib") + set_toolsets("strip", "llvm-strip") -- check toolchain on_check("check") @@ -30,18 +42,6 @@ toolchain("llvm") -- on load on_load(function (toolchain) - -- set toolsets - toolchain:set("toolsets", "cc", "clang") - toolchain:set("toolsets", "cxx", "clang", "clang++") - toolchain:set("toolsets", "cpp", "clang -E") - toolchain:set("toolsets", "as", "clang") - toolchain:set("toolsets", "ld", "clang++", "clang") - toolchain:set("toolsets", "sh", "clang++", "clang") - toolchain:set("toolsets", "ar", "llvm-ar") - toolchain:set("toolsets", "ex", "llvm-ar") - toolchain:set("toolsets", "ranlib", "llvm-ranlib") - toolchain:set("toolsets", "strip", "llvm-strip") - -- init linkdirs and includedirs local sdkdir = toolchain:sdkdir() if sdkdir then diff --git a/xmake/toolchains/sdcc/check.lua b/xmake/toolchains/sdcc/check.lua new file mode 100644 index 000000000..a55f99a76 --- /dev/null +++ b/xmake/toolchains/sdcc/check.lua @@ -0,0 +1,37 @@ +--!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.project.config") +import("detect.sdks.find_cross_toolchain") + +-- check the cross toolchain +function main(toolchain) + local sdkdir = config.get("sdk") + local bindir = config.get("bin") + local cross_toolchain = find_cross_toolchain(sdkdir, {bindir = bindir}) + if cross_toolchain then + config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) + config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) + else + raise("sdcc toolchain not found!") + end + return cross_toolchain +end diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua new file mode 100644 index 000000000..c7f305e61 --- /dev/null +++ b/xmake/toolchains/sdcc/xmake.lua @@ -0,0 +1,62 @@ +--!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("sdcc") + + -- mark as standalone toolchain + set_kind("standalone") + + -- set toolsets + set_toolsets("cc", "sdcc") + set_toolsets("cxx", "sdcc") + set_toolsets("cpp", "sdcpp") + set_toolsets("as", "sdcc") + set_toolsets("ld", "sdcc") + set_toolsets("sh", "sdcc") + set_toolsets("ar", "sdar") + set_toolsets("ex", "sdar") + + -- check toolchain + on_check("check") + + -- on load + on_load(function (toolchain) + + -- init linkdirs and includedirs + local sdkdir = toolchain:sdkdir() + if sdkdir then + local includedir = path.join(sdkdir, "include") + if os.isdir(includedir) then + toolchain:add("includedirs", includedir) + end + local linkdir = path.join(sdkdir, "lib") + if os.isdir(linkdir) then + toolchain:add("linkdirs", linkdir) + end + end + + -- add port flags for arch + local arch = get_config("arch") + if arch then + toolchain:add("cxflags", "-m" .. arch) + toolchain:add("ldflags", "-m" .. arch) + end + end) -- cgit v1.3.1 From f42509d5a1f4b98ef789bcd1a12cc436e3dc43b1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 22:36:26 +0800 Subject: remove sdcc platform --- xmake/core/platform/platform.lua | 26 ++++++++- xmake/core/tool/toolchain.lua | 1 + xmake/platforms/sdcc/check.lua | 114 --------------------------------------- xmake/platforms/sdcc/load.lua | 47 ---------------- xmake/platforms/sdcc/xmake.lua | 39 -------------- xmake/toolchains/sdcc/xmake.lua | 6 +++ 6 files changed, 32 insertions(+), 201 deletions(-) delete mode 100644 xmake/platforms/sdcc/check.lua delete mode 100644 xmake/platforms/sdcc/load.lua delete mode 100644 xmake/platforms/sdcc/xmake.lua diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index c20da127e..9b0e1ebec 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -245,6 +245,24 @@ function _instance:check() end end +-- get formats +function _instance:formats() + local formats = self._FORMATS + if not formats then + for _, toolchain_inst in ipairs(self:toolchains()) do + formats = toolchain_inst:get("formats") + if formats then + break + end + end + if not formats then + formats = self._INFO:get("formats") + end + self._FORMATS = formats + end + return formats +end + -- is builtin configuration? function _instance:_is_builtin_conf(name) @@ -510,8 +528,14 @@ end -- get the format of the given target kind for platform function platform.format(targetkind) + -- get platform instance + local instance, errors = platform.load(plat) + if not instance then + os.raise(errors) + end + -- get formats - local formats = platform.get("formats") + local formats = instance:formats() if formats then return formats[targetkind] end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 368a25b20..3644fa8c0 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -267,6 +267,7 @@ function toolchain._apis() "toolchain.set_kind" , "toolchain.set_bindir" , "toolchain.set_sdkdir" + , "toolchain.set_archs" } , keyvalues = { diff --git a/xmake/platforms/sdcc/check.lua b/xmake/platforms/sdcc/check.lua deleted file mode 100644 index 6532ea00e..000000000 --- a/xmake/platforms/sdcc/check.lua +++ /dev/null @@ -1,114 +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 check.lua --- - --- imports -import("core.project.config") -import("core.base.singleton") -import("detect.sdks.find_cross_toolchain") -import("private.platform.toolchain") -import("private.platform.check_arch") -import("private.platform.check_toolchain") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "stm8") - end -end - --- check the cross toolchain -function _check_cross_toolchain() - -- find cross toolchain - local cross_toolchain = find_cross_toolchain(config.get("sdk") or config.get("bin"), {bindir = config.get("bin"), cross = config.get("cross")}) - if cross_toolchain then - config.set("cross", cross_toolchain.cross, {readonly = true, force = true}) - config.set("bin", cross_toolchain.bindir, {readonly = true, force = true}) - - -- TODO add to environment module - -- add bin search library for loading some dependent .dll files windows - if cross_toolchain.bindir and is_host("windows") then - os.addenv("PATH", cross_toolchain.bindir) - end - end -end - --- get toolchains -function _toolchains() - - -- init toolchains - local cc = toolchain("the c compiler") - local cxx = toolchain("the c++ compiler") - local cpp = toolchain("the c preprocessor") - 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 ranlib = toolchain("the static library index generator") - local as = toolchain("the assember") - local toolchains = {cc = cc, cxx = cxx, cpp = cpp, as = as, ld = ld, sh = sh, ar = ar, ex = ex, ranlib = ranlib} - - -- init the c compiler - cc:add("$(env CC)", "sdcc") - - -- init the c preprocessor - cpp:add("$(env CPP)", "sdcpp") - - -- init the c++ compiler - cxx:add("$(env CXX)", "sdcc") - - -- init the assember - as:add("$(env AS)", "sdcc") - - -- init the linker - ld:add("$(env LD)", "$(env CXX)", "sdcc") - - -- init the shared library linker - sh:add("$(env SH)", "$(env CXX)", "sdcc") - - -- init the static library archiver - ar:add("$(env AR)", "sdar") - - -- init the static library extractor - ex:add("$(env AR)", "sdar") - return toolchains -end - --- check it -function main(platform, name) - - -- only check the given config name? - if name then - local toolchain = singleton.get("cross.toolchains", _toolchains)[name] - if toolchain then - check_toolchain(config, name, toolchain) - end - else - - -- check arch - _check_arch() - - -- check cross toolchain - _check_cross_toolchain() - end -end - diff --git a/xmake/platforms/sdcc/load.lua b/xmake/platforms/sdcc/load.lua deleted file mode 100644 index 2f44d691e..000000000 --- a/xmake/platforms/sdcc/load.lua +++ /dev/null @@ -1,47 +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 linkdirs and includedirs - local sdkdir = config.get("sdk") - if sdkdir then - local includedir = path.join(sdkdir, "include") - if os.isdir(includedir) then - platform:add("includedirs", includedir) - end - local linkdir = path.join(sdkdir, "lib") - if os.isdir(linkdir) then - platform:add("linkdirs", linkdir) - end - end - - -- add port flags for arch - local arch = config.get("arch") - if arch then - platform:add("cxflags", "-m" .. arch) - platform:add("ldflags", "-m" .. arch) - end -end - diff --git a/xmake/platforms/sdcc/xmake.lua b/xmake/platforms/sdcc/xmake.lua deleted file mode 100644 index ad2f02be9..000000000 --- a/xmake/platforms/sdcc/xmake.lua +++ /dev/null @@ -1,39 +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 xmake.lua --- - --- define platform -platform("sdcc") - - -- set hosts - set_hosts("macosx", "linux", "windows") - - -- set archs - set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") - - -- set formats - set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} - - -- on check - on_check("check") - - -- on load - on_load("load") - - diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua index c7f305e61..84a8d93fc 100644 --- a/xmake/toolchains/sdcc/xmake.lua +++ b/xmake/toolchains/sdcc/xmake.lua @@ -33,6 +33,12 @@ toolchain("sdcc") set_toolsets("sh", "sdcc") set_toolsets("ar", "sdar") set_toolsets("ex", "sdar") + + -- set archs + set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") + + -- set formats + set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} -- check toolchain on_check("check") -- cgit v1.3.1 From 38b0a926dfdab29c5c1aaeb182bdba6bda5a2970 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 22:39:06 +0800 Subject: improve set_formats --- xmake/core/platform/platform.lua | 5 ++++- xmake/core/tool/toolchain.lua | 8 ++------ xmake/platforms/android/xmake.lua | 5 ++++- xmake/platforms/bsd/xmake.lua | 5 ++++- xmake/platforms/cross/xmake.lua | 5 ++++- xmake/platforms/cygwin/xmake.lua | 6 +++++- xmake/platforms/iphoneos/xmake.lua | 5 ++++- xmake/platforms/linux/xmake.lua | 5 ++++- xmake/platforms/macosx/xmake.lua | 5 ++++- xmake/platforms/mingw/xmake.lua | 6 +++++- xmake/platforms/msys/xmake.lua | 6 +++++- xmake/platforms/watchos/xmake.lua | 5 ++++- xmake/platforms/windows/xmake.lua | 6 +++++- xmake/toolchains/sdcc/xmake.lua | 5 ++++- 14 files changed, 58 insertions(+), 19 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 9b0e1ebec..3fc92be63 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -321,11 +321,14 @@ function platform._apis() "platform.on_load" , "platform.on_check" } + , keyvalues = + { + "platform.set_formats" + } , dictionary = { -- platform.set_xxx "platform.set_menu" - , "platform.set_formats" } } end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 3644fa8c0..894dfb879 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -272,7 +272,8 @@ function toolchain._apis() , keyvalues = { -- toolchain.set_xxx - "toolchain.set_toolsets" + "toolchain.set_formats" + , "toolchain.set_toolsets" -- toolchain.add_xxx , "toolchain.add_runenvs" } @@ -282,11 +283,6 @@ function toolchain._apis() "toolchain.on_load" , "toolchain.on_check" } - , dictionary = - { - -- toolchain.set_xxx - "toolchain.set_formats" - } } end diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 4644af7a4..48177245e 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -37,7 +37,10 @@ platform("android") set_archs("armeabi", "armeabi-v7a", "arm64-v8a", "x86", "x86_64", "mips", "mip64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- on check on_check("check") diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index e829d0514..7bc9c03b8 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -31,7 +31,10 @@ platform("bsd") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index e46f2fb06..4e6b2dcc2 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -28,7 +28,10 @@ platform("cross") set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- on check on_check("check") diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index 14b608732..c7f16f8d2 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -31,7 +31,11 @@ platform("cygwin") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dll", binary = "$(name).exe", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index d0d57f5da..bf7612c2c 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -31,7 +31,10 @@ platform("iphoneos") set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") -- on check on_check("check") diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 0b13c1a5b..62cc1e3e8 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -31,7 +31,10 @@ platform("linux") set_archs("i386", "x86_64", "armv7", "armv7s", "arm64-v8a", "mips", "mips64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).so", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).so") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 4537e419d..0dc0ece52 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -31,7 +31,10 @@ platform("macosx") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") -- set install directory set_installdir("/usr/local") diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 1c19443b8..6a29e39d5 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -31,7 +31,11 @@ platform("mingw") set_archs("i386", "x86_64") -- set formats - set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} + set_formats("static", "$(name).lib") + set_formats("object", "$(name).obj") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).pdb") -- on check on_check("check") diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index 2a171e83b..7fa199b76 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -31,7 +31,11 @@ platform("msys") set_archs("i386", "x86_64") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dll", binary = "$(name).exe", symbol = "$(name).sym"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).sym") -- set install directory set_installdir("/usr/local") diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 9215e2b96..8be929977 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -31,7 +31,10 @@ platform("watchos") set_archs("armv7k", "i386") -- set formats - set_formats {static = "lib$(name).a", object = "$(name).o", shared = "lib$(name).dylib", symbol = "$(name).dSYM"} + set_formats("static", "lib$(name).a") + set_formats("object", "$(name).o") + set_formats("shared", "lib$(name).dylib") + set_formats("symbol", "$(name).dSYM") -- on check on_check("check") diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 19ee3bb7a..f43d7179c 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -31,7 +31,11 @@ platform("windows") set_archs("x86", "x64") -- set formats - set_formats {static = "$(name).lib", object = "$(name).obj", shared = "$(name).dll", binary = "$(name).exe", symbol = "$(name).pdb"} + set_formats("static", "$(name).lib") + set_formats("object", "$(name).obj") + set_formats("shared", "$(name).dll") + set_formats("binary", "$(name).exe") + set_formats("symbol", "$(name).pdb") -- on check on_check("check") diff --git a/xmake/toolchains/sdcc/xmake.lua b/xmake/toolchains/sdcc/xmake.lua index 84a8d93fc..859f0b6d9 100644 --- a/xmake/toolchains/sdcc/xmake.lua +++ b/xmake/toolchains/sdcc/xmake.lua @@ -38,7 +38,10 @@ toolchain("sdcc") set_archs("stm8", "mcs51", "z80", "z180", "r2k", "r3ka", "s08", "hc08") -- set formats - set_formats {static = "$(name).lib", object = "$(name).rel", binary = "$(name).bin", symbol = "$(name).sym"} + set_formats("static", "$(name).lib") + set_formats("object", "$(name).rel") + set_formats("binary", "$(name).bin") + set_formats("symbol", "$(name).sym") -- check toolchain on_check("check") -- cgit v1.3.1 From 7ddbf1f6cb9a11ef792d256bee7da417f4058168 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 22:42:23 +0800 Subject: add platform.toolchains --- xmake/actions/config/xmake.lua | 21 +++++++--------- xmake/core/platform/platform.lua | 29 +++++++++++++++++++--- .../modules/import/core/platform/platform.lua | 5 ++++ 3 files changed, 40 insertions(+), 15 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 3b02846d1..2756a3bf1 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -55,7 +55,7 @@ task("config") , {'p', "plat", "kv", "$(subhost)" , "Compile for the given platform." , values = function (complete, opt) - -- import + -- imports import("core.platform.platform") import("core.base.hashset") @@ -77,10 +77,10 @@ task("config") -- show the description of all architectures function () - -- import platform + -- imports import("core.platform.platform") - -- make description + -- get all architectures local description = {} for i, plat in ipairs(platform.plats()) do local archs = platform.archs(plat) @@ -91,20 +91,17 @@ task("config") end end end - - -- get it return description end , values = function (complete, opt) if not complete then return end - -- import + -- imports import("core.platform.platform") import("core.base.hashset") - -- get archs + -- get all architectures local archset = hashset.new() - for _, plat in ipairs(opt.plat and { opt.plat } or platform.plats()) do local archs = platform.archs(plat) if archs then @@ -113,8 +110,6 @@ task("config") end end end - - -- get it return archset:to_array() end } , {'m', "mode", "kv", "release" , "Compile for the given mode." @@ -157,8 +152,10 @@ task("config") , " - sdk/lib" , " - sdk/include" } , {nil, "toolchain", "kv", nil, "The Toolchain Name" - , "e.g." - , " - llvm" } + , values = function (complete, opt) + import("core.platform.platform") + return platform.toolchains() + end } -- show language menu options , function () diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 3fc92be63..182ae17d9 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -503,9 +503,7 @@ function platform.plats() local plats = {} local dirs = platform.directories() for _, dir in ipairs(dirs) do - - -- get the platform list - local platpathes = os.match(path.join(dir, "*"), true) + local platpathes = os.dirs(path.join(dir, "*")) if platpathes then for _, platpath in ipairs(platpathes) do if os.isfile(path.join(platpath, "xmake.lua")) then @@ -518,6 +516,31 @@ function platform.plats() return plats end +-- get the all toolchains +function platform.toolchains() + + -- return it directly if exists + if platform._TOOLCHAINS then + return platform._TOOLCHAINS + end + + -- get all toolchains + local toolchains = {} + local dirs = toolchain.directories() + for _, dir in ipairs(dirs) do + local dirs = os.dirs(path.join(dir, "*")) + if dirs then + for _, dir in ipairs(dirs) do + if os.isfile(path.join(dir, "xmake.lua")) then + table.insert(toolchains, path.basename(dir)) + end + end + end + end + platform._TOOLCHAINS = toolchains + return toolchains +end + -- get the platform os function platform.os(plat) return platform.get("os", plat) diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index 6919010e6..d9730f830 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -45,6 +45,11 @@ function sandbox_core_platform.plats() return assert(platform.plats()) end +-- get the all toolchains +function sandbox_core_platform.toolchains() + return assert(platform.toolchains()) +end + -- get the all architectures for the given platform function sandbox_core_platform.archs(plat) return platform.archs(plat) -- cgit v1.3.1 From cf943ea441cdb49e426e2a3cedc1134922529644 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 23:07:29 +0800 Subject: improve to check toolchains --- xmake/core/platform/platform.lua | 70 +++++++++++++++++----- .../sandbox/modules/import/core/project/config.lua | 5 +- xmake/platforms/android/check.lua | 11 ---- xmake/platforms/bsd/check.lua | 22 ------- xmake/platforms/cross/check.lua | 11 ---- xmake/platforms/cygwin/check.lua | 23 ------- xmake/platforms/iphoneos/check.lua | 12 ---- xmake/platforms/linux/check.lua | 23 ------- xmake/platforms/macosx/check.lua | 23 ------- xmake/platforms/mingw/check.lua | 12 ---- xmake/platforms/msys/check.lua | 23 ------- xmake/platforms/watchos/check.lua | 11 ---- xmake/platforms/windows/check.lua | 23 ------- 13 files changed, 60 insertions(+), 209 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 182ae17d9..0131895ec 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -122,25 +122,34 @@ function _instance:runenvs() end -- get the toolchains -function _instance:toolchains() +function _instance:toolchains(opt) local toolchains = self._TOOLCHAINS if not toolchains then - -- get the given toolchain + -- get current valid toolchains from configuration cache + local names = nil toolchains = {} - local toolchain_given = config.get("toolchain") - if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) - if not toolchain_inst then - os.raise(errors) + if not (opt and opt.all) then + names = config.get("__toolchains") + else + -- get the given toolchain + local toolchain_given = config.get("toolchain") + if toolchain_given then + local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) + if not toolchain_inst then + os.raise(errors) + end + table.insert(toolchains, toolchain_inst) + toolchain_given = toolchain_inst end - table.insert(toolchains, toolchain_inst) - toolchain_given = toolchain_inst - end - -- get the platform toolchains - if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then - for _, name in ipairs(self._INFO:get("toolchains")) do + -- get the platform toolchains + if (not toolchain_given or not toolchain_given:standalone()) and self._INFO:get("toolchains") then + names = self._INFO:get("toolchains") + end + end + if names then + for _, name in ipairs(names) do local toolchain_inst, errors = toolchain.load(name, self:name()) if not toolchain_inst then os.raise(errors) @@ -239,10 +248,43 @@ end -- do check function _instance:check() + + -- check platform local on_check = self:script("check") if on_check then - on_check(self) + local ok, errors = sandbox.load(on_check, self) + if not ok then + return false, errors + end + end + + -- check toolchains + local toolchains = self:toolchains({all = true}) + local idx = 1 + local num = #toolchains + local standalone = false + local toolchains_valid = {} + 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 + table.insert(toolchains_valid, toolchain:name()) + end end + if #toolchains == 0 then + return false, "toolchains not found!" + end + + -- save valid toolchains + config.set("__toolchains", toolchains_valid) + return true end -- get formats diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index c7121a8a4..3ea6d3a30 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -116,7 +116,10 @@ function sandbox_core_project_config.check() -- get the current platform local instance, errors = platform.load() if instance then - instance:check() + local ok, errors = instance:check() + if not ok then + raise(errors) + end else raise(errors) end diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua index c262e1bed..5db47502a 100644 --- a/xmake/platforms/android/check.lua +++ b/xmake/platforms/android/check.lua @@ -24,17 +24,6 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, "armeabi-v7a") - - -- check toolchains - local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then - table.remove(toolchains, idx) - end - end - assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua index 71d2e555c..50c933cba 100644 --- a/xmake/platforms/bsd/check.lua +++ b/xmake/platforms/bsd/check.lua @@ -24,28 +24,6 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, os.arch()) - - -- 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/cross/check.lua b/xmake/platforms/cross/check.lua index 0c95f43c9..6c02f12b5 100644 --- a/xmake/platforms/cross/check.lua +++ b/xmake/platforms/cross/check.lua @@ -33,17 +33,6 @@ end -- check it function main(platform) - - -- check arch _check_arch() - - -- check toolchains - local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then - table.remove(toolchains, idx) - end - end - assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua index 8cd3cfbe0..5c5902225 100644 --- a/xmake/platforms/cygwin/check.lua +++ b/xmake/platforms/cygwin/check.lua @@ -24,28 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, config.get("cross") and "none" or os.subarch()) - - -- 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/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua index ad0110b39..520420f84 100644 --- a/xmake/platforms/iphoneos/check.lua +++ b/xmake/platforms/iphoneos/check.lua @@ -24,17 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, "arm64") - - -- check toolchains - local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then - table.remove(toolchains, idx) - end - end - assert(#toolchains > 0, "toolchains not found!") end - diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua index 71d2e555c..2d3a4a063 100644 --- a/xmake/platforms/linux/check.lua +++ b/xmake/platforms/linux/check.lua @@ -24,28 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, os.arch()) - - -- 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/macosx/check.lua b/xmake/platforms/macosx/check.lua index b4eb3b73b..0885534cc 100644 --- a/xmake/platforms/macosx/check.lua +++ b/xmake/platforms/macosx/check.lua @@ -24,28 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(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/mingw/check.lua b/xmake/platforms/mingw/check.lua index a44983421..6b81b5d92 100644 --- a/xmake/platforms/mingw/check.lua +++ b/xmake/platforms/mingw/check.lua @@ -24,17 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, "x86_64") - - -- check toolchains - local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then - table.remove(toolchains, idx) - end - end - assert(#toolchains > 0, "toolchains not found!") end - diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua index 8cd3cfbe0..5c5902225 100644 --- a/xmake/platforms/msys/check.lua +++ b/xmake/platforms/msys/check.lua @@ -24,28 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, config.get("cross") and "none" or os.subarch()) - - -- 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/watchos/check.lua b/xmake/platforms/watchos/check.lua index e4e36f092..bd8852db3 100644 --- a/xmake/platforms/watchos/check.lua +++ b/xmake/platforms/watchos/check.lua @@ -24,16 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(config, "armv7k") - - -- check toolchains - local toolchains = platform:toolchains() - for idx, toolchain in irpairs(toolchains) do - if not toolchain:check() then - table.remove(toolchains, idx) - end - end - assert(#toolchains > 0, "toolchains not found!") end diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua index 0dfc7b536..0885534cc 100644 --- a/xmake/platforms/windows/check.lua +++ b/xmake/platforms/windows/check.lua @@ -24,28 +24,5 @@ import("private.platform.check_arch") -- check it function main(platform) - - -- check arch check_arch(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 - -- cgit v1.3.1 From 445a9fd453c4e9c536e6bcc234c0c21e67d7ba05 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 23:07:52 +0800 Subject: remove some unused codes --- xmake/modules/private/platform/check_toolchain.lua | 83 ----------------- xmake/modules/private/platform/check_vstudio.lua | 103 --------------------- xmake/modules/private/platform/toolchain.lua | 38 -------- 3 files changed, 224 deletions(-) delete mode 100644 xmake/modules/private/platform/check_toolchain.lua delete mode 100644 xmake/modules/private/platform/check_vstudio.lua delete mode 100644 xmake/modules/private/platform/toolchain.lua diff --git a/xmake/modules/private/platform/check_toolchain.lua b/xmake/modules/private/platform/check_toolchain.lua deleted file mode 100644 index 839e6600d..000000000 --- a/xmake/modules/private/platform/check_toolchain.lua +++ /dev/null @@ -1,83 +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 check_toolchain.lua --- - --- imports -import("core.base.option") -import("lib.detect.find_tool") - --- check the given tool -function _check_tool(config, toolkind, description, name, cross, pathes, check) - - -- get the program - local program = config.get(toolkind) - if not program then - - -- translate program name to attempt to get `$(env XX)` - name = vformat(name) - if #name == 0 then - return - end - - -- attempt to check it - local toolname = nil - if not program then - local tool = find_tool(name, {program = (cross or "") .. name, pathes = pathes or config.get("bin"), check = check}) - if tool then - program = tool.program - toolname = tool.name - end - end - - -- check ok? - if program then - config.set(toolkind, program) - config.set("__toolname_" .. toolkind, toolname) - config.save() - end - - -- trace - if option.get("verbose") then - if program then - cprint("${dim}checking for %s (%s) ... ${color.success}%s", description, toolkind, path.filename(program)) - else - cprint("${dim}checking for %s (%s: ${bright}%s${clear}) ... ${color.nothing}${text.nothing}", description, toolkind, name) - end - end - end - - -- ok? - return program -end - --- check the toolchain -function main(config, name, toolchain) - for _, toolinfo in ipairs(toolchain.list) do - if type(toolinfo) == "string" then - if _check_tool(config, name, toolchain.description, toolinfo) then - break - end - else - if _check_tool(config, name, toolchain.description, toolinfo.name, toolinfo.cross, toolinfo.pathes, toolinfo.check) then - break - end - end - end -end - diff --git a/xmake/modules/private/platform/check_vstudio.lua b/xmake/modules/private/platform/check_vstudio.lua deleted file mode 100644 index 6657e43ea..000000000 --- a/xmake/modules/private/platform/check_vstudio.lua +++ /dev/null @@ -1,103 +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 check_vstudio.lua --- - --- imports -import("core.base.option") -import("detect.sdks.find_vstudio") -import("lib.detect.find_tool") -import("core.platform.environment") - --- attempt to check vs environment -function _check_vsenv(config) - - -- 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(config, opt) - - -- attempt to check the given vs version first - local vs = _check_vsenv(config) - if vs then - - -- save it - config.set("vs", vs, {readonly = true, force = true}) - - -- trace - cprint("checking for the Microsoft Visual Studio (%s) version ... ${color.success}%s", config.get("arch"), vs) - else - -- failed - 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 -end - - diff --git a/xmake/modules/private/platform/toolchain.lua b/xmake/modules/private/platform/toolchain.lua deleted file mode 100644 index 7ddf361d6..000000000 --- a/xmake/modules/private/platform/toolchain.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 toolchain.lua --- - --- imports -import("core.base.object") - --- init toolchain -local toolchain = toolchain or object {_init = {"description", "list"}} - --- add tool to toolchain list -function toolchain:add(...) - for _, item in ipairs({...}) do - table.insert(self.list, item) - end -end - --- create a toolchain object -function main(description) - return toolchain {description, {}} -end - -- cgit v1.3.1 From f248bb4ffe4a980eebd31a9ae12ddf8a03237d29 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 23:09:02 +0800 Subject: fix ex tool --- xmake/toolchains/clang/xmake.lua | 2 +- xmake/toolchains/gcc/xmake.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/toolchains/clang/xmake.lua b/xmake/toolchains/clang/xmake.lua index ca84a94be..944a6bc22 100644 --- a/xmake/toolchains/clang/xmake.lua +++ b/xmake/toolchains/clang/xmake.lua @@ -30,7 +30,7 @@ toolchain("clang") set_toolsets("ld", "clang++", "clang") set_toolsets("sh", "clang++", "clang") set_toolsets("ar", "ar") - set_toolsets("ex", "ex") + set_toolsets("ex", "ar") set_toolsets("strip", "strip") set_toolsets("mm", "clang") set_toolsets("mxx", "clang", "clang++") diff --git a/xmake/toolchains/gcc/xmake.lua b/xmake/toolchains/gcc/xmake.lua index 77f2ef228..17270aedb 100644 --- a/xmake/toolchains/gcc/xmake.lua +++ b/xmake/toolchains/gcc/xmake.lua @@ -30,7 +30,7 @@ toolchain("gcc") set_toolsets("ld", "g++", "gcc") set_toolsets("sh", "g++", "gcc") set_toolsets("ar", "ar") - set_toolsets("ex", "ex") + set_toolsets("ex", "ar") set_toolsets("strip", "strip") set_toolsets("mm", "gcc") set_toolsets("mxx", "gcc", "g++") -- cgit v1.3.1 From 36e30f47020e0c4399eb5f7b7a8739d55489f499 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 23:11:51 +0800 Subject: improve to check arch for platform --- xmake/modules/private/platform/check_arch.lua | 38 --------------------------- xmake/platforms/android/check.lua | 29 -------------------- xmake/platforms/android/xmake.lua | 11 ++++++-- xmake/platforms/bsd/check.lua | 29 -------------------- xmake/platforms/bsd/xmake.lua | 11 ++++++-- xmake/platforms/cross/check.lua | 38 --------------------------- xmake/platforms/cross/xmake.lua | 9 ++++++- xmake/platforms/cygwin/check.lua | 28 -------------------- xmake/platforms/cygwin/xmake.lua | 9 ++++++- xmake/platforms/iphoneos/check.lua | 28 -------------------- xmake/platforms/iphoneos/xmake.lua | 11 ++++++-- xmake/platforms/linux/check.lua | 28 -------------------- xmake/platforms/linux/xmake.lua | 11 ++++++-- xmake/platforms/macosx/check.lua | 28 -------------------- xmake/platforms/macosx/xmake.lua | 9 ++++++- xmake/platforms/mingw/check.lua | 28 -------------------- xmake/platforms/mingw/xmake.lua | 11 ++++++-- xmake/platforms/msys/check.lua | 28 -------------------- xmake/platforms/msys/xmake.lua | 11 ++++++-- xmake/platforms/watchos/check.lua | 28 -------------------- xmake/platforms/watchos/xmake.lua | 9 ++++++- xmake/platforms/windows/check.lua | 28 -------------------- xmake/platforms/windows/xmake.lua | 11 ++++++-- 23 files changed, 95 insertions(+), 376 deletions(-) delete mode 100644 xmake/modules/private/platform/check_arch.lua delete mode 100644 xmake/platforms/android/check.lua delete mode 100644 xmake/platforms/bsd/check.lua delete mode 100644 xmake/platforms/cross/check.lua delete mode 100644 xmake/platforms/cygwin/check.lua delete mode 100644 xmake/platforms/iphoneos/check.lua delete mode 100644 xmake/platforms/linux/check.lua delete mode 100644 xmake/platforms/macosx/check.lua delete mode 100644 xmake/platforms/mingw/check.lua delete mode 100644 xmake/platforms/msys/check.lua delete mode 100644 xmake/platforms/watchos/check.lua delete mode 100644 xmake/platforms/windows/check.lua diff --git a/xmake/modules/private/platform/check_arch.lua b/xmake/modules/private/platform/check_arch.lua deleted file mode 100644 index 4e67f8ae9..000000000 --- a/xmake/modules/private/platform/check_arch.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 check_arch.lua --- - --- imports -import("core.base.option") - --- check the architecture -function main(config, default) - - -- get the architecture - local arch = config.get("arch") - if not arch then - - -- init the default architecture - config.set("arch", default or os.arch()) - - -- trace - cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) - end -end - diff --git a/xmake/platforms/android/check.lua b/xmake/platforms/android/check.lua deleted file mode 100644 index 5db47502a..000000000 --- a/xmake/platforms/android/check.lua +++ /dev/null @@ -1,29 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, "armeabi-v7a") -end - diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index 48177245e..27bea1645 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -42,8 +42,15 @@ platform("android") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "armeabi-v7a") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "ndk", "rust") diff --git a/xmake/platforms/bsd/check.lua b/xmake/platforms/bsd/check.lua deleted file mode 100644 index 50c933cba..000000000 --- a/xmake/platforms/bsd/check.lua +++ /dev/null @@ -1,29 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, os.arch()) -end - diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 7bc9c03b8..35f063eb7 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -39,8 +39,15 @@ platform("bsd") -- set install directory set_installdir("/usr/local") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") diff --git a/xmake/platforms/cross/check.lua b/xmake/platforms/cross/check.lua deleted file mode 100644 index 6c02f12b5..000000000 --- a/xmake/platforms/cross/check.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 check.lua --- - --- imports -import("core.project.config") - --- check the architecture -function _check_arch() - - -- get the architecture - local arch = config.get("arch") - if not arch then - config.set("arch", "none") - end -end - --- check it -function main(platform) - _check_arch() -end - diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index 4e6b2dcc2..c5b12eda5 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -34,7 +34,14 @@ platform("cross") set_formats("symbol", "$(name).sym") -- on check - on_check("check") + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "none") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "cross") diff --git a/xmake/platforms/cygwin/check.lua b/xmake/platforms/cygwin/check.lua deleted file mode 100644 index 5c5902225..000000000 --- a/xmake/platforms/cygwin/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, config.get("cross") and "none" or os.subarch()) -end diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index c7f16f8d2..deca581bc 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -41,7 +41,14 @@ platform("cygwin") set_installdir("/usr/local") -- on check - on_check("check") + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.subarch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm") diff --git a/xmake/platforms/iphoneos/check.lua b/xmake/platforms/iphoneos/check.lua deleted file mode 100644 index 520420f84..000000000 --- a/xmake/platforms/iphoneos/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, "arm64") -end diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index bf7612c2c..7118846b7 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,8 +36,15 @@ platform("iphoneos") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "arm64") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "xcode") diff --git a/xmake/platforms/linux/check.lua b/xmake/platforms/linux/check.lua deleted file mode 100644 index 2d3a4a063..000000000 --- a/xmake/platforms/linux/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, os.arch()) -end diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 62cc1e3e8..a1097565b 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -39,8 +39,15 @@ platform("linux") -- set install directory set_installdir("/usr/local") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust") diff --git a/xmake/platforms/macosx/check.lua b/xmake/platforms/macosx/check.lua deleted file mode 100644 index 0885534cc..000000000 --- a/xmake/platforms/macosx/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config) -end diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index 0dc0ece52..f643d2c80 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -40,7 +40,14 @@ platform("macosx") set_installdir("/usr/local") -- on check - on_check("check") + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go") diff --git a/xmake/platforms/mingw/check.lua b/xmake/platforms/mingw/check.lua deleted file mode 100644 index 6b81b5d92..000000000 --- a/xmake/platforms/mingw/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, "x86_64") -end diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 6a29e39d5..82c2ae07e 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -37,8 +37,15 @@ platform("mingw") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "x86_64") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "mingw") diff --git a/xmake/platforms/msys/check.lua b/xmake/platforms/msys/check.lua deleted file mode 100644 index 5c5902225..000000000 --- a/xmake/platforms/msys/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, config.get("cross") and "none" or os.subarch()) -end diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index 7fa199b76..ec73a87ee 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -40,8 +40,15 @@ platform("msys") -- set install directory set_installdir("/usr/local") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.subarch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm") diff --git a/xmake/platforms/watchos/check.lua b/xmake/platforms/watchos/check.lua deleted file mode 100644 index bd8852db3..000000000 --- a/xmake/platforms/watchos/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config, "armv7k") -end diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 8be929977..b6d864d0b 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -37,7 +37,14 @@ platform("watchos") set_formats("symbol", "$(name).dSYM") -- on check - on_check("check") + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", "armv7k") + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("envs", "xcode") diff --git a/xmake/platforms/windows/check.lua b/xmake/platforms/windows/check.lua deleted file mode 100644 index 0885534cc..000000000 --- a/xmake/platforms/windows/check.lua +++ /dev/null @@ -1,28 +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 check.lua --- - --- imports -import("core.project.config") -import("private.platform.check_arch") - --- check it -function main(platform) - check_arch(config) -end diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index f43d7179c..5c29b0e0b 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -37,8 +37,15 @@ platform("windows") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") - -- on check - on_check("check") + -- on check + on_check(function (platform) + import("core.project.config") + local arch = config.get("arch") + if not arch then + config.set("arch", os.arch()) + cprint("checking for the architecture ... ${color.success}%s", config.get("arch")) + end + end) -- set toolchains set_toolchains("vs", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go") -- cgit v1.3.1 From 158492c9932be3a1bb79dbc1b969de06498dd2d1 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 21 May 2020 23:12:30 +0800 Subject: improve llvm-ar --- xmake/modules/core/tools/llvm_ar.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/xmake/modules/core/tools/llvm_ar.lua b/xmake/modules/core/tools/llvm_ar.lua index b9674ffaf..0d890bd5c 100644 --- a/xmake/modules/core/tools/llvm_ar.lua +++ b/xmake/modules/core/tools/llvm_ar.lua @@ -24,9 +24,6 @@ import("core.tool.compiler") -- init it function init(self) self:set("arflags", "cr") - if is_plat("cross") and is_subhost("windows") then - self:set("formats", { static = "$(name).lib" }) - end end -- make the strip flag -- cgit v1.3.1 From eb098b6358005b1fe52e6efba860ab462977825e Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 00:30:49 +0800 Subject: add 'xmake show' --- xmake/plugins/show/list.lua | 31 +++++++++++++++++++++ xmake/plugins/show/lists/toolchains.lua | 29 +++++++++++++++++++ xmake/plugins/show/main.lua | 37 +++++++++++++++++++++++++ xmake/plugins/show/xmake.lua | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 xmake/plugins/show/list.lua create mode 100644 xmake/plugins/show/lists/toolchains.lua create mode 100644 xmake/plugins/show/main.lua create mode 100644 xmake/plugins/show/xmake.lua diff --git a/xmake/plugins/show/list.lua b/xmake/plugins/show/list.lua new file mode 100644 index 000000000..3d44532bb --- /dev/null +++ b/xmake/plugins/show/list.lua @@ -0,0 +1,31 @@ +--!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 list.lua +-- + +-- imports +import("core.base.option") + +-- get all list values +function lists() + local values = {} + for _, filepath in ipairs(os.files(path.join(os.scriptdir(), "lists", "*.lua"))) do + table.insert(values, path.basename(filepath)) + end + return values +end diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua new file mode 100644 index 000000000..a1b7008e3 --- /dev/null +++ b/xmake/plugins/show/lists/toolchains.lua @@ -0,0 +1,29 @@ +--!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 toolchains.lua +-- + +-- imports +import("core.platform.platform") + +-- get all toolchains +function main() + for _, name in ipairs(platform.toolchains()) do + print(name) + end +end diff --git a/xmake/plugins/show/main.lua b/xmake/plugins/show/main.lua new file mode 100644 index 000000000..816ca30a3 --- /dev/null +++ b/xmake/plugins/show/main.lua @@ -0,0 +1,37 @@ +--!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 main.lua +-- + +-- imports +import("core.base.option") + +-- show list +function _show_list(name) + return assert(import("lists." .. name, {try = true, anonymous = true}), "unknown list name(%s)", name)() +end + +-- main entry +function main() + + -- show list? + local listname = option.get("list") + if listname then + return _show_list(listname) + end +end diff --git a/xmake/plugins/show/xmake.lua b/xmake/plugins/show/xmake.lua new file mode 100644 index 000000000..180b2140d --- /dev/null +++ b/xmake/plugins/show/xmake.lua @@ -0,0 +1,49 @@ +--!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 task +task("show") + + -- set category + set_category("plugin") + + -- on run + on_run("main") + + -- set menu + set_menu { + -- usage + usage = "xmake show [options] [arguments]" + + -- description + , description = "Show the given project information." + + -- options + , options = + { + {'l', "list" , "kv" , nil , "Show the values list of the given name." + , values = function (complete, opt) + return import("list").lists() + end} + } + } + + + -- cgit v1.3.1 From 3f25af48131cf74e2ce5dc291b7427a2b3a48e01 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 00:32:41 +0800 Subject: impl xmake show toolchains --- xmake/plugins/show/lists/toolchains.lua | 11 ++++++++--- xmake/plugins/show/showlist.lua | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 xmake/plugins/show/showlist.lua diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua index a1b7008e3..30897559e 100644 --- a/xmake/plugins/show/lists/toolchains.lua +++ b/xmake/plugins/show/lists/toolchains.lua @@ -19,11 +19,16 @@ -- -- imports +import("core.base.option") import("core.platform.platform") +import(".showlist") --- get all toolchains +-- show all toolchains function main() - for _, name in ipairs(platform.toolchains()) do - print(name) + if option.get("verbose") then + -- TODO show description + showlist(platform.toolchains()) + else + showlist(platform.toolchains()) end end diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua new file mode 100644 index 000000000..88176f9ad --- /dev/null +++ b/xmake/plugins/show/showlist.lua @@ -0,0 +1,30 @@ +--!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 showlist.lua +-- + +-- imports +import("core.base.option") + +-- show values +function main(values) + -- TODO use text.table + for _, value in ipairs(values) do + print(value) + end +end -- cgit v1.3.1 From 90e7778e33d39bb86d6b79084a5cea12b88238fe Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 00:46:06 +0800 Subject: improve help for toolchains --- xmake/actions/config/xmake.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 2756a3bf1..89e739e88 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -152,9 +152,15 @@ task("config") , " - sdk/lib" , " - sdk/include" } , {nil, "toolchain", "kv", nil, "The Toolchain Name" + , "e.g. " + , " - xmake f --toolchain=clang" + , " - xmake f --toolchain=[cross|llvm|sdcc ..] --sdk=/xxx" + , " - run `xmake show -l toolchains` to get all toolchains" , values = function (complete, opt) - import("core.platform.platform") - return platform.toolchains() + if complete then + import("core.platform.platform") + return platform.toolchains() + end end } -- show language menu options -- cgit v1.3.1 From e702326e0c1a25ad6e10ab31864b8a9f991606c7 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 00:49:11 +0800 Subject: improve to show list --- xmake/plugins/show/lists/toolchains.lua | 7 +------ xmake/plugins/show/showlist.lua | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua index 30897559e..1a288859f 100644 --- a/xmake/plugins/show/lists/toolchains.lua +++ b/xmake/plugins/show/lists/toolchains.lua @@ -25,10 +25,5 @@ import(".showlist") -- show all toolchains function main() - if option.get("verbose") then - -- TODO show description - showlist(platform.toolchains()) - else - showlist(platform.toolchains()) - end + showlist(platform.toolchains()) end diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index 88176f9ad..acd7e2587 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -20,11 +20,21 @@ -- imports import("core.base.option") +import("core.base.text") -- show values function main(values) - -- TODO use text.table + local tbl = {align = 'l', sep = " "} + local row = {} for _, value in ipairs(values) do - print(value) + table.insert(row, value) + if #row > 10 then + table.insert(tbl, row) + row = {} + end end + if #row > 0 then + table.insert(tbl, row) + end + print(text.table(tbl)) end -- cgit v1.3.1 From e649d1c2a8dab803bacbdd1551f629469ab5158f Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 22:43:17 +0800 Subject: improve toolchain to support multi-arch --- xmake/core/base/scopeinfo.lua | 7 +- xmake/core/platform/platform.lua | 2 +- xmake/core/project/project.lua | 47 ++++++++++++- .../modules/import/core/project/project.lua | 2 + xmake/core/tool/toolchain.lua | 78 ++++++++++++++-------- 5 files changed, 102 insertions(+), 34 deletions(-) diff --git a/xmake/core/base/scopeinfo.lua b/xmake/core/base/scopeinfo.lua index 05337e4c8..c8bd2fec7 100644 --- a/xmake/core/base/scopeinfo.lua +++ b/xmake/core/base/scopeinfo.lua @@ -546,7 +546,12 @@ function _instance:extraconf(name, item, key) return value end --- new an scope instance +-- clone a new instance from the current +function _instance:clone() + return _instance.new(self:kind(), self:info(), {interpreter = self:interpreter(), remove_repeat = self._REMOVE_REPEAT, enable_filter = self._ENABLE_FILTER}) +end + +-- new a scope instance function scopeinfo.new(...) return _instance.new(...) end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 0131895ec..56491c927 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -135,7 +135,7 @@ function _instance:toolchains(opt) -- get the given toolchain local toolchain_given = config.get("toolchain") if toolchain_given then - local toolchain_inst, errors = toolchain.load(toolchain_given, self:name()) + local toolchain_inst, errors = toolchain.load(toolchain_given) if not toolchain_inst then os.raise(errors) end diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index e900f394f..08f843d0e 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -42,6 +42,7 @@ local deprecated_project = require("project/deprecated/project") local package = require("package/package") local platform = require("platform/platform") local environment = require("platform/environment") +local toolchain = require("tool/toolchain") local language = require("language/language") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") @@ -327,6 +328,29 @@ function project._load_rules() return rules end +-- load toolchains +function project._load_toolchains() + + -- load the project file first if has not been loaded? + local ok, errors = project._load() + if not ok then + return nil, errors + end + + -- load the toolchain from the the project file + local results, errors = project._load_scope("toolchain", true, true) + if not results then + return nil, errors + end + + -- make toolchain instances + local toolchains = {} + for toolchain_name, toolchain_info in pairs(results) do + toolchains[toolchain_name] = toolchain.new(toolchain_name, toolchain_info) + end + return toolchains +end + -- load targets function project._load_targets() @@ -680,6 +704,9 @@ function project.interpreter() -- define apis for language interp:api_define(language.apis()) + -- define apis for toolchain + interp:api_define(toolchain.apis()) + -- define apis for project interp:api_define(project.apis()) @@ -924,10 +951,7 @@ end -- get project rules function project.rules() - if not project._RULES then - - -- load rules local rules, errors = project._load_rules() if not rules then os.raise(errors) @@ -937,6 +961,23 @@ function project.rules() return project._RULES end +-- get the given toolchain +function project.toolchain(name) + return project.toolchains()[name] +end + +-- get project toolchains +function project.toolchains() + if not project._TOOLCHAINS then + local toolchains, errors = project._load_toolchains() + if not toolchains then + os.raise(errors) + end + project._TOOLCHAINS = toolchains + end + return project._TOOLCHAINS +end + -- get the given task function project.task(name) return project.tasks()[name] diff --git a/xmake/core/sandbox/modules/import/core/project/project.lua b/xmake/core/sandbox/modules/import/core/project/project.lua index c6796af36..cb7465fcd 100644 --- a/xmake/core/sandbox/modules/import/core/project/project.lua +++ b/xmake/core/sandbox/modules/import/core/project/project.lua @@ -39,6 +39,8 @@ local import = require("sandbox/modules/import") sandbox_core_project.get = project.get sandbox_core_project.rule = project.rule sandbox_core_project.rules = project.rules +sandbox_core_project.toolchain = project.toolchain +sandbox_core_project.toolchains = project.toolchains sandbox_core_project.target = project.target sandbox_core_project.targets = project.targets sandbox_core_project.option = project.option diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 894dfb879..dddfb841a 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -49,21 +49,48 @@ function _instance:name() return self._NAME end +-- get toolchain platform +function _instance:plat() + return config.get("plat") or os.host() +end + +-- get toolchain architecture +function _instance:arch() + return config.get("arch") or os.arch() +end + +-- get toolchain info +function _instance:info() + local arch = self:arch() + local infos = self._INFOS + if not infos then + infos = {} + self._INFOS = infos + end + local info = infos[arch] + if not info then + -- we need multiple info objects for different architectures + info = self._INFO:clone() + infos[arch] = info + end + return info +end + -- set the value to the toolchain configuration function _instance:set(name, ...) - self._INFO:apival_set(name, ...) + self:info():apival_set(name, ...) end -- add the value to the toolchain configuration function _instance:add(name, ...) - self._INFO:apival_add(name, ...) + self:info():apival_add(name, ...) end -- get the toolchain configuration function _instance:get(name) -- attempt to get the static configure value - local value = self._INFO:get(name) + local value = self:info():get(name) if value ~= nil then return value end @@ -72,12 +99,12 @@ function _instance:get(name) self:_load() -- get other platform info - return self._INFO:get(name) + return self:info():get(name) end -- get toolchain kind function _instance:kind() - return self._INFO:get("kind") + return self:info():get("kind") end -- is standalone toolchain? @@ -100,7 +127,7 @@ end -- get the toolchain script function _instance:script(name) - return self._INFO:get(name) + return self:info():get(name) end -- get the bin directory @@ -115,25 +142,27 @@ end -- do load function _instance:_load() - if not self._LOADED and not self._LOADING then - local on_load = self._INFO:get("load") + local info = self:info() + if not info:get("__loaded") and not info:get("__loading") then + local on_load = info:get("load") if on_load then - self._LOADING = true + info:set("__loading", true) local ok, errors = sandbox.load(on_load, self) - self._LOADING = false + info:set("__loading", false) if not ok then os.raise(errors) end end - self._LOADED = true + info:set("__loaded", true) end end -- do check function _instance:check() local checkok = true - if not self._CHECKED then - local on_check = self._INFO:get("check") + local info = self:info() + if not info:get("__checked") then + local on_check = self:info():get("check") if on_check then local ok, results_or_errors = sandbox.load(on_check, self) if ok then @@ -142,7 +171,7 @@ function _instance:check() os.raise(results_or_errors) end end - self._CHECKED = true + info:set("__checked", true) end return checkok end @@ -246,7 +275,7 @@ function toolchain._interpreter() assert(interp) -- define apis - interp:api_define(toolchain._apis()) + interp:api_define(toolchain.apis()) -- define apis for language interp:api_define(language.apis()) @@ -259,7 +288,7 @@ function toolchain._interpreter() end -- get toolchain apis -function toolchain._apis() +function toolchain.apis() return { values = @@ -300,21 +329,12 @@ function toolchain.directories() end -- load the given toolchain -function toolchain.load(name, plat) - - -- get toolchain name - plat = plat or config.get("plat") or os.host() - if not plat then - return nil, string.format("unknown toolchain!") - end - - -- get cache key - local cachekey = name .. "_" .. plat .. "_" .. (config.get("arch") or os.arch()) +function toolchain.load(name) -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} - if toolchain._TOOLCHAINS[cachekey] then - return toolchain._TOOLCHAINS[cachekey] + if toolchain._TOOLCHAINS[name] then + return toolchain._TOOLCHAINS[name] end -- find the toolchain script path @@ -357,7 +377,7 @@ function toolchain.load(name, plat) end -- save instance to the cache - toolchain._TOOLCHAINS[cachekey] = instance + toolchain._TOOLCHAINS[name] = instance return instance end -- cgit v1.3.1 From b1df391694245eb0f1555b3855fad3faee0d2a82 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 22:44:15 +0800 Subject: load toolchains for project --- xmake/core/platform/platform.lua | 10 ++-------- xmake/core/tool/toolchain.lua | 15 +++++++-------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 56491c927..af6a2f0e0 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -34,11 +34,10 @@ local config = require("project/config") local global = require("base/global") -- new an instance -function _instance.new(name, info, rootdir) +function _instance.new(name, info) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info - instance._ROOTDIR = rootdir return instance end @@ -465,13 +464,8 @@ function platform.load(plat) return nil, string.format("the platform %s not found!", plat) end - -- new an instance - local instance, errors = _instance.new(plat, result, interp:rootdir()) - if not instance then - return nil, errors - end - -- save instance to the cache + local instance = _instance.new(plat, result) platform._PLATFORMS[cachekey] = instance return instance end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index dddfb841a..dd682d3b2 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,11 +36,10 @@ local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info, rootdir) +function _instance.new(name, info) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info - instance._ROOTDIR = rootdir return instance end @@ -370,16 +369,16 @@ function toolchain.load(name) return nil, string.format("the toolchain %s not found!", name) end - -- new an instance - local instance, errors = _instance.new(name, result, interp:rootdir()) - if not instance then - return nil, errors - end - -- save instance to the cache + local instance = _instance.new(name, result) toolchain._TOOLCHAINS[name] = instance return instance end +-- new toolchain +function toolchain.new(name, info) + return _instance.new(name, info) +end + -- return module return toolchain -- cgit v1.3.1 From 9a3ccbc46480462a7d2a702c8c635af17cd85249 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 22:49:44 +0800 Subject: load toolchain from project --- xmake/core/main.lua | 1 - xmake/core/platform/platform.lua | 15 ++++++++++++++- xmake/core/project/project.lua | 3 +++ xmake/core/tool/toolchain.lua | 9 ++++----- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/xmake/core/main.lua b/xmake/core/main.lua index 63270ee15..ea85a605e 100644 --- a/xmake/core/main.lua +++ b/xmake/core/main.lua @@ -191,7 +191,6 @@ function main._init() else os.addenv("PATH", os.programdir()) end - return true end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index af6a2f0e0..eb247f7af 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -135,6 +135,10 @@ function _instance:toolchains(opt) local toolchain_given = config.get("toolchain") if toolchain_given then local toolchain_inst, errors = toolchain.load(toolchain_given) + -- attempt to load toolchain from project + if not toolchain_inst and platform._project() then + toolchain_inst = platform._project().toolchain(toolchain_given) + end if not toolchain_inst then os.raise(errors) end @@ -149,7 +153,11 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name, self:name()) + local toolchain_inst, errors = toolchain.load(name) + -- attempt to load toolchain from project + if not toolchain_inst and platform._project() then + toolchain_inst = platform._project().toolchain(name) + end if not toolchain_inst then os.raise(errors) end @@ -343,6 +351,11 @@ function platform._interpreter() return interp end +-- get project +function platform._project() + return platform._PROJECT +end + -- get platform apis function platform._apis() return diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 08f843d0e..1c97bdfd4 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -47,6 +47,9 @@ local language = require("language/language") local sandbox_os = require("sandbox/modules/os") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") +-- register project to platform +platform._PROJECT = project + -- the current os is belong to the given os? function project._api_is_os(interp, ...) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index dd682d3b2..e2220127e 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -139,7 +139,7 @@ function _instance:sdkdir() return config.get("sdk") or self:get("sdkdir") end --- do load +-- do load, @note we need load it repeatly for each architectures function _instance:_load() local info = self:info() if not info:get("__loaded") and not info:get("__loading") then @@ -156,11 +156,10 @@ function _instance:_load() end end --- do check +-- do check, we only check it once for all architectures function _instance:check() local checkok = true - local info = self:info() - if not info:get("__checked") then + if not self._CHECKED then local on_check = self:info():get("check") if on_check then local ok, results_or_errors = sandbox.load(on_check, self) @@ -170,7 +169,7 @@ function _instance:check() os.raise(results_or_errors) end end - info:set("__checked", true) + self._CHECKED = true end return checkok end -- cgit v1.3.1 From f216efbfd66a9e72ed423d34f28c17243190ac70 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 22:50:15 +0800 Subject: improve to show toolchains --- xmake/plugins/show/lists/toolchains.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xmake/plugins/show/lists/toolchains.lua b/xmake/plugins/show/lists/toolchains.lua index 1a288859f..911fd801c 100644 --- a/xmake/plugins/show/lists/toolchains.lua +++ b/xmake/plugins/show/lists/toolchains.lua @@ -20,10 +20,15 @@ -- imports import("core.base.option") +import("core.project.project") import("core.platform.platform") import(".showlist") -- show all toolchains function main() - showlist(platform.toolchains()) + local names = table.copy(platform.toolchains()) + for name, _ in pairs(project.toolchains()) do + table.insert(names, name) + end + showlist(names) end -- cgit v1.3.1 From adad9bc3ad159e5cf327d2058ff212c831fedcfd Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 22:50:44 +0800 Subject: improve toolchains values --- xmake/actions/config/xmake.lua | 7 ++++++- xmake/plugins/show/showlist.lua | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index 89e739e88..621037f53 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -158,8 +158,13 @@ task("config") , " - run `xmake show -l toolchains` to get all toolchains" , values = function (complete, opt) if complete then + import("core.project.project") import("core.platform.platform") - return platform.toolchains() + local names = table.copy(platform.toolchains()) + for name, _ in pairs(project.toolchains()) do + table.insert(names, name) + end + return names end end } diff --git a/xmake/plugins/show/showlist.lua b/xmake/plugins/show/showlist.lua index acd7e2587..7a7e90b54 100644 --- a/xmake/plugins/show/showlist.lua +++ b/xmake/plugins/show/showlist.lua @@ -24,7 +24,7 @@ import("core.base.text") -- show values function main(values) - local tbl = {align = 'l', sep = " "} + local tbl = {align = 'l', sep = " "} local row = {} for _, value in ipairs(values) do table.insert(row, value) -- cgit v1.3.1 From 5ad2eaee8cd65987359dbdfc5149bdd61b9260fc Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 22 May 2020 23:06:53 +0800 Subject: show platforms and targets --- xmake/plugins/show/lists/platforms.lua | 28 +++++++++++++++++++++++++++ xmake/plugins/show/lists/targets.lua | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 xmake/plugins/show/lists/platforms.lua create mode 100644 xmake/plugins/show/lists/targets.lua diff --git a/xmake/plugins/show/lists/platforms.lua b/xmake/plugins/show/lists/platforms.lua new file mode 100644 index 000000000..0f9d2507c --- /dev/null +++ b/xmake/plugins/show/lists/platforms.lua @@ -0,0 +1,28 @@ +--!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 platforms.lua +-- + +-- imports +import("core.platform.platform") +import(".showlist") + +-- show all platforms +function main() + showlist(platform.plats()) +end diff --git a/xmake/plugins/show/lists/targets.lua b/xmake/plugins/show/lists/targets.lua new file mode 100644 index 000000000..7089fc53f --- /dev/null +++ b/xmake/plugins/show/lists/targets.lua @@ -0,0 +1,35 @@ +--!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 targets.lua +-- + +-- imports +import("core.project.config") +import("core.project.project") +import("core.platform.platform") +import(".showlist") + +-- show all platforms +function main() + config.load() + local targets = {} + for name, _ in pairs(project.targets()) do + table.insert(targets, name) + end + showlist(targets) +end -- cgit v1.3.1