diff options
| author | ruki <[email protected]> | 2020-06-19 00:48:33 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2020-06-18 22:51:19 +0800 |
| commit | 92dd2db73694ab13671db73194ab1e9fae1b9371 (patch) | |
| tree | 1d4ae3f3c82999f6d67043a882d68286e8ea94b4 | |
| parent | 53df324acd9c7432336a5894ceef578daa1ce38d (diff) | |
improve the plat/arch of toolchain
| -rw-r--r-- | xmake/core/platform/platform.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/project.lua | 4 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 4 | ||||
| -rw-r--r-- | xmake/core/tool/toolchain.lua | 48 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/check.lua | 4 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/xmake.lua | 14 |
9 files changed, 55 insertions, 29 deletions
diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index e9a66d0dc..39f88645f 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) + local toolchain_inst, errors = toolchain.load(toolchain_given, {plat = self:name()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(toolchain_given) @@ -154,7 +154,7 @@ function _instance:toolchains(opt) end if names then for _, name in ipairs(names) do - local toolchain_inst, errors = toolchain.load(name) + local toolchain_inst, errors = toolchain.load(name, {plat = self:name()}) -- attempt to load toolchain from project if not toolchain_inst and platform._project() then toolchain_inst = platform._project().toolchain(name) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 96d4256ef..795f863b5 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -433,7 +433,9 @@ function project._load_targets() if toolchains then t._TOOLCHAINS = {} for _, name in ipairs(table.wrap(toolchains)) do - local toolchain_inst, errors = toolchain.load(name) + local toolchain_plat = t:extraconf("toolchains", name, "plat") + local toolchain_arch = t:extraconf("toolchains", name, "arch") + local toolchain_inst, errors = toolchain.load(name, {plat = toolchain_plat, arch = toolchain_arch}) -- attempt to load toolchain from project if not toolchain_inst then toolchain_inst = project.toolchain(name) diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 3df4128c5..ad001c559 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1707,8 +1707,8 @@ function _instance:tool(toolkind) end end - -- attempt to get program from config first - if not program then + -- attempt to get program from config first if no the given toolchains in target + if not program and not self:get("toolchains") then program = config.get(toolkind) toolname = config.get("__toolname_" .. toolkind) end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 6e48ef836..12470394b 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,9 +36,11 @@ local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info) +function _instance.new(name, plat, arch, info) local instance = table.inherit(_instance) instance._NAME = name + instance._PLAT = plat + instance._ARCH = arch instance._INFO = info return instance end @@ -50,12 +52,32 @@ end -- get toolchain platform function _instance:plat() - return config.get("plat") or os.host() + return self._PLAT end -- get toolchain architecture function _instance:arch() - return config.get("arch") or os.arch() + return self._ARCH +end + +-- the current platform is belong to the given platforms? +function _instance:is_plat(...) + local plat = self:plat() + for _, v in ipairs(table.join(...)) do + if v and plat == v then + return true + end + end +end + +-- the current architecture is belong to the given architectures? +function _instance:is_arch(...) + local arch = self:arch() + for _, v in ipairs(table.join(...)) do + if v and arch:find("^" .. v:gsub("%-", "%%-") .. "$") then + return true + end + end end -- get toolchain info @@ -318,24 +340,26 @@ 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) +function toolchain.load(name, opt) + + -- init cache key + opt = opt or {} + local plat = opt.plat or config.get("plat") or os.host() + local arch = opt.arch or config.get("arch") or os.arch() + local cachekey = name .. plat .. arch -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} - if toolchain._TOOLCHAINS[name] then - return toolchain._TOOLCHAINS[name] + if toolchain._TOOLCHAINS[cachekey] then + return toolchain._TOOLCHAINS[cachekey] end -- find the toolchain script path @@ -372,8 +396,8 @@ function toolchain.load(name) end -- save instance to the cache - local instance = _instance.new(name, result) - toolchain._TOOLCHAINS[name] = instance + local instance = _instance.new(name, plat, arch, result) + toolchain._TOOLCHAINS[cachekey] = instance return instance end diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 925db3870..d5f79ab27f 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -27,7 +27,7 @@ import("detect.sdks.find_xcode") function main(toolchain) -- find xcode - local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = config.get("plat"), arch = config.get("arch")}) + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = toolchain:plat(), arch = toolchain:arch()}) if xcode then config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) else @@ -39,7 +39,7 @@ function main(toolchain) local target_minver = config.get("target_minver") if xcode_sdkver and not target_minver then target_minver = xcode_sdkver - if is_plat("macosx") then + if toolchain:is_plat("macosx") then local macos_ver = macos.version() if macos_ver then target_minver = macos_ver:major() .. "." .. macos_ver:minor() diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 3aeb78672..842064cb7 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -25,7 +25,7 @@ import("core.project.config") function main(toolchain) -- init architecture - local arch = config.get("arch") or "arm64" + local arch = toolchain:arch() local simulator = (arch == "i386" or arch == "x86_64") -- init platform name diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index de7dddb1e..f2060ad68 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -25,7 +25,7 @@ import("core.project.config") function main(toolchain) -- init flags for architecture - local arch = config.get("arch") or os.arch() + local arch = toolchain:arch() local target_minver = config.get("target_minver") -- init flags for the xcode sdk directory diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index 5048f4bb7..6730784b1 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -25,7 +25,7 @@ import("core.project.config") function main(toolchain) -- init architecture - local arch = config.get("arch") + local arch = toolchain:arch() local simulator = arch == "i386" -- init platform name diff --git a/xmake/toolchains/xcode/xmake.lua b/xmake/toolchains/xcode/xmake.lua index 776c142af..7394c8a13 100644 --- a/xmake/toolchains/xcode/xmake.lua +++ b/xmake/toolchains/xcode/xmake.lua @@ -36,14 +36,14 @@ toolchain("xcode") -- get cross local cross, arch, simulator - if is_plat("macosx") then + if toolchain:is_plat("macosx") then cross = "xcrun -sdk macosx " - elseif is_plat("iphoneos") then - arch = get_config("arch") or os.arch() + elseif toolchain:is_plat("iphoneos") then + arch = toolchain:arch() simulator = (arch == "i386" or arch == "x86_64") cross = simulator and "xcrun -sdk iphonesimulator " or "xcrun -sdk iphoneos " - elseif is_plat("watchos") then - arch = get_config("arch") or os.arch() + elseif toolchain:is_plat("watchos") then + arch = toolchain:arch() simulator = (arch == "i386") cross = simulator and "xcrun -sdk watchsimulator " or "xcrun -sdk watchos " else @@ -67,7 +67,7 @@ toolchain("xcode") if arch then toolchain:set("toolset", "cpp", cross .. "clang -arch " .. arch .. " -E") end - if is_plat("macosx") then + if toolchain:is_plat("macosx") then toolchain:set("toolset", "as", cross .. "clang") elseif simulator then toolchain:set("toolset", "as", cross .. "clang") @@ -76,5 +76,5 @@ toolchain("xcode") end -- load configurations - import("load_" .. get_config("plat"))(toolchain) + import("load_" .. toolchain:plat())(toolchain) end) |
