From d313c481f3bc4288ca06ba0a043ae36234c151da Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 13 Dec 2020 20:40:03 +0800 Subject: improve toolchain --- xmake/core/project/project.lua | 47 ++++++++++--------- .../sandbox/modules/import/core/tool/toolchain.lua | 2 +- xmake/core/tool/toolchain.lua | 52 +++++++++++++++++++--- 3 files changed, 69 insertions(+), 32 deletions(-) diff --git a/xmake/core/project/project.lua b/xmake/core/project/project.lua index 8098b88fc..0c6d5a463 100644 --- a/xmake/core/project/project.lua +++ b/xmake/core/project/project.lua @@ -321,7 +321,7 @@ function project._load_rules() end -- load toolchains -function project._load_toolchains(opt) +function project._load_toolchains() -- load the project file first if has not been loaded? local ok, errors = project._load() @@ -338,7 +338,7 @@ function project._load_toolchains(opt) -- make toolchain instances local toolchains = {} for toolchain_name, toolchain_info in pairs(results) do - toolchains[toolchain_name] = toolchain.new(toolchain_name, toolchain_info, opt) + toolchains[toolchain_name] = toolchain_info end return toolchains end @@ -671,6 +671,20 @@ function project._sort_targets(targets, ordertargets, targetrefs, target) end end +-- get project toolchain infos (@note only with toolchain info) +function project._toolchains() + local toolchains = project._TOOLCHAINS + if not toolchains then + local errors + toolchains, errors = project._load_toolchains() + if not toolchains then + os.raise(errors) + end + project._TOOLCHAINS = toolchains + end + return toolchains +end + -- get project apis function project.apis() @@ -1023,24 +1037,15 @@ end -- get the given toolchain function project.toolchain(name, opt) - return project.toolchains(opt)[name] + local info = project._toolchains()[name] + if info then + return toolchain.load_withinfo(name, info, opt) + end end --- get project toolchains -function project.toolchains(opt) - opt = opt or {} - local key = "key_" .. (opt.plat or "") .. "_" .. (opt.arch or "") - project._TOOLCHAINS = project._TOOLCHAINS or {} - local toolchains = project._TOOLCHAINS[key] - if not toolchains then - local errors - toolchains, errors = project._load_toolchains(opt) - if not toolchains then - os.raise(errors) - end - project._TOOLCHAINS[key] = toolchains - end - return toolchains +-- get project toolchains list +function project.toolchains() + return table.keys(project._toolchains()) end -- get the given task @@ -1050,10 +1055,7 @@ end -- get tasks function project.tasks() - if not project._TASKS then - - -- load tasks local tasks, errors = project._load_tasks() if not tasks then os.raise(errors) @@ -1065,10 +1067,7 @@ end -- get packages function project.packages() - if not project._PACKAGES then - - -- load packages local packages, errors = project._load_packages() if not packages then return nil, errors diff --git a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua index a6dae7f9d..a2041573a 100644 --- a/xmake/core/sandbox/modules/import/core/tool/toolchain.lua +++ b/xmake/core/sandbox/modules/import/core/tool/toolchain.lua @@ -31,7 +31,7 @@ local raise = require("sandbox/modules/raise") function sandbox_core_tool_toolchain.list() local names = table.copy(platform.toolchains()) if os.isfile(os.projectfile()) then - for name, _ in pairs(project.toolchains()) do + for _, name in ipairs(project.toolchains()) do table.insert(names, name) end end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index bc152a3f6..a411b4db5 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,12 +36,13 @@ local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info, plat, arch) +function _instance.new(name, info, plat, arch, configs) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info instance._PLAT = plat instance._ARCH = arch + instance._CONFIGS = configs return instance end @@ -192,6 +193,17 @@ function _instance:sdkdir() return config.get("sdk") or self:info():get("sdkdir") end +-- get user config from `set_toolchains("", {configs = {vs = "2018"}})` +function _instance:config(name) + return self._CONFIGS and self._CONFIGS[name] +end + +-- set user config +function _instance:config_set(name, data) + self._CONFIGS = self._CONFIGS or {} + self._CONFIGS[name] = data +end + -- do check, we only check it once for all architectures function _instance:check() local checkok = true @@ -378,6 +390,19 @@ function toolchain._interpreter() return interp end +-- get cache key +function toolchain._cachekey(name, plat, arch, configs) + local cachekey = name .. plat .. arch + local configs = configs + if configs then + for _, k in ipairs(table.orderkeys(configs)) do + local v = configs[k] + cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) + end + end + return cachekey +end + -- get toolchain apis function toolchain.apis() return @@ -419,14 +444,14 @@ function toolchain.directories() return dirs end --- load the given toolchain +-- load toolchain 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 + local cachekey = toolchain._cachekey(name, plat, arch, opt.configs) -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} @@ -468,17 +493,30 @@ function toolchain.load(name, opt) end -- save instance to the cache - local instance = _instance.new(name, result, plat, arch) + local instance = _instance.new(name, result, plat, arch, opt.configs) toolchain._TOOLCHAINS[cachekey] = instance return instance end --- new toolchain -function toolchain.new(name, info, opt) +-- load toolchain from the give toolchain info +function toolchain.load_withinfo(name, info, 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() - return _instance.new(name, info, plat, arch) + local cachekey = toolchain._cachekey(name, plat, arch, opt.configs) + + -- get it directly from cache dirst + toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} + if toolchain._TOOLCHAINS[cachekey] then + return toolchain._TOOLCHAINS[cachekey] + end + + -- save instance to the cache + local instance = _instance.new(name, info, plat, arch, opt.configs) + toolchain._TOOLCHAINS[cachekey] = instance + return instance end -- return module -- cgit v1.3.1 From 38b7c45ae4b1c58d4734ab027fd520d9a397a383 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 13 Dec 2020 21:00:41 +0800 Subject: pass config to toolchain --- xmake/core/tool/toolchain.lua | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index a411b4db5..0accd5eb4 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,12 +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, plat, arch, configs) +function _instance.new(name, info, configs) local instance = table.inherit(_instance) instance._NAME = name instance._INFO = info - instance._PLAT = plat - instance._ARCH = arch instance._CONFIGS = configs return instance end @@ -53,12 +51,12 @@ end -- get toolchain platform function _instance:plat() - return self._PLAT + return self:config("plat") end -- get toolchain architecture function _instance:arch() - return self._ARCH + return self:config("arch") end -- the current platform is belong to the given platforms? @@ -391,14 +389,11 @@ function toolchain._interpreter() end -- get cache key -function toolchain._cachekey(name, plat, arch, configs) - local cachekey = name .. plat .. arch - local configs = configs - if configs then - for _, k in ipairs(table.orderkeys(configs)) do - local v = configs[k] - cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) - end +function toolchain._cachekey(name, opt) + local cachekey = name + for _, k in ipairs(table.orderkeys(opt)) do + local v = opt[k] + cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) end return cachekey end @@ -449,9 +444,9 @@ 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 = toolchain._cachekey(name, plat, arch, opt.configs) + opt.plat = opt.plat or config.get("plat") or os.host() + opt.arch = opt.arch or config.get("arch") or os.arch() + local cachekey = toolchain._cachekey(name, opt) -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} @@ -493,7 +488,7 @@ function toolchain.load(name, opt) end -- save instance to the cache - local instance = _instance.new(name, result, plat, arch, opt.configs) + local instance = _instance.new(name, result, opt) toolchain._TOOLCHAINS[cachekey] = instance return instance end @@ -503,9 +498,9 @@ function toolchain.load_withinfo(name, info, 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 = toolchain._cachekey(name, plat, arch, opt.configs) + opt.plat = opt.plat or config.get("plat") or os.host() + opt.arch = opt.arch or config.get("arch") or os.arch() + local cachekey = toolchain._cachekey(name, opt) -- get it directly from cache dirst toolchain._TOOLCHAINS = toolchain._TOOLCHAINS or {} @@ -514,7 +509,7 @@ function toolchain.load_withinfo(name, info, opt) end -- save instance to the cache - local instance = _instance.new(name, info, plat, arch, opt.configs) + local instance = _instance.new(name, info, opt) toolchain._TOOLCHAINS[cachekey] = instance return instance end -- cgit v1.3.1 From 0f7d4ef7bf2c3d9e04fc104defb50e8c7f6583f1 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 13 Dec 2020 22:31:27 +0800 Subject: cache toolchain configs --- xmake/core/tool/toolchain.lua | 32 +++++++++++++++++++++++--------- xmake/toolchains/msvc/check.lua | 22 +++++++++++++--------- xmake/toolchains/msvc/load.lua | 31 ++++--------------------------- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 0accd5eb4..4eaa525b0 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,11 +36,16 @@ local sandbox = require("sandbox/sandbox") local sandbox_module = require("sandbox/modules/import/core/sandbox/module") -- new an instance -function _instance.new(name, info, configs) - local instance = table.inherit(_instance) - instance._NAME = name - instance._INFO = info - instance._CONFIGS = configs +function _instance.new(name, info, cachekey, configs) + local instance = table.inherit(_instance) + instance._NAME = name + instance._INFO = info + instance._CACHE = require("sandbox/modules/import/lib/detect/cache") + instance._CACHEKEY = cachekey + instance._CONFIGS = instance._CACHE.load(cachekey) or {} + for k, v in pairs(configs) do + instance._CONFIGS[k] = v + end return instance end @@ -191,17 +196,26 @@ function _instance:sdkdir() return config.get("sdk") or self:info():get("sdkdir") end +-- get cachekey +function _instance:cachekey() + return self._CACHEKEY +end + -- get user config from `set_toolchains("", {configs = {vs = "2018"}})` function _instance:config(name) - return self._CONFIGS and self._CONFIGS[name] + return self._CONFIGS[name] end -- set user config function _instance:config_set(name, data) - self._CONFIGS = self._CONFIGS or {} self._CONFIGS[name] = data end +-- save user configs +function _instance:configs_save() + self._CACHE.save(self:cachekey(), self._CONFIGS) +end + -- do check, we only check it once for all architectures function _instance:check() local checkok = true @@ -488,7 +502,7 @@ function toolchain.load(name, opt) end -- save instance to the cache - local instance = _instance.new(name, result, opt) + local instance = _instance.new(name, result, cachekey, opt) toolchain._TOOLCHAINS[cachekey] = instance return instance end @@ -509,7 +523,7 @@ function toolchain.load_withinfo(name, info, opt) end -- save instance to the cache - local instance = _instance.new(name, info, opt) + local instance = _instance.new(name, info, cachekey, opt) toolchain._TOOLCHAINS[cachekey] = instance return instance end diff --git a/xmake/toolchains/msvc/check.lua b/xmake/toolchains/msvc/check.lua index 33cfc6298..f0fd5f2f6 100644 --- a/xmake/toolchains/msvc/check.lua +++ b/xmake/toolchains/msvc/check.lua @@ -28,13 +28,16 @@ import("lib.detect.find_tool") function _check_vsenv(toolchain) -- have been checked? - local vs = config.get("vs") - if vs and config.get("__vcvarsall") then + local vs = toolchain:config("vs") or config.get("vs") + local vcvars = toolchain:config("vcvars") + if vs and vcvars then return vs end -- find vstudio - local vstudio = find_vstudio({vcvars_ver = config.get("vs_toolset"), sdkver = config.get("vs_sdkver")}) + local vs_toolset = toolchain:config("vs_toolset") or config.get("vs_toolset") + local vs_sdkver = toolchain:config("vs_sdkver") or config.get("vs_sdkver") + local vstudio = find_vstudio({vcvars_ver = vs_toolset, sdkver = vs_sdkver}) if vstudio then -- make order vsver @@ -52,15 +55,15 @@ function _check_vsenv(toolchain) -- get vcvarsall for _, vsver in ipairs(vsvers) do local vcvarsall = (vstudio[vsver] or {}).vcvarsall or {} - local vsenv = vcvarsall[toolchain:arch()] - if vsenv and vsenv.PATH and vsenv.INCLUDE and vsenv.LIB then + local vcvars = vcvarsall[toolchain:arch()] + if vcvars and vcvars.PATH and vcvars.INCLUDE and vcvars.LIB then - -- save vsenv - config.set("__vcvarsall", vcvarsall) + -- save vcvars + toolchain:config_set("vcvars", vcvars) -- check compiler local program = nil - local tool = find_tool("cl.exe", {force = true, envs = vsenv}) + local tool = find_tool("cl.exe", {force = true, envs = vcvars}) if tool then program = tool.program end @@ -76,7 +79,8 @@ end function _check_vstudio(toolchain) local vs = _check_vsenv(toolchain) if vs then - config.set("vs", vs, {readonly = true, force = true}) + toolchain:config_set("vs", vs) + toolchain:configs_save() cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs) else cprint("checking for Microsoft Visual Studio (%s) version ... ${color.nothing}${text.nothing}", toolchain:arch()) diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 3e6dd39d5..95ebe0cf1 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -26,37 +26,14 @@ 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 + -- get vcvars + local vcvars = toolchain:config("vcvars") + if not vcvars then return end - -- get vs environment for the current arch - local arch = toolchain: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 paths for the vs environment - local new = vsenv[name] + local new = vcvars[name] if new then toolchain:add("runenvs", name:upper(), path.splitenv(new)) end -- cgit v1.3.1 From 361eda0cd491f887acfb842567f498a553249ad7 Mon Sep 17 00:00:00 2001 From: ruki Date: Sun, 13 Dec 2020 22:51:02 +0800 Subject: fix load toolchain --- xmake/core/platform/platform.lua | 2 +- xmake/core/project/target.lua | 2 +- xmake/core/tool/tool.lua | 2 +- xmake/core/tool/toolchain.lua | 11 +++++++---- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 4b366fceb..0c2565099 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -195,7 +195,7 @@ function _instance:tool(toolkind) for idx, toolchain_inst in ipairs(toolchains) do program, toolname = toolchain_inst:tool(toolkind) if program then - toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch()} + toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch(), cachekey = toolchain_inst:cachekey()} toolinfo[1] = program toolinfo[2] = toolname toolinfo[3] = toolchain_info diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 257e1b93b..dab501131 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1773,7 +1773,7 @@ function _instance:tool(toolkind) for idx, toolchain_inst in ipairs(toolchains) do program, toolname = toolchain_inst:tool(toolkind) if program then - toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch()} + toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch(), cachekey = toolchain_inst:cachekey()} break end end diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 2bd0ed7ca..5e674fc5d 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -221,7 +221,7 @@ function tool.load(kind, opt) -- load toolchain instance local toolchain_inst if toolchain_info and toolchain_info.name then - toolchain_inst = toolchain.load(toolchain_info.name, {plat = plat, arch = arch}) + toolchain_inst = toolchain.load(toolchain_info.name, {plat = plat, arch = arch, cachekey = toolchain_info.cachekey}) end -- new an instance diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 4eaa525b0..8775090a3 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -404,10 +404,13 @@ end -- get cache key function toolchain._cachekey(name, opt) - local cachekey = name - for _, k in ipairs(table.orderkeys(opt)) do - local v = opt[k] - cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) + local cachekey = opt.cachekey + if not cachekey then + cachekey = name + for _, k in ipairs(table.orderkeys(opt)) do + local v = opt[k] + cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) + end end return cachekey end -- cgit v1.3.1 From 007b2200be5b2a8e5d784829782b56793e93e572 Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 14 Dec 2020 21:00:04 +0800 Subject: improve find_rc --- xmake/core/tool/tool.lua | 4 ---- xmake/modules/detect/tools/find_rc.lua | 16 ++++++---------- xmake/toolchains/msvc/load.lua | 4 +++- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/xmake/core/tool/tool.lua b/xmake/core/tool/tool.lua index 5e674fc5d..bd90c0658 100644 --- a/xmake/core/tool/tool.lua +++ b/xmake/core/tool/tool.lua @@ -229,11 +229,7 @@ function tool.load(kind, opt) if not instance then return nil, errors end - - -- save instance to the cache tool._TOOLS[cachekey] = instance - - -- ok return instance end diff --git a/xmake/modules/detect/tools/find_rc.lua b/xmake/modules/detect/tools/find_rc.lua index 5edd8d69c..a36cd25bb 100644 --- a/xmake/modules/detect/tools/find_rc.lua +++ b/xmake/modules/detect/tools/find_rc.lua @@ -57,16 +57,12 @@ function main(opt) -- -- e.g. C:\Program Files (x86)\Windows Kits\10\bin\10.0.17134.0\x64 -- - local arch = opt.arch or config.arch() or os.arch() - local vcvarsall = config.get("__vcvarsall") - if vcvarsall then - local vcvars = vcvarsall[arch] - if vcvars and vcvars.WindowsSdkDir and vcvars.WindowsSDKVersion then - local bindir = path.join(vcvars.WindowsSdkDir, "bin", vcvars.WindowsSDKVersion, arch) - if os.isdir(bindir) then - opt.paths = opt.paths or {} - table.insert(opt.paths, bindir) - end + local envs = opt.envs + if envs and envs.WindowsSdkDir and envs.WindowsSDKVersion then + local bindir = path.join(envs.WindowsSdkDir, "bin", envs.WindowsSDKVersion, arch) + if os.isdir(bindir) then + opt.paths = opt.paths or {} + table.insert(opt.paths, bindir) end end diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index 95ebe0cf1..b112e2c80 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -35,7 +35,7 @@ function _add_vsenv(toolchain, name) -- get the paths for the vs environment local new = vcvars[name] if new then - toolchain:add("runenvs", name:upper(), path.splitenv(new)) + toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) end end @@ -61,6 +61,8 @@ function main(toolchain) _add_vsenv(toolchain, "LIB") _add_vsenv(toolchain, "INCLUDE") _add_vsenv(toolchain, "LIBPATH") + _add_vsenv(toolchain, "WindowsSdkDir") + _add_vsenv(toolchain, "WindowsSDKVersion") -- add some default flags toolchain:add("cxxflags", "/EHsc") -- cgit v1.3.1 From 4030bf655cd5bbf3af26b682078f4354eb2cb86c Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 14 Dec 2020 22:39:29 +0800 Subject: remove __vcvarsall --- xmake/modules/detect/sdks/find_dotnet.lua | 17 ++++++++++------- xmake/modules/detect/sdks/find_wdk.lua | 22 +++++++--------------- xmake/modules/detect/tools/find_devenv.lua | 12 +++++++----- xmake/plugins/project/vstudio/impl/vs201x.lua | 10 +++++++--- .../project/vstudio/impl/vs201x_vcxproj.lua | 6 +----- xmake/toolchains/msvc/load.lua | 1 + 6 files changed, 33 insertions(+), 35 deletions(-) diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua index bb8180f57..284925f04 100644 --- a/xmake/modules/detect/sdks/find_dotnet.lua +++ b/xmake/modules/detect/sdks/find_dotnet.lua @@ -21,6 +21,7 @@ -- imports import("lib.detect.cache") import("lib.detect.find_file") +import("core.tool.toolchain") import("core.base.option") import("core.base.global") import("core.project.config") @@ -28,14 +29,16 @@ import("core.project.config") -- find dotnet directory function _find_sdkdir(sdkdir) - -- get sdk directory from vsvars + -- get sdk directory from vcvars if not sdkdir then - local arch = config.arch() - local vcvarsall = config.get("__vcvarsall") - if vcvarsall then - sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir - if sdkdir then - sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK") + local msvc = toolchain.load("msvc") + if msvc and msvc:check() then + local vcvars = msvc:config("vcvars") + if vcvars then + sdkdir = vcvars.WindowsSdkDir + if sdkdir then + sdkdir = path.join(path.directory(path.translate(sdkdir)), "NETFXSDK") + end end end end diff --git a/xmake/modules/detect/sdks/find_wdk.lua b/xmake/modules/detect/sdks/find_wdk.lua index f91e9a1b7..d9844146a 100644 --- a/xmake/modules/detect/sdks/find_wdk.lua +++ b/xmake/modules/detect/sdks/find_wdk.lua @@ -24,6 +24,7 @@ import("lib.detect.find_file") import("core.base.option") import("core.base.global") import("core.project.config") +import("core.tool.toolchain") import("detect.sdks.find_vstudio") -- find WDK directory @@ -34,24 +35,15 @@ function _find_sdkdir(sdkdir) sdkdir = os.getenv("WindowsSdkDir") end - -- get sdk directory from vsvars + -- get sdk directory from vcvars if not sdkdir then - local arch = config.arch() or os.arch() - local vcvarsall = config.get("__vcvarsall") - if not vcvarsall then - local vstudio = find_vstudio() - if vstudio then - for _, vsinfo in pairs(vstudio) do - if vsinfo.vcvarsall then - vcvarsall = vsinfo.vcvarsall - break - end - end + local msvc = toolchain.load("msvc") + if msvc and msvc:check() then + local vcvars = msvc:config("vcvars") + if vcvars then + sdkdir = vcvars.WindowsSdkDir end end - if vcvarsall then - sdkdir = (vcvarsall[arch] or {}).WindowsSdkDir - end end return sdkdir end diff --git a/xmake/modules/detect/tools/find_devenv.lua b/xmake/modules/detect/tools/find_devenv.lua index 745c26099..1111c92a3 100644 --- a/xmake/modules/detect/tools/find_devenv.lua +++ b/xmake/modules/detect/tools/find_devenv.lua @@ -20,6 +20,7 @@ -- imports import("core.project.config") +import("core.tool.toolchain") -- find devenv -- @@ -48,11 +49,12 @@ function main(opt) -- e.g. C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE -- local program = nil - local vcvarsall = config.get("__vcvarsall") - if vcvarsall then - for _, vsvars in pairs(vcvarsall) do - if vsvars.DevEnvdir and os.isexec(path.join(vsvars.DevEnvdir, "devenv.exe")) then - program = path.join(vsvars.DevEnvdir, "devenv.exe") + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars then + if vcvars.DevEnvdir and os.isexec(path.join(vcvars.DevEnvdir, "devenv.exe")) then + program = path.join(vcvars.DevEnvdir, "devenv.exe") end end end diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index b19ebadc6..f29f77124 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -25,6 +25,7 @@ import("core.project.project") import("core.platform.platform") import("core.tool.compiler") import("core.tool.linker") +import("core.tool.toolchain") import("vs201x_solution") import("vs201x_vcxproj") import("vs201x_vcxproj_filters") @@ -37,9 +38,12 @@ function _make_targetinfo(mode, arch, target) local targetinfo = { mode = mode, arch = (arch == "x86" and "Win32" or "x64") } -- get sdk version - local vcvarsall = config.get("__vcvarsall") - if vcvarsall then - targetinfo.sdkver = (vcvarsall[arch] or {}).WindowsSDKVersion + local msvc = toolchain.load("msvc") + if msvc then + local vcvars = msvc:config("vcvars") + if vcvars then + targetinfo.sdkver = vcvars.WindowsSDKVersion + end end -- save c/c++ precompiled output file (.pch) diff --git a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua index 3a66a31d2..adfc52757 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x_vcxproj.lua @@ -39,10 +39,8 @@ function _get_toolset_ver(targetinfo, vsinfo) return toolset_ver end --- get platform sdk version +-- get platform sdk version from vcvars.WindowsSDKVersion function _get_platform_sdkver(target, vsinfo) - - -- get sdk version for vcvarsall[arch].WindowsSDKVersion local sdkver = nil for _, targetinfo in ipairs(target.info) do sdkver = targetinfo.sdkver @@ -50,8 +48,6 @@ function _get_platform_sdkver(target, vsinfo) break end end - - -- done return sdkver or vsinfo.sdk_version end diff --git a/xmake/toolchains/msvc/load.lua b/xmake/toolchains/msvc/load.lua index b112e2c80..a1d7c754d 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -61,6 +61,7 @@ function main(toolchain) _add_vsenv(toolchain, "LIB") _add_vsenv(toolchain, "INCLUDE") _add_vsenv(toolchain, "LIBPATH") + -- find_rc.lua need them _add_vsenv(toolchain, "WindowsSdkDir") _add_vsenv(toolchain, "WindowsSDKVersion") -- cgit v1.3.1 From a6f93e44186006e0ee73450937608ec24fef192e Mon Sep 17 00:00:00 2001 From: ruki Date: Mon, 14 Dec 2020 22:43:43 +0800 Subject: add multivs tests --- tests/apis/toolchain_multivs/.gitignore | 8 ++++++++ tests/apis/toolchain_multivs/src/main.cpp | 9 +++++++++ tests/apis/toolchain_multivs/src/test.asm | 1 + tests/apis/toolchain_multivs/src/test.rc | 0 tests/apis/toolchain_multivs/test.lua | 7 +++++++ tests/apis/toolchain_multivs/xmake.lua | 18 ++++++++++++++++++ xmake/core/project/target.lua | 2 +- xmake/core/sandbox/modules/import/lib/detect/cache.lua | 4 ---- xmake/core/tool/toolchain.lua | 7 ++----- 9 files changed, 46 insertions(+), 10 deletions(-) create mode 100644 tests/apis/toolchain_multivs/.gitignore create mode 100644 tests/apis/toolchain_multivs/src/main.cpp create mode 100644 tests/apis/toolchain_multivs/src/test.asm create mode 100644 tests/apis/toolchain_multivs/src/test.rc create mode 100644 tests/apis/toolchain_multivs/test.lua create mode 100644 tests/apis/toolchain_multivs/xmake.lua diff --git a/tests/apis/toolchain_multivs/.gitignore b/tests/apis/toolchain_multivs/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/toolchain_multivs/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/toolchain_multivs/src/main.cpp b/tests/apis/toolchain_multivs/src/main.cpp new file mode 100644 index 000000000..7c435d251 --- /dev/null +++ b/tests/apis/toolchain_multivs/src/main.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/apis/toolchain_multivs/src/test.asm b/tests/apis/toolchain_multivs/src/test.asm new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/apis/toolchain_multivs/src/test.asm @@ -0,0 +1 @@ + diff --git a/tests/apis/toolchain_multivs/src/test.rc b/tests/apis/toolchain_multivs/src/test.rc new file mode 100644 index 000000000..e69de29bb diff --git a/tests/apis/toolchain_multivs/test.lua b/tests/apis/toolchain_multivs/test.lua new file mode 100644 index 000000000..795df5c95 --- /dev/null +++ b/tests/apis/toolchain_multivs/test.lua @@ -0,0 +1,7 @@ +function test_multivs(t) + if is_subhost("windows") then + t:build() + else + return t:skip("wrong host platform") + end +end diff --git a/tests/apis/toolchain_multivs/xmake.lua b/tests/apis/toolchain_multivs/xmake.lua new file mode 100644 index 000000000..4e61a20a1 --- /dev/null +++ b/tests/apis/toolchain_multivs/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +rule("vs2015_x86") + before_load(function (target) + target:set("arch", "x86") + target:set("toolchains", "msvc", {vs = "2015"}) + end) + +target("testvs_vs2015_x86") + set_kind("binary") + add_files("src/*.cpp", "src/*.rc") + add_rules("vs2015_x86") + +target("testvs") + set_kind("binary") + add_files("src/*.cpp", "src/*.rc") + + diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index dab501131..bb6516767 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1745,7 +1745,7 @@ function _instance:tool(toolkind) end -- get tool program - local key = toolkind .. "_" .. self:plat() .. "_" .. self:arch() + local key = self:name() .. "_" .. toolkind .. "_" .. self:plat() .. "_" .. self:arch() local program, toolname, toolchain_info local toolinfo = tools[key] if toolinfo == nil then diff --git a/xmake/core/sandbox/modules/import/lib/detect/cache.lua b/xmake/core/sandbox/modules/import/lib/detect/cache.lua index de2468bf9..f4eb7445d 100644 --- a/xmake/core/sandbox/modules/import/lib/detect/cache.lua +++ b/xmake/core/sandbox/modules/import/lib/detect/cache.lua @@ -34,8 +34,6 @@ local raise = require("sandbox/modules/raise") -- get detect cache instance function sandbox_lib_detect_cache._instance() - - -- get it local detectcache = sandbox_lib_detect_cache._INSTANCE or cache(os.isfile(project.rootfile()) and "local.detect" or "memory.detect") sandbox_lib_detect_cache._INSTANCE = detectcache return detectcache @@ -56,8 +54,6 @@ function sandbox_lib_detect_cache.load(name) cacheinfo = {} detectcache:set(name, cacheinfo) end - - -- ok? return cacheinfo end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index 8775090a3..adb17c865 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -352,12 +352,9 @@ function _instance:_checktool(toolkind, toolpath) end end - -- init cache key - local cachekey = "toolchain_" .. self:plat() .. "_" .. self:arch() - -- find tool program local program, toolname - local tool = find_tool(toolpath, {cachekey = cachekey, program = toolpath, paths = self:bindir(), envs = self:get("runenvs")}) + local tool = find_tool(toolpath, {cachekey = self:cachekey(), program = toolpath, paths = self:bindir(), envs = self:get("runenvs")}) if tool then program = tool.program toolname = tool.name @@ -406,7 +403,7 @@ end function toolchain._cachekey(name, opt) local cachekey = opt.cachekey if not cachekey then - cachekey = name + cachekey = "toolchain_" .. name for _, k in ipairs(table.orderkeys(opt)) do local v = opt[k] cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) -- cgit v1.3.1 From 99a7d26748e8afa84fa7123344f6aa4d24a1be93 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Dec 2020 00:44:32 +0800 Subject: fix check vs --- xmake/core/platform/platform.lua | 5 ++++- xmake/core/project/target.lua | 5 ++++- xmake/core/tool/toolchain.lua | 14 ++++++++++++++ xmake/toolchains/msvc/check.lua | 3 +++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 0c2565099..dda45956d 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -195,7 +195,10 @@ function _instance:tool(toolkind) for idx, toolchain_inst in ipairs(toolchains) do program, toolname = toolchain_inst:tool(toolkind) if program then - toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch(), cachekey = toolchain_inst:cachekey()} + toolchain_info = {name = toolchain_inst:name(), + plat = toolchain_inst:plat(), + arch = toolchain_inst:arch(), + cachekey = toolchain_inst:cachekey()} toolinfo[1] = program toolinfo[2] = toolname toolinfo[3] = toolchain_info diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index bb6516767..0a5a67ddf 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1773,7 +1773,10 @@ function _instance:tool(toolkind) for idx, toolchain_inst in ipairs(toolchains) do program, toolname = toolchain_inst:tool(toolkind) if program then - toolchain_info = {name = toolchain_inst:name(), plat = toolchain_inst:plat(), arch = toolchain_inst:arch(), cachekey = toolchain_inst:cachekey()} + toolchain_info = {name = toolchain_inst:name(), + plat = toolchain_inst:plat(), + arch = toolchain_inst:arch(), + cachekey = toolchain_inst:cachekey()} break end end diff --git a/xmake/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index adb17c865..327be29ed 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -46,6 +46,15 @@ function _instance.new(name, info, cachekey, configs) for k, v in pairs(configs) do instance._CONFIGS[k] = v end + -- is global toolchain for the whole platform? + configs.plat = nil + configs.arch = nil + configs.cachekey = nil + local plat = config.get("plat") or os.host() + local arch = config.get("arch") or os.arch() + if instance:is_plat(plat) and instance:is_arch(arch) and #table.keys(configs) == 0 then + instance._CONFIGS.__global = true + end return instance end @@ -137,6 +146,11 @@ function _instance:standalone() return self:kind() == "standalone" end +-- global toolchain for whole platform +function _instance:global() + return self:config("__global") +end + -- get the run environments function _instance:runenvs() local runenvs = self._RUNENVS diff --git a/xmake/toolchains/msvc/check.lua b/xmake/toolchains/msvc/check.lua index f0fd5f2f6..731836f88 100644 --- a/xmake/toolchains/msvc/check.lua +++ b/xmake/toolchains/msvc/check.lua @@ -79,6 +79,9 @@ end function _check_vstudio(toolchain) local vs = _check_vsenv(toolchain) if vs then + if toolchain:global() then + config.set("vs", vs, {force = true, readonly = true}) + end toolchain:config_set("vs", vs) toolchain:configs_save() cprint("checking for Microsoft Visual Studio (%s) version ... ${color.success}%s", toolchain:arch(), vs) -- cgit v1.3.1 From 36c64e2b54268d7dfb4d59456996ae55abcb7372 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Dec 2020 00:52:26 +0800 Subject: fix find_lib --- xmake/modules/detect/tools/find_lib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua index f3c5806ee..741f6a091 100644 --- a/xmake/modules/detect/tools/find_lib.lua +++ b/xmake/modules/detect/tools/find_lib.lua @@ -51,8 +51,8 @@ function main(opt) io.writefile(sourcefile, "int test(void)\n{return 0;}") -- check it - local cl = assert(find_tool("cl")) - local link = assert(find_tool("link")) + local cl = assert(find_tool("cl", opt)) + local link = assert(find_tool("link", opt)) os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) os.runv(link.program, {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs}) verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs}) -- cgit v1.3.1 From dcdd8e5712a863fe225539a09671a7a6a73d60b6 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 15 Dec 2020 00:55:48 +0800 Subject: fix find_lib --- xmake/modules/detect/tools/find_lib.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua index 741f6a091..b01960e25 100644 --- a/xmake/modules/detect/tools/find_lib.lua +++ b/xmake/modules/detect/tools/find_lib.lua @@ -51,8 +51,8 @@ function main(opt) io.writefile(sourcefile, "int test(void)\n{return 0;}") -- check it - local cl = assert(find_tool("cl", opt)) - local link = assert(find_tool("link", opt)) + local cl = assert(find_tool("cl", {envs = opt.envs})) + local link = assert(find_tool("link", {envs = opt.envs})) os.runv(cl.program, {"-c", "-Fo" .. objectfile, sourcefile}, {envs = opt.envs}) os.runv(link.program, {"-lib", "-out:" .. libraryfile, objectfile}, {envs = opt.envs}) verinfo = os.iorunv(program, {"-list", libraryfile}, {envs = opt.envs}) -- cgit v1.3.1 From b3d4c235f88fb14f0aa42c2704727a104ab33fd2 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 00:45:51 +0800 Subject: improve toolchain for xcode --- xmake/modules/detect/sdks/find_xcode.lua | 11 +---------- xmake/rules/xcode/info_plist/xmake.lua | 8 +++++++- xmake/rules/xcode/storyboard/xmake.lua | 13 ++++++++----- xmake/rules/xcode/xcassets/xmake.lua | 13 ++++++++----- xmake/toolchains/xcode/check.lua | 20 ++++++++++---------- xmake/toolchains/xcode/load_iphoneos.lua | 4 ++-- xmake/toolchains/xcode/load_macosx.lua | 4 ++-- xmake/toolchains/xcode/load_watchos.lua | 4 ++-- 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 1177685a5..a42ee1985 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -147,19 +147,12 @@ function main(sdkdir, opt) local plat = opt.plat or config.get("plat") or "macosx" local arch = opt.arch or config.get("arch") or "x86_64" - -- get xcode sdk version - local xcode_sdkver = (plat == config.plat()) and config.get("xcode_sdkver") - if not xcode_sdkver then - xcode_sdkver = config.get("xcode_sdkver_" .. plat) - end - -- find xcode - local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver or xcode_sdkver, plat, arch) + local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver, plat, arch) if xcode and xcode.sdkdir then -- save to config config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - config.set("xcode_sdkver_" .. plat, xcode.sdkver, {force = true, readonly = true}) config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true}) config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true}) @@ -191,7 +184,5 @@ function main(sdkdir, opt) -- save to cache cacheinfo.xcode = xcode or false cache.save(key, cacheinfo) - - -- ok? return xcode end diff --git a/xmake/rules/xcode/info_plist/xmake.lua b/xmake/rules/xcode/info_plist/xmake.lua index 5b36277d4..9d8d47731 100644 --- a/xmake/rules/xcode/info_plist/xmake.lua +++ b/xmake/rules/xcode/info_plist/xmake.lua @@ -31,6 +31,7 @@ rule("xcode.info_plist") import("core.base.option") import("core.theme.theme") import("core.project.depend") + import("core.tool.toolchain") import("private.utils.progress") -- check @@ -60,8 +61,13 @@ rule("xcode.info_plist") PRODUCT_NAME = target:name(), PRODUCT_DISPLAY_NAME = target:name(), CURRENT_PROJECT_VERSION = target:version() and tostring(target:version()) or "1.0", - MACOSX_DEPLOYMENT_TARGET = get_config("target_minver_macosx") } + if target:is_plat("macosx") then + local toolchain_xcode = toolchain.load("xcode", {plat = target:plat(), arch = target:arch()}) + if toolchain_xcode then + maps.MACOSX_DEPLOYMENT_TARGET = toolchain_xcode:config("target_minver") + end + end if target:rule("xcode.bundle") then maps.PRODUCT_BUNDLE_PACKAGE_TYPE = "BNDL" elseif target:rule("xcode.framework") then diff --git a/xmake/rules/xcode/storyboard/xmake.lua b/xmake/rules/xcode/storyboard/xmake.lua index 83b04fbb0..95a9c9aed 100644 --- a/xmake/rules/xcode/storyboard/xmake.lua +++ b/xmake/rules/xcode/storyboard/xmake.lua @@ -31,6 +31,7 @@ rule("xcode.storyboard") import("core.base.option") import("core.theme.theme") import("core.project.depend") + import("core.tool.toolchain") import("private.utils.progress") -- get xcode sdk directory @@ -57,14 +58,16 @@ rule("xcode.storyboard") os.tryrm(base_lproj) -- do compile - local target_minver + local target_minver = nil + local toolchain_xcode = toolchain.load("xcode", {plat = target:plat(), arch = target:arch()}) + if toolchain_xcode then + target_minver = toolchain_xcode:config("target_minver") + end local argv = {"--errors", "--warnings", "--notices", "--auto-activate-custom-fonts", "--output-format", "human-readable-text"} - if is_plat("macosx") then - target_minver = get_config("target_minver_macosx") + if target:is_plat("macosx") then table.insert(argv, "--target-device") table.insert(argv, "mac") - elseif is_plat("iphoneos") then - target_minver = get_config("target_minver_iphoneos") + elseif target:is_plat("iphoneos") then table.insert(argv, "--target-device") table.insert(argv, "iphone") table.insert(argv, "--target-device") diff --git a/xmake/rules/xcode/xcassets/xmake.lua b/xmake/rules/xcode/xcassets/xmake.lua index 5c1912dd4..31c26a56d 100644 --- a/xmake/rules/xcode/xcassets/xmake.lua +++ b/xmake/rules/xcode/xcassets/xmake.lua @@ -31,6 +31,7 @@ rule("xcode.xcassets") import("core.base.option") import("core.theme.theme") import("core.project.depend") + import("core.tool.toolchain") import("private.utils.progress") -- get xcode sdk directory @@ -60,16 +61,18 @@ rule("xcode.xcassets") io.writefile(assetcatalog_generated_info_plist, "") -- do compile - local target_minver + local target_minver = nil + local toolchain_xcode = toolchain.load("xcode", {plat = target:plat(), arch = target:arch()}) + if toolchain_xcode then + target_minver = toolchain_xcode:config("target_minver") + end local argv = {"--warnings", "--notices", "--output-format", "human-readable-text"} - if is_plat("macosx") then - target_minver = get_config("target_minver_macosx") + if target:is_plat("macosx") then table.insert(argv, "--target-device") table.insert(argv, "mac") table.insert(argv, "--platform") table.insert(argv, "macosx") - elseif is_plat("iphoneos") then - target_minver = get_config("target_minver_iphoneos") + elseif target:is_plat("iphoneos") then table.insert(argv, "--target-device") table.insert(argv, "iphone") table.insert(argv, "--target-device") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 579def16c..c815cf5d0 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -27,8 +27,13 @@ import("detect.sdks.find_xcode") function main(toolchain) -- find xcode - local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, plat = toolchain:plat(), arch = toolchain:arch()}) + local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") + local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, + sdkver = xcode_sdkver, + plat = toolchain:plat(), + arch = toolchain:arch()}) if xcode then + xcode_sdkver = xcode.sdkver config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) else return false @@ -44,14 +49,7 @@ function main(toolchain) -- target("test") -- set_toolchains("xcode", {plat = os.host(), arch = os.arch()}) -- - local xcode_sdkver = toolchain:is_plat(config.plat()) and config.get("xcode_sdkver") - if not xcode_sdkver then - xcode_sdkver = config.get("xcode_sdkver_" .. toolchain:plat()) - end - local target_minver = toolchain:is_plat(config.plat()) and config.get("target_minver") - if not target_minver then - target_minver = config.get("target_minver_" .. toolchain:plat()) - end + local target_minver = toolchain:config("target_minver") and config.get("target_minver") if xcode_sdkver and not target_minver then target_minver = xcode_sdkver if toolchain:is_plat("macosx") then @@ -61,6 +59,8 @@ function main(toolchain) end end end - config.set("target_minver_" .. toolchain:plat(), target_minver) + toolchain:config_set("xcode_sdkver", xcode_sdkver) + toolchain:config_set("target_minver", target_minver) + toolchain:configs_save() return true end diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index cbae31f91..e399f290a 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -32,7 +32,7 @@ function main(toolchain) local platname = simulator and "iPhoneSimulator" or "iPhoneOS" -- init target minimal version - local target_minver = config.get("target_minver_iphoneos") + local target_minver = toolchain:config("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 @@ -40,7 +40,7 @@ function main(toolchain) -- init the xcode sdk directory local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver_iphoneos") + local xcode_sdkver = toolchain:config("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++ diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index 8b5241b45..86bd03252 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -26,11 +26,11 @@ function main(toolchain) -- init flags for architecture local arch = toolchain:arch() - local target_minver = config.get("target_minver_macosx") + local target_minver = toolchain:config("target_minver") -- init flags for the xcode sdk directory local xcode_dir = config.get("xcode") - local xcode_sdkver = config.get("xcode_sdkver_macosx") + local xcode_sdkver = toolchain:config("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" diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index 6efa6f547..08121277e 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -32,12 +32,12 @@ function main(toolchain) local platname = simulator and "WatchSimulator" or "WatchOS" -- init target minimal version - local target_minver = config.get("target_minver_watchos") + local target_minver = toolchain:config("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_watchos") + local xcode_sdkver = toolchain:config("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++ -- cgit v1.3.1 From f3b3357ddad20367ff94e8b984a525a703d5947f Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:34:31 +0800 Subject: improve check platform --- tests/projects/other/multiplats/src/main.c | 7 +++++++ tests/projects/other/multiplats/test.lua | 8 ++++++++ tests/projects/other/multiplats/xmake.lua | 15 +++++++++++++++ xmake/actions/config/main.lua | 22 +++++++++++----------- xmake/core/platform/platform.lua | 10 ++++++++++ xmake/platforms/iphoneos/xmake.lua | 1 + 6 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 tests/projects/other/multiplats/src/main.c create mode 100644 tests/projects/other/multiplats/test.lua create mode 100644 tests/projects/other/multiplats/xmake.lua diff --git a/tests/projects/other/multiplats/src/main.c b/tests/projects/other/multiplats/src/main.c new file mode 100644 index 000000000..9ae580511 --- /dev/null +++ b/tests/projects/other/multiplats/src/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char** argv) +{ + printf("hello world!\n"); + return 0; +} diff --git a/tests/projects/other/multiplats/test.lua b/tests/projects/other/multiplats/test.lua new file mode 100644 index 000000000..196797077 --- /dev/null +++ b/tests/projects/other/multiplats/test.lua @@ -0,0 +1,8 @@ +function main(t) + if is_host("macosx") then + os.exec("xmake f -c -vD") + os.exec("xmake -rvD") + os.exec("xmake f -c -vD -p iphoneos") + os.exec("xmake -rvD") + end +end diff --git a/tests/projects/other/multiplats/xmake.lua b/tests/projects/other/multiplats/xmake.lua new file mode 100644 index 000000000..e8fbbb372 --- /dev/null +++ b/tests/projects/other/multiplats/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") +target("test_host") + set_kind("binary") + add_files("src/*.c") + +target("test_iphoneos") + set_kind("binary") + add_files("src/*.c") + set_plat("iphoneos") + +target("test_iphoneos_armv7") + set_kind("binary") + add_files("src/*.c") + set_plat("iphoneos") + set_arch("armv7") diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 8490dd4e3..b3aeeb9a3 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -141,23 +141,23 @@ function _check_target_toolchains() -- check toolchains configuration for all target in the current project -- @note we must check targets after loading options for _, target in pairs(project.targets()) do - if target:get("enabled") ~= false and (target:get("toolchains") or not target:is_plat(config.get("plat"))) then + if target:get("enabled") ~= false and (target:get("toolchains") or + not target:is_plat(config.get("plat")) or + not target:is_arch(config.get("arch"))) then local target_toolchains = target:get("toolchains") if target_toolchains then target_toolchains = hashset.from(table.wrap(target_toolchains)) - end - for _, toolchain_inst in pairs(target:toolchains()) do - -- check toolchains for `target/set_toolchains()` - if target_toolchains then + for _, toolchain_inst in pairs(target:toolchains()) do + -- check toolchains for `target/set_toolchains()` if not toolchain_inst:check() and target_toolchains:has(toolchain_inst:name()) then raise("toolchain(\"%s\"): not found!", toolchain_inst:name()) end - else - -- check platform toolchains for `target/set_plat()` - local ok, errors = target:platform():check() - if not ok then - raise(errors) - end + end + else + -- check platform toolchains for `target/set_plat()` + local ok, errors = target:platform():check() + if not ok then + raise(errors) end end end diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index dda45956d..4d0aa8fd0 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -52,6 +52,16 @@ function _instance:arch() return self._ARCH or config.get("arch") end +-- set platform architecture +function _instance:arch_set(arch) + if self:arch() ~= arch then + -- we need clean the dirty cache if architecture has been changed + platform._PLATFORMS[self:name() .. "_" .. self:arch()] = nil + platform._PLATFORMS[self:name() .. "_" .. arch] = self + self._ARCH = arch + end +end + -- set the value to the platform configuration function _instance:set(name, ...) self._INFO:apival_set(name, ...) diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 4fbb4e2b2..af6eb8e18 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -42,6 +42,7 @@ platform("iphoneos") local arch = config.get("arch") if not arch then config.set("arch", "arm64") + platform:arch_set("arm64") cprint("checking for architecture ... ${color.success}%s", config.get("arch")) end end) -- cgit v1.3.1 From 207b4e753a4bed1f75836b78180411442103a9cd Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:43:28 +0800 Subject: add find_platform --- xmake/modules/private/detect/find_platform.lua | 146 +++++++++++++++++++++++++ xmake/platforms/android/xmake.lua | 10 -- xmake/platforms/bsd/xmake.lua | 10 -- xmake/platforms/cross/xmake.lua | 48 -------- xmake/platforms/cygwin/xmake.lua | 10 -- xmake/platforms/iphoneos/xmake.lua | 11 -- xmake/platforms/linux/xmake.lua | 10 -- xmake/platforms/macosx/xmake.lua | 10 -- xmake/platforms/mingw/xmake.lua | 19 ---- xmake/platforms/msys/xmake.lua | 10 -- xmake/platforms/wasm/xmake.lua | 10 -- xmake/platforms/watchos/xmake.lua | 10 -- xmake/platforms/windows/xmake.lua | 10 -- 13 files changed, 146 insertions(+), 168 deletions(-) create mode 100644 xmake/modules/private/detect/find_platform.lua diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua new file mode 100644 index 000000000..a18849b82 --- /dev/null +++ b/xmake/modules/private/detect/find_platform.lua @@ -0,0 +1,146 @@ +--!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_platform.lua +-- + +-- imports +import("core.project.config") +import("detect.sdks.find_cross_toolchain") + +-- find platform +function _find_plat(plat) + plat = plat or config.get("plat") + if not plat then + plat = os.subhost() + if plat == "msys" then + local msystem = os.getenv("MSYSTEM") + if msystem and msystem:lower():find("mingw", 1, true) then + plat = "mingw" + end + end + end + return plat +end + +-- find architecture for cross platform +function _find_arch_from_cross() + local cross = config.get("cross") + if not cross then + local cross_toolchain = find_cross_toolchain(config.get("sdk"), {bindir = config.get("bin")}) + if cross_toolchain then + cross = cross_toolchain.cross + end + end + local arch = "none" + if cross then + if cross:find("aarch64", 1, true) then + arch = "arm64" + elseif cross:find("arm", 1, true) then + arch = "arm" + elseif cross:find("mips64", 1, true) then + arch = "mips64" + elseif cross:find("mips", 1, true) then + arch = "mips" + elseif cross:find("riscv64", 1, true) then + arch = "riscv64" + elseif cross:find("riscv", 1, true) then + arch = "riscv" + elseif cross:find("s390x", 1, true) then + arch = "s390x" + elseif cross:find("powerpc64", 1, true) then + arch = "ppc64" + elseif cross:find("powerpc", 1, true) then + arch = "ppc" + elseif cross:find("sh4", 1, true) then + arch = "sh4" + elseif cross:find("x86_64", 1, true) then + arch = "x86_64" + elseif cross:find("i386", 1, true) or cross:find("i686", 1, true) then + arch = "i386" + end + end + return arch +end + +-- find architecture +function _find_arch(plat, arch) + arch = arch or config.get("arch") + if not arch then + if plat == "android" then + arch = "armeabi-v7a" + elseif plat == "iphoneos" then + arch = "arm64" + elseif plat == "watchos" then + arch = "armv7k" + elseif plat == "wasm" then + arch = "wasm32" + elseif plat == "mingw" then + local mingw_chost = nil + if is_subhost("msys") then + mingw_chost = os.getenv("MINGW_CHOST") + end + if mingw_chost == "i686-w64-mingw32" then + arch = "i386" + else + arch = "x86_64" + end + elseif plat == "cross" then + arch = _find_arch_from_cross() + else + arch = os.subarch() + end + end + return arch +end + +-- find default platform and architecture +-- +-- @param opt the argument options, e.g. {plat = "", arch = "", global = true} +-- +-- @return {plat = "", arch = ""} +-- +-- @code +-- +-- find the default platform: +-- local result = find_platform() +-- +-- find the default architecture from the given platform: +-- local result = find_platform({plat = "iphoneos"}) +-- +-- @endcode +-- +function main(opt) + + -- find plat and arch + opt = opt or {} + local plat = _find_plat(opt.plat) + local arch = _find_arch(plat, opt.arch) + + -- save the local configuration if be global + if opt.global then + if not opt.plat and not config.get("plat") then + config.set("plat", plat) + cprint("checking for platform ... ${color.success}%s", plat) + end + if not opt.arch and not config.get("arch") then + config.set("arch", arch) + cprint("checking for architecture ... ${color.success}%s", plat) + end + end + return {plat = plat, arch = arch} +end diff --git a/xmake/platforms/android/xmake.lua b/xmake/platforms/android/xmake.lua index b68df1072..d36c91ba7 100644 --- a/xmake/platforms/android/xmake.lua +++ b/xmake/platforms/android/xmake.lua @@ -42,16 +42,6 @@ platform("android") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "ndk", "rust") diff --git a/xmake/platforms/bsd/xmake.lua b/xmake/platforms/bsd/xmake.lua index 64dacbb3e..f3b7b8044 100644 --- a/xmake/platforms/bsd/xmake.lua +++ b/xmake/platforms/bsd/xmake.lua @@ -39,16 +39,6 @@ platform("bsd") -- set install directory set_installdir("/usr/local") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust", "gfortran", "zig") diff --git a/xmake/platforms/cross/xmake.lua b/xmake/platforms/cross/xmake.lua index a7180396a..fb055977a 100644 --- a/xmake/platforms/cross/xmake.lua +++ b/xmake/platforms/cross/xmake.lua @@ -33,54 +33,6 @@ platform("cross") set_formats("shared", "lib$(name).so") set_formats("symbol", "$(name).sym") - -- on check - on_check(function (platform) - import("core.project.config") - import("detect.sdks.find_cross_toolchain") - - -- detect arch - local arch = config.get("arch") - if not arch then - local cross = config.get("cross") - if not cross then - local cross_toolchain = find_cross_toolchain(config.get("sdk"), {bindir = config.get("bin")}) - if cross_toolchain then - cross = cross_toolchain.cross - end - end - arch = "none" - if cross then - if cross:find("aarch64", 1, true) then - arch = "arm64" - elseif cross:find("arm", 1, true) then - arch = "arm" - elseif cross:find("mips64", 1, true) then - arch = "mips64" - elseif cross:find("mips", 1, true) then - arch = "mips" - elseif cross:find("riscv64", 1, true) then - arch = "riscv64" - elseif cross:find("riscv", 1, true) then - arch = "riscv" - elseif cross:find("s390x", 1, true) then - arch = "s390x" - elseif cross:find("powerpc64", 1, true) then - arch = "ppc64" - elseif cross:find("powerpc", 1, true) then - arch = "ppc" - elseif cross:find("sh4", 1, true) then - arch = "sh4" - elseif cross:find("x86_64", 1, true) then - arch = "x86_64" - elseif cross:find("i386", 1, true) or cross:find("i686", 1, true) then - arch = "i386" - end - end - config.set("arch", arch) - cprint("checking for architecture ... ${color.success}%s", arch) - end - end) - -- set toolchains set_toolchains("envs", "cross") diff --git a/xmake/platforms/cygwin/xmake.lua b/xmake/platforms/cygwin/xmake.lua index 0161ae58c..f2b8722c6 100644 --- a/xmake/platforms/cygwin/xmake.lua +++ b/xmake/platforms/cygwin/xmake.lua @@ -40,16 +40,6 @@ platform("cygwin") -- set install directory set_installdir("/usr/local") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm", "gfortran") diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index af6eb8e18..55c4eeec9 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,17 +36,6 @@ platform("iphoneos") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- on check - on_check(function (platform) - import("core.project.config") - local arch = config.get("arch") - if not arch then - config.set("arch", "arm64") - platform:arch_set("arm64") - cprint("checking for architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "xcode") diff --git a/xmake/platforms/linux/xmake.lua b/xmake/platforms/linux/xmake.lua index 1f70ed35e..40f92e0d6 100644 --- a/xmake/platforms/linux/xmake.lua +++ b/xmake/platforms/linux/xmake.lua @@ -39,16 +39,6 @@ platform("linux") -- set install directory set_installdir("/usr/local") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm", "nasm", "fasm", "cuda", "dlang", "go", "rust", "gfortran", "zig") diff --git a/xmake/platforms/macosx/xmake.lua b/xmake/platforms/macosx/xmake.lua index ebda335c2..e41a3c9da 100644 --- a/xmake/platforms/macosx/xmake.lua +++ b/xmake/platforms/macosx/xmake.lua @@ -39,16 +39,6 @@ platform("macosx") -- set install directory set_installdir("/usr/local") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "xcode", "clang", "gcc", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig") diff --git a/xmake/platforms/mingw/xmake.lua b/xmake/platforms/mingw/xmake.lua index 80c6467e7..0d3320807 100644 --- a/xmake/platforms/mingw/xmake.lua +++ b/xmake/platforms/mingw/xmake.lua @@ -37,25 +37,6 @@ platform("mingw") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") - -- on check - on_check(function (platform) - import("core.project.config") - local arch = config.get("arch") - if not arch then - local mingw_chost = nil - if is_subhost("msys") then - mingw_chost = os.getenv("MINGW_CHOST") - end - if mingw_chost == "i686-w64-mingw32" then - arch = "i386" - else - arch = "x86_64" - end - config.set("arch", arch) - cprint("checking for architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "mingw", "yasm", "nasm", "fasm", "go") diff --git a/xmake/platforms/msys/xmake.lua b/xmake/platforms/msys/xmake.lua index 86901dc08..9cf119bd5 100644 --- a/xmake/platforms/msys/xmake.lua +++ b/xmake/platforms/msys/xmake.lua @@ -40,16 +40,6 @@ platform("msys") -- set install directory set_installdir("/usr/local") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "cross", "gcc", "clang", "yasm", "go", "gfortran") diff --git a/xmake/platforms/wasm/xmake.lua b/xmake/platforms/wasm/xmake.lua index 4b3fb02ac..4676b75fe 100644 --- a/xmake/platforms/wasm/xmake.lua +++ b/xmake/platforms/wasm/xmake.lua @@ -37,16 +37,6 @@ platform("wasm") set_formats("binary", "$(name).html") set_formats("symbol", "$(name).sym") - -- on check - on_check(function (platform) - import("core.project.config") - local arch = config.get("arch") - if not arch then - config.set("arch", "wasm32") - cprint("checking for architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("emcc") diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index b3652e21b..357b7aa12 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -36,16 +36,6 @@ platform("watchos") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- on 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("envs", "xcode") diff --git a/xmake/platforms/windows/xmake.lua b/xmake/platforms/windows/xmake.lua index 813990f84..141f270ce 100644 --- a/xmake/platforms/windows/xmake.lua +++ b/xmake/platforms/windows/xmake.lua @@ -37,16 +37,6 @@ platform("windows") set_formats("binary", "$(name).exe") set_formats("symbol", "$(name).pdb") - -- 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 architecture ... ${color.success}%s", config.get("arch")) - end - end) - -- set toolchains set_toolchains("msvc", "clang", "yasm", "nasm", "cuda", "dlang", "rust", "go", "gfortran", "zig", "tinyc") -- cgit v1.3.1 From acb182fce388de57b6f7262087e1e27ae3d71b41 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:45:37 +0800 Subject: improve to check config --- xmake/actions/config/main.lua | 16 +++++++++++----- xmake/core/platform/platform.lua | 10 ---------- .../sandbox/modules/import/core/platform/platform.lua | 7 +++---- .../core/sandbox/modules/import/core/project/config.lua | 15 --------------- xmake/modules/private/detect/find_platform.lua | 6 +++--- 5 files changed, 17 insertions(+), 37 deletions(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index b3aeeb9a3..6c143bf81 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -26,6 +26,7 @@ import("core.project.config") import("core.project.project") import("core.platform.platform") import("core.project.cache") +import("private.detect.find_platform") import("lib.detect.cache", {alias = "detectcache"}) import("scangen") import("menuconf", {alias = "menuconf_show"}) @@ -268,6 +269,14 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end + -- find default platform and save to configuration + local plat, arch = find_platform({global = true}) + assert(plat == config.plat()) + assert(arch == config.arch()) + + -- load platform instance + local instance_plat = platform.load(plat, arch) + -- merge the checked configure local recheck = _need_check(options_changed or not configcache_loaded or autogen) if recheck then @@ -275,8 +284,8 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- clear detect cache detectcache.clear() - -- check configure - config.check() + -- check platform + instance_plat:check() -- check project options if not trybuild then @@ -284,9 +293,6 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end - -- load platform - platform.load(config.plat()) - -- translate the build directory local buildir = config.get("buildir") if buildir and path.is_absolute(buildir) then diff --git a/xmake/core/platform/platform.lua b/xmake/core/platform/platform.lua index 4d0aa8fd0..5467d7944 100644 --- a/xmake/core/platform/platform.lua +++ b/xmake/core/platform/platform.lua @@ -279,15 +279,6 @@ end -- do check function _instance:check() - -- check platform - local on_check = self:script("check") - if on_check then - 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 @@ -396,7 +387,6 @@ function platform._apis() { -- platform.on_xxx "platform.on_load" - , "platform.on_check" } , keyvalues = { diff --git a/xmake/core/sandbox/modules/import/core/platform/platform.lua b/xmake/core/sandbox/modules/import/core/platform/platform.lua index fab24e1e0..b4a7799b7 100644 --- a/xmake/core/sandbox/modules/import/core/platform/platform.lua +++ b/xmake/core/sandbox/modules/import/core/platform/platform.lua @@ -27,12 +27,11 @@ local raise = require("sandbox/modules/raise") -- load the current platform function sandbox_core_platform.load(plat, arch) - - -- load the platform configure - local ok, errors = platform.load(plat, arch) - if not ok then + local instance, errors = platform.load(plat, arch) + if not instance then raise(errors) end + return instance end -- get the platform os diff --git a/xmake/core/sandbox/modules/import/core/project/config.lua b/xmake/core/sandbox/modules/import/core/project/config.lua index 7adb6f003..ab9db683f 100644 --- a/xmake/core/sandbox/modules/import/core/project/config.lua +++ b/xmake/core/sandbox/modules/import/core/project/config.lua @@ -111,21 +111,6 @@ function sandbox_core_project_config.clear() config.clear() end --- check the configuration -function sandbox_core_project_config.check() - - -- check configuration for the current platform - local instance, errors = platform.load() - if instance then - local ok, errors = instance:check() - if not ok then - raise(errors) - end - else - raise(errors) - end -end - -- dump the configuration function sandbox_core_project_config.dump() config.dump() diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index a18849b82..26a09cc0e 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -110,9 +110,9 @@ end -- find default platform and architecture -- --- @param opt the argument options, e.g. {plat = "", arch = "", global = true} +-- @param opt the argument options, e.g. {plat = "", arch = "", global = true} -- --- @return {plat = "", arch = ""} +-- @return plat, arch -- -- @code -- @@ -142,5 +142,5 @@ function main(opt) cprint("checking for architecture ... ${color.success}%s", plat) end end - return {plat = plat, arch = arch} + return plat, arch end -- cgit v1.3.1 From c0aafd82e851cbdbba2292e02df4ac23d00f9ae6 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:46:19 +0800 Subject: improve to find default platform --- xmake/actions/config/xmake.lua | 15 +-------------- xmake/modules/private/detect/find_platform.lua | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/xmake/actions/config/xmake.lua b/xmake/actions/config/xmake.lua index b1da4ffa5..5745b0206 100644 --- a/xmake/actions/config/xmake.lua +++ b/xmake/actions/config/xmake.lua @@ -18,18 +18,6 @@ -- @file xmake.lua -- --- get the default platform -function get_default_plat() - local subhost = os.subhost() - if subhost == "msys" then - local msystem = os.getenv("MSYSTEM") - if msystem and msystem:lower():find("mingw", 1, true) then - return "mingw" - end - end - return subhost -end - -- define task task("config") @@ -56,8 +44,7 @@ task("config") {'c', "clean", "k", nil , "Clean the cached configure and configure all again." } , {nil, "menu", "k", nil , "Configure project with a menu-driven user interface." } , {category = "."} - , {'p', "plat", "kv", get_default_plat() - , "Compile for the given platform." + , {'p', "plat", "kv", "auto" , "Compile for the given platform." , values = function (complete, opt) -- imports diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index 26a09cc0e..d366260b6 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -139,7 +139,7 @@ function main(opt) end if not opt.arch and not config.get("arch") then config.set("arch", arch) - cprint("checking for architecture ... ${color.success}%s", plat) + cprint("checking for architecture ... ${color.success}%s", arch) end end return plat, arch -- cgit v1.3.1 From c3bec4b1e483f5bcf443cf1a26b3b8bd8cfa2fba Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:49:44 +0800 Subject: improve app rules --- tests/projects/objc/iosapp/xmake.lua | 2 ++ xmake/modules/detect/sdks/find_xcode.lua | 4 +--- xmake/rules/xcode/application/build.lua | 4 ++-- xmake/rules/xcode/application/install.lua | 6 +++--- xmake/rules/xcode/application/load.lua | 6 +++--- xmake/rules/xcode/application/package.lua | 2 +- xmake/rules/xcode/application/run.lua | 4 ++-- xmake/rules/xcode/application/uninstall.lua | 4 ++-- xmake/rules/xcode/bundle/xmake.lua | 4 ++-- xmake/rules/xcode/storyboard/xmake.lua | 2 +- xmake/rules/xcode/xcassets/xmake.lua | 2 +- xmake/toolchains/xcode/check.lua | 2 +- 12 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/projects/objc/iosapp/xmake.lua b/tests/projects/objc/iosapp/xmake.lua index e1e9e6d74..c8becfc3b 100644 --- a/tests/projects/objc/iosapp/xmake.lua +++ b/tests/projects/objc/iosapp/xmake.lua @@ -4,3 +4,5 @@ target("test") add_rules("xcode.application") add_files("src/*.m", "src/**.storyboard", "src/*.xcassets") add_files("src/Info.plist") + set_plat("iphoneos") + set_arch("arm64") diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index a42ee1985..a1ffca6dc 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -96,7 +96,7 @@ function _find_xcode(sdkdir, xcode_sdkver, plat, arch) -- find mobile provision only for iphoneos local mobile_provision - if is_plat("iphoneos") then + if plat == "iphoneos" then local mobile_provisions = codesign.mobile_provisions() if mobile_provisions then mobile_provision = config.get("xcode_mobile_provision") @@ -174,8 +174,6 @@ function main(sdkdir, opt) end end else - - -- trace if opt.verbose or option.get("verbose") then cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}") end diff --git a/xmake/rules/xcode/application/build.lua b/xmake/rules/xcode/application/build.lua index 432ab8bf9..a83e42684 100644 --- a/xmake/rules/xcode/application/build.lua +++ b/xmake/rules/xcode/application/build.lua @@ -41,7 +41,7 @@ function main (target, opt) -- copy target file local binarydir = contentsdir - if is_plat("macosx") then + if target:is_plat("macosx") then binarydir = path.join(contentsdir, "MacOS") end os.vcp(target:targetfile(), path.join(binarydir, path.filename(target:targetfile()))) @@ -72,7 +72,7 @@ function main (target, opt) -- generate embedded.mobileprovision to *.app/embedded.mobileprovision local mobile_provision_embedded = path.join(bundledir, "embedded.mobileprovision") local mobile_provision = target:values("xcode.mobile_provision") or get_config("xcode_mobile_provision") - if mobile_provision and is_plat("iphoneos") then + if mobile_provision and target:is_plat("iphoneos") then os.tryrm(mobile_provision_embedded) local provisions = codesign.mobile_provisions() if provisions then diff --git a/xmake/rules/xcode/application/install.lua b/xmake/rules/xcode/application/install.lua index bc76248ab..dee303ce4 100644 --- a/xmake/rules/xcode/application/install.lua +++ b/xmake/rules/xcode/application/install.lua @@ -62,13 +62,13 @@ end -- main entry function main (target) - if is_plat("iphoneos") then - if is_arch("x86_64", "i386") then + if target:is_plat("iphoneos") then + if target:is_arch("x86_64", "i386") then _install_for_ios_simulator(target) else _install_for_ios(target) end - elseif is_plat("macosx") then + elseif target:is_plat("macosx") then _install_for_macosx(target) end end diff --git a/xmake/rules/xcode/application/load.lua b/xmake/rules/xcode/application/load.lua index e4f76191e..7cf0625f0 100644 --- a/xmake/rules/xcode/application/load.lua +++ b/xmake/rules/xcode/application/load.lua @@ -29,7 +29,7 @@ function main (target) -- get contents and resources directory local contentsdir = bundledir local resourcesdir = bundledir - if is_plat("macosx") then + if target:is_plat("macosx") then contentsdir = path.join(bundledir, "Contents") resourcesdir = path.join(bundledir, "Contents", "Resources") end @@ -41,12 +41,12 @@ function main (target) target:set("filename", target:basename()) -- set install directory - if is_plat("macosx") and not target:get("installdir") then + if target:is_plat("macosx") and not target:get("installdir") then target:set("installdir", "/Applications") end -- add frameworks - if is_plat("macosx") then + if target:is_plat("macosx") then target:add("frameworks", "AppKit") else target:add("frameworks", "UIKit") diff --git a/xmake/rules/xcode/application/package.lua b/xmake/rules/xcode/application/package.lua index d7aa9cbfd..bcf8d60fe 100644 --- a/xmake/rules/xcode/application/package.lua +++ b/xmake/rules/xcode/application/package.lua @@ -40,7 +40,7 @@ end -- main entry function main (target, opt) - if is_plat("iphoneos") then + if target:is_plat("iphoneos") then _package_for_ios(target) end end diff --git a/xmake/rules/xcode/application/run.lua b/xmake/rules/xcode/application/run.lua index 19bbf9b85..14a7c0f12 100644 --- a/xmake/rules/xcode/application/run.lua +++ b/xmake/rules/xcode/application/run.lua @@ -87,9 +87,9 @@ end -- main entry function main (target, opt) - if is_plat("macosx") then + if target:is_plat("macosx") then _run_on_macosx(target, opt) - elseif is_plat("iphoneos") and is_arch("x86_64", "i386") then + elseif target:is_plat("iphoneos") and target:is_arch("x86_64", "i386") then _run_on_simulator(target, opt) else raise("we can only run application on macOS or simulator!") diff --git a/xmake/rules/xcode/application/uninstall.lua b/xmake/rules/xcode/application/uninstall.lua index be06e9fff..421cb8e83 100644 --- a/xmake/rules/xcode/application/uninstall.lua +++ b/xmake/rules/xcode/application/uninstall.lua @@ -38,9 +38,9 @@ end -- main entry function main (target) - if is_plat("iphoneos") then + if target:is_plat("iphoneos") then _uninstall_for_ios(target) - elseif is_plat("macosx") then + elseif target:is_plat("macosx") then _uninstall_for_macosx(target) end end diff --git a/xmake/rules/xcode/bundle/xmake.lua b/xmake/rules/xcode/bundle/xmake.lua index c96fc72ac..9cbd92b6f 100644 --- a/xmake/rules/xcode/bundle/xmake.lua +++ b/xmake/rules/xcode/bundle/xmake.lua @@ -35,7 +35,7 @@ rule("xcode.bundle") -- get contents and resources directory local contentsdir = bundledir local resourcesdir = bundledir - if is_plat("macosx") then + if target:is_plat("macosx") then contentsdir = path.join(bundledir, "Contents") resourcesdir = path.join(bundledir, "Contents", "Resources") end @@ -74,7 +74,7 @@ rule("xcode.bundle") progress.show(opt.progress, "${color.build.target}generating.xcode.$(mode) %s", path.filename(bundledir)) -- copy target file - if is_plat("macosx") then + if target:is_plat("macosx") then os.vcp(target:targetfile(), path.join(contentsdir, "MacOS", path.filename(target:targetfile()))) else os.vcp(target:targetfile(), path.join(contentsdir, path.filename(target:targetfile()))) diff --git a/xmake/rules/xcode/storyboard/xmake.lua b/xmake/rules/xcode/storyboard/xmake.lua index 95a9c9aed..bfa88e6e1 100644 --- a/xmake/rules/xcode/storyboard/xmake.lua +++ b/xmake/rules/xcode/storyboard/xmake.lua @@ -86,7 +86,7 @@ rule("xcode.storyboard") -- do link argv = {"--errors", "--warnings", "--notices", "--auto-activate-custom-fonts", "--output-format", "human-readable-text"} - if is_plat("macosx") then + if target:is_plat("macosx") then table.insert(argv, "--target-device") table.insert(argv, "mac") end diff --git a/xmake/rules/xcode/xcassets/xmake.lua b/xmake/rules/xcode/xcassets/xmake.lua index 31c26a56d..d20fc278c 100644 --- a/xmake/rules/xcode/xcassets/xmake.lua +++ b/xmake/rules/xcode/xcassets/xmake.lua @@ -88,7 +88,7 @@ rule("xcode.xcassets") end table.insert(argv, "--app-icon") table.insert(argv, "AppIcon") - if is_plat("iphoneos") then + if target:is_plat("iphoneos") then table.insert(argv, "--enable-on-demand-resources") table.insert(argv, "YES") table.insert(argv, "--compress-pngs") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index c815cf5d0..d7412e798 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -28,7 +28,7 @@ function main(toolchain) -- find xcode local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") - local xcode = find_xcode(config.get("xcode"), {force = not optional, verbose = true, + local xcode = find_xcode(config.get("xcode"), {force = true, verbose = toolchain:global(), sdkver = xcode_sdkver, plat = toolchain:plat(), arch = toolchain:arch()}) -- cgit v1.3.1 From 1392992e8e941f188238c31ca9282bdd2f3d4531 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 16 Dec 2020 23:56:23 +0800 Subject: fix some old cached configs --- xmake/modules/package/manager/conan/install_package.lua | 7 ++++++- xmake/rules/qt/deploy/macosx.lua | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/xmake/modules/package/manager/conan/install_package.lua b/xmake/modules/package/manager/conan/install_package.lua index 8e7561826..cc7721527 100644 --- a/xmake/modules/package/manager/conan/install_package.lua +++ b/xmake/modules/package/manager/conan/install_package.lua @@ -21,6 +21,7 @@ -- imports import("core.base.option") import("core.project.config") +import("core.tool.toolchain") import("core.platform.platform") import("lib.detect.find_tool") import("devel.git") @@ -219,7 +220,11 @@ function main(name, opt) table.insert(argv, "compiler.runtime=" .. opt.vs_runtime) end elseif opt.plat == "iphoneos" then - local target_minver = config.get("target_minver_iphoneos") + local target_minver = nil + local toolchain_xcode = toolchain.load("xcode", {plat = opt.plat, arch = opt.arch}) + if toolchain_xcode then + target_minver = toolchain_xcode:config("target_minver") + end if target_minver and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "x86") then target_minver = "10" -- iOS 10 is the maximum deployment target for 32-bit targets end diff --git a/xmake/rules/qt/deploy/macosx.lua b/xmake/rules/qt/deploy/macosx.lua index 09d470189..67b9193d3 100644 --- a/xmake/rules/qt/deploy/macosx.lua +++ b/xmake/rules/qt/deploy/macosx.lua @@ -23,12 +23,21 @@ import("core.theme.theme") import("core.base.option") import("core.project.config") import("core.project.depend") +import("core.tool.toolchain") import("lib.detect.find_path") import("private.utils.progress") -- save Info.plist function _save_info_plist(target, info_plist_file) + -- get target minver + local target_minver = nil + local toolchain_xcode = toolchain.load("xcode", {plat = target:plat(), arch = target:arch()}) + if toolchain_xcode then + target_minver = toolchain_xcode:config("target_minver") + end + + -- generate info.plist local name = target:basename() io.writefile(info_plist_file, string.format([[ @@ -59,7 +68,7 @@ function _save_info_plist(target, info_plist_file) NSPrincipalClass NSApplication -]], name, name, name, name, get_config("target_minver_macosx") or (macos.version():major() .. "." .. macos.version():minor()))) +]], name, name, name, name, target_minver or (macos.version():major() .. "." .. macos.version():minor()))) end -- deploy application package for macosx -- cgit v1.3.1 From cd5449d66ce5463202b4ccde6b41edf9486b42f5 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:05:41 +0800 Subject: improve to find plat/arch --- xmake/actions/config/main.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 6c143bf81..c52d2a179 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -195,6 +195,11 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- lock the whole project project.lock() + -- find default platform and save to configuration + local plat, arch = find_platform({global = true}) + assert(plat == config.plat()) + assert(arch == config.arch()) + -- enter menu config local options_changed = false if option.get("menu") then @@ -269,11 +274,6 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end - -- find default platform and save to configuration - local plat, arch = find_platform({global = true}) - assert(plat == config.plat()) - assert(arch == config.arch()) - -- load platform instance local instance_plat = platform.load(plat, arch) -- cgit v1.3.1 From 99fef1222a2e7905ce4ad396c848ffaf0a991849 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:05:59 +0800 Subject: move tests --- tests/apis/toolchain_multivs/.gitignore | 8 -------- tests/apis/toolchain_multivs/src/main.cpp | 9 --------- tests/apis/toolchain_multivs/src/test.asm | 1 - tests/apis/toolchain_multivs/src/test.rc | 0 tests/apis/toolchain_multivs/test.lua | 7 ------- tests/apis/toolchain_multivs/xmake.lua | 18 ------------------ tests/projects/other/multiplats/src/main.c | 7 ------- tests/projects/other/multiplats/test.lua | 8 -------- tests/projects/other/multiplats/xmake.lua | 15 --------------- tests/projects/other/multiplats_vs/.gitignore | 8 ++++++++ tests/projects/other/multiplats_vs/src/main.cpp | 9 +++++++++ tests/projects/other/multiplats_vs/src/test.asm | 1 + tests/projects/other/multiplats_vs/src/test.rc | 0 tests/projects/other/multiplats_vs/test.lua | 7 +++++++ tests/projects/other/multiplats_vs/xmake.lua | 18 ++++++++++++++++++ tests/projects/other/multiplats_xcode/src/main.c | 7 +++++++ tests/projects/other/multiplats_xcode/test.lua | 8 ++++++++ tests/projects/other/multiplats_xcode/xmake.lua | 15 +++++++++++++++ 18 files changed, 73 insertions(+), 73 deletions(-) delete mode 100644 tests/apis/toolchain_multivs/.gitignore delete mode 100644 tests/apis/toolchain_multivs/src/main.cpp delete mode 100644 tests/apis/toolchain_multivs/src/test.asm delete mode 100644 tests/apis/toolchain_multivs/src/test.rc delete mode 100644 tests/apis/toolchain_multivs/test.lua delete mode 100644 tests/apis/toolchain_multivs/xmake.lua delete mode 100644 tests/projects/other/multiplats/src/main.c delete mode 100644 tests/projects/other/multiplats/test.lua delete mode 100644 tests/projects/other/multiplats/xmake.lua create mode 100644 tests/projects/other/multiplats_vs/.gitignore create mode 100644 tests/projects/other/multiplats_vs/src/main.cpp create mode 100644 tests/projects/other/multiplats_vs/src/test.asm create mode 100644 tests/projects/other/multiplats_vs/src/test.rc create mode 100644 tests/projects/other/multiplats_vs/test.lua create mode 100644 tests/projects/other/multiplats_vs/xmake.lua create mode 100644 tests/projects/other/multiplats_xcode/src/main.c create mode 100644 tests/projects/other/multiplats_xcode/test.lua create mode 100644 tests/projects/other/multiplats_xcode/xmake.lua diff --git a/tests/apis/toolchain_multivs/.gitignore b/tests/apis/toolchain_multivs/.gitignore deleted file mode 100644 index 152105761..000000000 --- a/tests/apis/toolchain_multivs/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Xmake cache -.xmake/ -build/ - -# MacOS Cache -.DS_Store - - diff --git a/tests/apis/toolchain_multivs/src/main.cpp b/tests/apis/toolchain_multivs/src/main.cpp deleted file mode 100644 index 7c435d251..000000000 --- a/tests/apis/toolchain_multivs/src/main.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -using namespace std; - -int main(int argc, char** argv) -{ - cout << "hello world!" << endl; - return 0; -} diff --git a/tests/apis/toolchain_multivs/src/test.asm b/tests/apis/toolchain_multivs/src/test.asm deleted file mode 100644 index 8b1378917..000000000 --- a/tests/apis/toolchain_multivs/src/test.asm +++ /dev/null @@ -1 +0,0 @@ - diff --git a/tests/apis/toolchain_multivs/src/test.rc b/tests/apis/toolchain_multivs/src/test.rc deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/apis/toolchain_multivs/test.lua b/tests/apis/toolchain_multivs/test.lua deleted file mode 100644 index 795df5c95..000000000 --- a/tests/apis/toolchain_multivs/test.lua +++ /dev/null @@ -1,7 +0,0 @@ -function test_multivs(t) - if is_subhost("windows") then - t:build() - else - return t:skip("wrong host platform") - end -end diff --git a/tests/apis/toolchain_multivs/xmake.lua b/tests/apis/toolchain_multivs/xmake.lua deleted file mode 100644 index 4e61a20a1..000000000 --- a/tests/apis/toolchain_multivs/xmake.lua +++ /dev/null @@ -1,18 +0,0 @@ -add_rules("mode.debug", "mode.release") - -rule("vs2015_x86") - before_load(function (target) - target:set("arch", "x86") - target:set("toolchains", "msvc", {vs = "2015"}) - end) - -target("testvs_vs2015_x86") - set_kind("binary") - add_files("src/*.cpp", "src/*.rc") - add_rules("vs2015_x86") - -target("testvs") - set_kind("binary") - add_files("src/*.cpp", "src/*.rc") - - diff --git a/tests/projects/other/multiplats/src/main.c b/tests/projects/other/multiplats/src/main.c deleted file mode 100644 index 9ae580511..000000000 --- a/tests/projects/other/multiplats/src/main.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(int argc, char** argv) -{ - printf("hello world!\n"); - return 0; -} diff --git a/tests/projects/other/multiplats/test.lua b/tests/projects/other/multiplats/test.lua deleted file mode 100644 index 196797077..000000000 --- a/tests/projects/other/multiplats/test.lua +++ /dev/null @@ -1,8 +0,0 @@ -function main(t) - if is_host("macosx") then - os.exec("xmake f -c -vD") - os.exec("xmake -rvD") - os.exec("xmake f -c -vD -p iphoneos") - os.exec("xmake -rvD") - end -end diff --git a/tests/projects/other/multiplats/xmake.lua b/tests/projects/other/multiplats/xmake.lua deleted file mode 100644 index e8fbbb372..000000000 --- a/tests/projects/other/multiplats/xmake.lua +++ /dev/null @@ -1,15 +0,0 @@ -add_rules("mode.debug", "mode.release") -target("test_host") - set_kind("binary") - add_files("src/*.c") - -target("test_iphoneos") - set_kind("binary") - add_files("src/*.c") - set_plat("iphoneos") - -target("test_iphoneos_armv7") - set_kind("binary") - add_files("src/*.c") - set_plat("iphoneos") - set_arch("armv7") diff --git a/tests/projects/other/multiplats_vs/.gitignore b/tests/projects/other/multiplats_vs/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/multiplats_vs/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/multiplats_vs/src/main.cpp b/tests/projects/other/multiplats_vs/src/main.cpp new file mode 100644 index 000000000..7c435d251 --- /dev/null +++ b/tests/projects/other/multiplats_vs/src/main.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} diff --git a/tests/projects/other/multiplats_vs/src/test.asm b/tests/projects/other/multiplats_vs/src/test.asm new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/tests/projects/other/multiplats_vs/src/test.asm @@ -0,0 +1 @@ + diff --git a/tests/projects/other/multiplats_vs/src/test.rc b/tests/projects/other/multiplats_vs/src/test.rc new file mode 100644 index 000000000..e69de29bb diff --git a/tests/projects/other/multiplats_vs/test.lua b/tests/projects/other/multiplats_vs/test.lua new file mode 100644 index 000000000..795df5c95 --- /dev/null +++ b/tests/projects/other/multiplats_vs/test.lua @@ -0,0 +1,7 @@ +function test_multivs(t) + if is_subhost("windows") then + t:build() + else + return t:skip("wrong host platform") + end +end diff --git a/tests/projects/other/multiplats_vs/xmake.lua b/tests/projects/other/multiplats_vs/xmake.lua new file mode 100644 index 000000000..4e61a20a1 --- /dev/null +++ b/tests/projects/other/multiplats_vs/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +rule("vs2015_x86") + before_load(function (target) + target:set("arch", "x86") + target:set("toolchains", "msvc", {vs = "2015"}) + end) + +target("testvs_vs2015_x86") + set_kind("binary") + add_files("src/*.cpp", "src/*.rc") + add_rules("vs2015_x86") + +target("testvs") + set_kind("binary") + add_files("src/*.cpp", "src/*.rc") + + diff --git a/tests/projects/other/multiplats_xcode/src/main.c b/tests/projects/other/multiplats_xcode/src/main.c new file mode 100644 index 000000000..9ae580511 --- /dev/null +++ b/tests/projects/other/multiplats_xcode/src/main.c @@ -0,0 +1,7 @@ +#include + +int main(int argc, char** argv) +{ + printf("hello world!\n"); + return 0; +} diff --git a/tests/projects/other/multiplats_xcode/test.lua b/tests/projects/other/multiplats_xcode/test.lua new file mode 100644 index 000000000..196797077 --- /dev/null +++ b/tests/projects/other/multiplats_xcode/test.lua @@ -0,0 +1,8 @@ +function main(t) + if is_host("macosx") then + os.exec("xmake f -c -vD") + os.exec("xmake -rvD") + os.exec("xmake f -c -vD -p iphoneos") + os.exec("xmake -rvD") + end +end diff --git a/tests/projects/other/multiplats_xcode/xmake.lua b/tests/projects/other/multiplats_xcode/xmake.lua new file mode 100644 index 000000000..e8fbbb372 --- /dev/null +++ b/tests/projects/other/multiplats_xcode/xmake.lua @@ -0,0 +1,15 @@ +add_rules("mode.debug", "mode.release") +target("test_host") + set_kind("binary") + add_files("src/*.c") + +target("test_iphoneos") + set_kind("binary") + add_files("src/*.c") + set_plat("iphoneos") + +target("test_iphoneos_armv7") + set_kind("binary") + add_files("src/*.c") + set_plat("iphoneos") + set_arch("armv7") -- cgit v1.3.1 From f699852e87b0b3d784cb9b00029e9c6b96b6224f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:06:49 +0800 Subject: improve test --- tests/projects/objc/iosapp/xmake.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/projects/objc/iosapp/xmake.lua b/tests/projects/objc/iosapp/xmake.lua index c8becfc3b..05f445980 100644 --- a/tests/projects/objc/iosapp/xmake.lua +++ b/tests/projects/objc/iosapp/xmake.lua @@ -5,4 +5,3 @@ target("test") add_files("src/*.m", "src/**.storyboard", "src/*.xcassets") add_files("src/Info.plist") set_plat("iphoneos") - set_arch("arm64") -- cgit v1.3.1 From 2fb94d278e31d0e10870317a4534891148921a0f Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:10:01 +0800 Subject: improve menuconfig --- xmake/actions/config/main.lua | 10 +++++----- xmake/actions/config/menuconf.lua | 15 +++++++++++---- xmake/toolchains/xcode/check.lua | 1 + 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index c52d2a179..6c143bf81 100644 --- a/xmake/actions/config/main.lua +++ b/xmake/actions/config/main.lua @@ -195,11 +195,6 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) -- lock the whole project project.lock() - -- find default platform and save to configuration - local plat, arch = find_platform({global = true}) - assert(plat == config.plat()) - assert(arch == config.arch()) - -- enter menu config local options_changed = false if option.get("menu") then @@ -274,6 +269,11 @@ force to build in current directory via run `xmake -P .`]], os.projectdir()) end end + -- find default platform and save to configuration + local plat, arch = find_platform({global = true}) + assert(plat == config.plat()) + assert(arch == config.arch()) + -- load platform instance local instance_plat = platform.load(plat, arch) diff --git a/xmake/actions/config/menuconf.lua b/xmake/actions/config/menuconf.lua index 67cb1fe69..8d72b2c71 100644 --- a/xmake/actions/config/menuconf.lua +++ b/xmake/actions/config/menuconf.lua @@ -31,6 +31,7 @@ import("core.ui.action") import("core.ui.menuconf") import("core.ui.mconfdialog") import("core.ui.application") +import("private.detect.find_platform") -- the app application local app = application() @@ -227,11 +228,17 @@ function app:_basic_configs(cache) -- make configs by category self._BASIC_CONFIGS = self:_make_configs_by_category("Basic Configuration", options_by_category, cache, function (opt) - -- get default + -- get option + local name = opt[2] or opt[1] local default = opt[4] + local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string" - -- get kind - local kind = (opt[3] == "k" or type(default) == "boolean") and "boolean" or "string" + -- get default platform + if name == "plat" then + default = find_platform() + elseif name == "arch" then + _, default = find_platform() + end -- choice option? local values = opt.values @@ -267,7 +274,7 @@ function app:_basic_configs(cache) end -- make option info - return {name = opt[2] or opt[1], kind = kind, default = default, values = values, description = description} + return {name = name, kind = kind, default = default, values = values, description = description} end) return self._BASIC_CONFIGS end diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index d7412e798..47d267e4e 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -59,6 +59,7 @@ function main(toolchain) end end end + print(toolchain:cachekey(), target_minver) toolchain:config_set("xcode_sdkver", xcode_sdkver) toolchain:config_set("target_minver", target_minver) toolchain:configs_save() -- cgit v1.3.1 From 83e09c0fa0ea1cc9b40860d9f58676b0a4f12a38 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:31:32 +0800 Subject: fix ci --- tests/plugins/project/test.lua | 3 +-- xmake/plugins/project/vstudio/impl/vs201x.lua | 7 ++----- xmake/plugins/project/vsxmake/getinfo.lua | 7 ++----- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 5cc1e7e0e..30fbe323b 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -21,8 +21,7 @@ function test_vsxmake(t) -- set config local arch = os.getenv("platform") or "x86" config.set("arch", arch, {readonly = true, force = true}) - config.check() - platform.load(config.plat()) + platform.load(config.plat()):check() -- create sln & vcxproj local vs = config.get("vs") diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index f29f77124..7bc9f9d45 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -237,15 +237,12 @@ function make(outputdir, vsinfo) -- clear project to reload and recheck it project.clear() - -- check configure - config.check() + -- check platform + platform.load(config.plat()):check() -- check project options project.check() - -- reload platform - platform.load(config.plat()) - -- re-generate configheader generate_configheader() end diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 96b4e18ba..0ba11514c 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -296,15 +296,12 @@ function main(outputdir, vsinfo) -- clear project to reload and recheck it project.clear() - -- check configure - config.check() + -- check platform + platform.load(config.plat()):check() -- check project options project.check() - -- reload platform - platform.load(config.plat()) - -- re-generate configheader generate_configheader() -- cgit v1.3.1 From 55ceaffc18102b40bee2916335303e6861e5cfcb Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:33:09 +0800 Subject: improve to load platform for vs plugin --- tests/plugins/project/test.lua | 2 +- xmake/plugins/project/vstudio/impl/vs201x.lua | 2 +- xmake/plugins/project/vsxmake/getinfo.lua | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 30fbe323b..1aac20088 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -21,7 +21,7 @@ function test_vsxmake(t) -- set config local arch = os.getenv("platform") or "x86" config.set("arch", arch, {readonly = true, force = true}) - platform.load(config.plat()):check() + platform.load(config.plat(), arch):check() -- create sln & vcxproj local vs = config.get("vs") diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index 7bc9f9d45..10784c5ea 100644 --- a/xmake/plugins/project/vstudio/impl/vs201x.lua +++ b/xmake/plugins/project/vstudio/impl/vs201x.lua @@ -238,7 +238,7 @@ function make(outputdir, vsinfo) project.clear() -- check platform - platform.load(config.plat()):check() + platform.load(config.plat(), arch):check() -- check project options project.check() diff --git a/xmake/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 0ba11514c..7a82036bc 100644 --- a/xmake/plugins/project/vsxmake/getinfo.lua +++ b/xmake/plugins/project/vsxmake/getinfo.lua @@ -297,7 +297,7 @@ function main(outputdir, vsinfo) project.clear() -- check platform - platform.load(config.plat()):check() + platform.load(config.plat(), arch):check() -- check project options project.check() -- cgit v1.3.1 From b16614cffa6d77431770e641c56d52355718bd34 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:34:41 +0800 Subject: remove some prints --- xmake/modules/detect/sdks/find_xcode.lua | 6 +++--- xmake/toolchains/xcode/check.lua | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index a1ffca6dc..8416a50b8 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -144,8 +144,8 @@ function main(sdkdir, opt) end -- get plat and arch - local plat = opt.plat or config.get("plat") or "macosx" - local arch = opt.arch or config.get("arch") or "x86_64" + local plat = opt.plat or config.get("plat") or os.host() + local arch = opt.arch or config.get("arch") or os.arch() -- find xcode local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver, plat, arch) @@ -159,7 +159,7 @@ function main(sdkdir, opt) -- trace if opt.verbose or option.get("verbose") then cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir) - cprint("checking for SDK version of Xcode ... ${color.success}%s", xcode.sdkver) + cprint("checking for SDK (%s) version of Xcode ... ${color.success}%s", plat, xcode.sdkver) if xcode.codesign_identity then cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity) else diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 47d267e4e..d7412e798 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -59,7 +59,6 @@ function main(toolchain) end end end - print(toolchain:cachekey(), target_minver) toolchain:config_set("xcode_sdkver", xcode_sdkver) toolchain:config_set("target_minver", target_minver) toolchain:configs_save() -- cgit v1.3.1 From 98bdd72d370d044081667a325c27138b2d61892a Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:34:49 +0800 Subject: improve ci --- .github/workflows/windows.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e3c12f8de..a93e74183 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -57,10 +57,10 @@ jobs: Copy-Item ./scripts/xrepo.bat ./xmake $Env:XMAKE_PROGRAM_DIR = $(Resolve-Path ./xmake) Set-Item -Path Env:Path -Value ($Env:XMAKE_PROGRAM_DIR + ";" + $Env:Path) + xrepo --version xmake show #xmake l -v private.utils.bcsave --rootname='@programdir' -x 'scripts/**|templates/**' xmake xmake lua -v -D tests/run.lua - xrepo --version # build artifacts - name: set release arch name -- cgit v1.3.1 From 8e149f26ccfc93a756074915b5d5f052ba73ed85 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:40:44 +0800 Subject: improve to check xcode --- xmake/modules/detect/sdks/find_xcode.lua | 105 ++++++++++++------------------- xmake/toolchains/xcode/check.lua | 32 ++++++++-- 2 files changed, 68 insertions(+), 69 deletions(-) diff --git a/xmake/modules/detect/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 8416a50b8..4e7a1f677 100644 --- a/xmake/modules/detect/sdks/find_xcode.lua +++ b/xmake/modules/detect/sdks/find_xcode.lua @@ -27,7 +27,7 @@ import("lib.detect.find_directory") import("private.tools.codesign") -- find xcode directory -function _find_sdkdir(sdkdir) +function _find_sdkdir(sdkdir, opt) if sdkdir and os.isdir(sdkdir) then return sdkdir end @@ -35,9 +35,11 @@ function _find_sdkdir(sdkdir) end -- find the sdk version of xcode -function _find_xcode_sdkver(sdkdir, plat, arch) +function _find_xcode_sdkver(sdkdir, opt) -- select platform sdkdir + local plat = opt.plat + local arch = opt.arch local platsdkdir = nil if plat == "iphoneos" then if arch == "i386" or arch == "x86_64" then @@ -65,52 +67,56 @@ function _find_xcode_sdkver(sdkdir, plat, arch) end -- find the xcode toolchain -function _find_xcode(sdkdir, xcode_sdkver, plat, arch) +function _find_xcode(sdkdir, opt) -- find xcode root directory - sdkdir = _find_sdkdir(sdkdir) + sdkdir = _find_sdkdir(sdkdir, opt) if not sdkdir then return {} end -- find the sdk version - local sdkver = xcode_sdkver or _find_xcode_sdkver(sdkdir, plat, arch) + local sdkver = opt.sdkver or _find_xcode_sdkver(sdkdir, opt) if not sdkver then return {} end - -- find codesign identity - local codesign_identity = config.get("xcode_codesign_identity") - if codesign_identity == nil then -- we will disable codesign_identity if be false - codesign_identity = global.get("xcode_codesign_identity") - end - if codesign_identity == nil then - local codesign_identities = codesign.codesign_identities() - if codesign_identities then - for identity, _ in pairs(codesign_identities) do - codesign_identity = identity - break + -- find codesign + if opt.find_codesign then + + -- find codesign identity + local codesign_identity = config.get("xcode_codesign_identity") + if codesign_identity == nil then -- we will disable codesign_identity if be false + codesign_identity = global.get("xcode_codesign_identity") + end + if codesign_identity == nil then + local codesign_identities = codesign.codesign_identities() + if codesign_identities then + for identity, _ in pairs(codesign_identities) do + codesign_identity = identity + break + end end end - end - -- find mobile provision only for iphoneos - local mobile_provision - if plat == "iphoneos" then - local mobile_provisions = codesign.mobile_provisions() - if mobile_provisions then - mobile_provision = config.get("xcode_mobile_provision") - if mobile_provision == nil then -- we will disable mobile_provision if be false - mobile_provision = global.get("xcode_mobile_provision") - end - if mobile_provision == nil then - for provision, _ in pairs(mobile_provisions) do - mobile_provision = provision - break + -- find mobile provision only for iphoneos + local mobile_provision + if opt.plat == "iphoneos" then + local mobile_provisions = codesign.mobile_provisions() + if mobile_provisions then + mobile_provision = config.get("xcode_mobile_provision") + if mobile_provision == nil then -- we will disable mobile_provision if be false + mobile_provision = global.get("xcode_mobile_provision") + end + if mobile_provision == nil then + for provision, _ in pairs(mobile_provisions) do + mobile_provision = provision + break + end + -- valid mobile provision not found? reset it + elseif not mobile_provisions[mobile_provision] then + mobile_provision = nil end - -- valid mobile provision not found? reset it - elseif not mobile_provisions[mobile_provision] then - mobile_provision = nil end end end @@ -121,7 +127,7 @@ end -- -- @param sdkdir the xcode directory -- @param opt the argument options --- e.g. {verbose = true, force = false, sdkver = 19, toolchains_ver = "4.9"} +-- e.g. {verbose = true, force = false, sdkver = 19, find_codesign = true} -- -- @return the xcode toolchain. e.g. {bindir = .., cross = ..} -- @@ -148,36 +154,7 @@ function main(sdkdir, opt) local arch = opt.arch or config.get("arch") or os.arch() -- find xcode - local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt.sdkver, plat, arch) - if xcode and xcode.sdkdir then - - -- save to config - config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true}) - config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true}) - - -- trace - if opt.verbose or option.get("verbose") then - cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir) - cprint("checking for SDK (%s) version of Xcode ... ${color.success}%s", plat, xcode.sdkver) - if xcode.codesign_identity then - cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity) - else - cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}") - end - if plat == "iphoneos" then - if xcode.mobile_provision then - cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision) - else - cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}") - end - end - end - else - if opt.verbose or option.get("verbose") then - cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}") - end - end + local xcode = _find_xcode(sdkdir or config.get("xcode") or global.get("xcode"), opt) -- save to cache cacheinfo.xcode = xcode or false diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index d7412e798..b8707a2a9 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -28,17 +28,37 @@ function main(toolchain) -- find xcode local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") - local xcode = find_xcode(config.get("xcode"), {force = true, verbose = toolchain:global(), + local xcode = find_xcode(config.get("xcode"), {force = true, verbose = true, + find_codesign = toolchain:global(), sdkver = xcode_sdkver, plat = toolchain:plat(), arch = toolchain:arch()}) - if xcode then - xcode_sdkver = xcode.sdkver - config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - else + if not xcode then + cprint("checking for Xcode directory ... ${color.nothing}${text.nothing}") return false end + -- xcode found + xcode_sdkver = xcode.sdkver + if toolchain:global() then + config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) + config.set("xcode_mobile_provision", xcode.mobile_provision, {force = true, readonly = true}) + config.set("xcode_codesign_identity", xcode.codesign_identity, {force = true, readonly = true}) + cprint("checking for Xcode directory ... ${color.success}%s", xcode.sdkdir) + if xcode.codesign_identity then + cprint("checking for Codesign Identity of Xcode ... ${color.success}%s", xcode.codesign_identity) + else + cprint("checking for Codesign Identity of Xcode ... ${color.nothing}${text.nothing}") + end + if toolchain:is_plat("iphoneos") then + if xcode.mobile_provision then + cprint("checking for Mobile Provision of Xcode ... ${color.success}%s", xcode.mobile_provision) + else + cprint("checking for Mobile Provision of Xcode ... ${color.nothing}${text.nothing}") + end + end + end + -- save target minver -- -- @note we need to differentiate the version for the system, @@ -62,5 +82,7 @@ function main(toolchain) toolchain:config_set("xcode_sdkver", xcode_sdkver) toolchain:config_set("target_minver", target_minver) toolchain:configs_save() + cprint("checking for SDK version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), xcode_sdkver) + cprint("checking for Minimal target version of Xcode for %s (%s) ... ${color.success}%s", toolchain:plat(), toolchain:arch(), target_minver) return true end -- cgit v1.3.1 From cca7e9f2b46df3003143a11e8e391567b9472014 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 00:51:51 +0800 Subject: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c79bfdb2d..eb3f1c97a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * [#1072](https://github.com/xmake-io/xmake/issues/1072): Fix and improve to parse cl deps * Support utf8 for ui modules and `xmake f --menu` * Improve to support zig on macOS +* [#1135](https://github.com/xmake-io/xmake/issues/1135): Improve multi-toolchain and multi-platforms for targets ### Bugs fixed @@ -894,6 +895,7 @@ * [#1072](https://github.com/xmake-io/xmake/issues/1072): 修复并改进 cl 编译器头文件依赖信息 * 针对 ui 模块和 `xmake f --menu` 增加 utf8 支持 * 改进 zig 语言在 macOS 上的支持 +* [#1135](https://github.com/xmake-io/xmake/issues/1135): 针对特定 target 改进多平台多工具链同时配置支持 ### Bugs 修复 -- cgit v1.3.1 From 98a044d2947d070d035fe76c651fdbf9f0c3b135 Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 17 Dec 2020 22:43:28 +0800 Subject: save xcode directory to toolchain --- xmake/toolchains/xcode/check.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index b8707a2a9..7bd6eca84 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -79,6 +79,7 @@ function main(toolchain) end end end + toolchain:config_set("xcode", xcode.sdkdir) toolchain:config_set("xcode_sdkver", xcode_sdkver) toolchain:config_set("target_minver", target_minver) toolchain:configs_save() -- cgit v1.3.1