diff options
| author | ruki <[email protected]> | 2020-12-17 10:59:28 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-17 10:59:28 +0800 |
| commit | e95f99d7d99daf3c065dd04d457b2a8a81545380 (patch) | |
| tree | 72816b1c749dd12e31da06b9b9d97ffc8d057866 | |
| parent | 37521d4aa857d57773b0f6cb9311856d3787c6f5 (diff) | |
| parent | 98a044d2947d070d035fe76c651fdbf9f0c3b135 (diff) | |
Merge pull request #1141 from xmake-io/toolchain
Improve toolchain
65 files changed, 597 insertions, 512 deletions
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 diff --git a/CHANGELOG.md b/CHANGELOG.md index bd2faf26f..dd5df92ce 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 @@ -895,6 +896,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 修复 diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 5cc1e7e0e..1aac20088 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(), arch):check() -- create sln & vcxproj local vs = config.get("vs") diff --git a/tests/projects/objc/iosapp/xmake.lua b/tests/projects/objc/iosapp/xmake.lua index e1e9e6d74..05f445980 100644 --- a/tests/projects/objc/iosapp/xmake.lua +++ b/tests/projects/objc/iosapp/xmake.lua @@ -4,3 +4,4 @@ target("test") add_rules("xcode.application") add_files("src/*.m", "src/**.storyboard", "src/*.xcassets") add_files("src/Info.plist") + set_plat("iphoneos") 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 <iostream> + +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 --- /dev/null +++ b/tests/projects/other/multiplats_vs/src/test.rc 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 <stdio.h> + +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") diff --git a/xmake/actions/config/main.lua b/xmake/actions/config/main.lua index 8490dd4e3..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"}) @@ -141,23 +142,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 @@ -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/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/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/core/platform/platform.lua b/xmake/core/platform/platform.lua index 4b366fceb..5467d7944 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, ...) @@ -195,7 +205,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()} + 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 @@ -266,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 @@ -383,7 +387,6 @@ function platform._apis() { -- platform.on_xxx "platform.on_load" - , "platform.on_check" } , keyvalues = { 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/project/target.lua b/xmake/core/project/target.lua index 257e1b93b..0a5a67ddf 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 @@ -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()} + 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/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/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/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/tool.lua b/xmake/core/tool/tool.lua index 2bd0ed7ca..bd90c0658 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 @@ -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/core/tool/toolchain.lua b/xmake/core/tool/toolchain.lua index bc152a3f6..327be29ed 100644 --- a/xmake/core/tool/toolchain.lua +++ b/xmake/core/tool/toolchain.lua @@ -36,12 +36,25 @@ 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) - local instance = table.inherit(_instance) - instance._NAME = name - instance._INFO = info - instance._PLAT = plat - instance._ARCH = arch +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 + -- 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 @@ -52,12 +65,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? @@ -133,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 @@ -192,6 +210,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[name] +end + +-- set user config +function _instance:config_set(name, data) + 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 @@ -328,12 +366,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 @@ -378,6 +413,19 @@ function toolchain._interpreter() return interp end +-- get cache key +function toolchain._cachekey(name, opt) + local cachekey = opt.cachekey + if not cachekey then + cachekey = "toolchain_" .. name + for _, k in ipairs(table.orderkeys(opt)) do + local v = opt[k] + cachekey = cachekey .. "_" .. k .. "_" .. tostring(v) + end + end + return cachekey +end + -- get toolchain apis function toolchain.apis() return @@ -419,14 +467,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 + 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 {} @@ -468,17 +516,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, cachekey, opt) 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) + 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 {} + if toolchain._TOOLCHAINS[cachekey] then + return toolchain._TOOLCHAINS[cachekey] + end + + -- save instance to the cache + local instance = _instance.new(name, info, cachekey, opt) + toolchain._TOOLCHAINS[cachekey] = instance + return instance end -- return module 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/sdks/find_xcode.lua b/xmake/modules/detect/sdks/find_xcode.lua index 1177685a5..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 is_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 = ..} -- @@ -144,54 +150,14 @@ 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" - - -- 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 + 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 or xcode_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}) - - -- 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) - 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 - - -- trace - 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 cache.save(key, cacheinfo) - - -- ok? return xcode 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/modules/detect/tools/find_lib.lua b/xmake/modules/detect/tools/find_lib.lua index f3c5806ee..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")) - local link = assert(find_tool("link")) + 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}) 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/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/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua new file mode 100644 index 000000000..d366260b6 --- /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", arch) + end + end + return plat, 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 4fbb4e2b2..55c4eeec9 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -36,16 +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") - 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") diff --git a/xmake/plugins/project/vstudio/impl/vs201x.lua b/xmake/plugins/project/vstudio/impl/vs201x.lua index b19ebadc6..10784c5ea 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) @@ -233,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(), arch):check() -- check project options project.check() - -- reload platform - platform.load(config.plat()) - -- re-generate configheader generate_configheader() end 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/plugins/project/vsxmake/getinfo.lua b/xmake/plugins/project/vsxmake/getinfo.lua index 96b4e18ba..7a82036bc 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(), arch):check() -- check project options project.check() - -- reload platform - platform.load(config.plat()) - -- re-generate configheader generate_configheader() 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([[<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> @@ -59,7 +68,7 @@ function _save_info_plist(target, info_plist_file) <key>NSPrincipalClass</key> <string>NSApplication</string> </dict> -</plist>]], name, name, name, name, get_config("target_minver_macosx") or (macos.version():major() .. "." .. macos.version():minor()))) +</plist>]], name, name, name, name, target_minver or (macos.version():major() .. "." .. macos.version():minor()))) end -- deploy application package for macosx 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/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..bfa88e6e1 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") @@ -83,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 5c1912dd4..d20fc278c 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") @@ -85,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/msvc/check.lua b/xmake/toolchains/msvc/check.lua index 33cfc6298..731836f88 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,11 @@ end function _check_vstudio(toolchain) local vs = _check_vsenv(toolchain) if vs then - config.set("vs", vs, {readonly = true, force = true}) + 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) 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..a1d7c754d 100644 --- a/xmake/toolchains/msvc/load.lua +++ b/xmake/toolchains/msvc/load.lua @@ -26,39 +26,16 @@ 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)) + toolchain:add("runenvs", name, table.unwrap(path.splitenv(new))) end end @@ -84,6 +61,9 @@ 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") -- add some default flags toolchain:add("cxxflags", "/EHsc") diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 579def16c..7bd6eca84 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -27,13 +27,38 @@ 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()}) - if xcode then - config.set("xcode", xcode.sdkdir, {force = true, readonly = true}) - else + local xcode_sdkver = toolchain:config("xcode_sdkver") or config.get("xcode_sdkver") + 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 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, @@ -44,14 +69,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 +79,11 @@ function main(toolchain) end end end - config.set("target_minver_" .. toolchain:plat(), target_minver) + toolchain:config_set("xcode", xcode.sdkdir) + 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 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++ |
