diff options
| author | ruki <[email protected]> | 2022-03-26 17:34:57 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-03-26 17:34:57 +0800 |
| commit | 0c51d82b9c4ed8762f11e6a52450c23918cfc49e (patch) | |
| tree | 97b6c241acb64128b8b537e5e0beb364348e062e | |
| parent | 58d882b87f497705211294f156c4a9172f8a1ae5 (diff) | |
| parent | f5d478243fc29898fd4d9de1aee33f006e7e4973 (diff) | |
Merge pull request #2204 from xmake-io/simulator
Improve apple simulator support
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/core/package/package.lua | 13 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 13 | ||||
| -rw-r--r-- | xmake/modules/package/tools/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/private/detect/find_platform.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/private/xrepo/action/install.lua | 4 | ||||
| -rw-r--r-- | xmake/platforms/appletvos/xmake.lua | 11 | ||||
| -rw-r--r-- | xmake/platforms/iphoneos/xmake.lua | 11 | ||||
| -rw-r--r-- | xmake/platforms/watchos/xmake.lua | 14 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/check.lua | 18 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_appletvos.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 2 |
13 files changed, 66 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index d21079468..16a731ce1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### New features * [#2138](https://github.com/xmake-io/xmake/issues/2138): Support template package +* [#2185](https://github.com/xmake-io/xmake/issues/2185): Add `--appledev=simulator` to improve apple simulator support ### Changes @@ -1234,6 +1235,7 @@ ### 新特性 * [#2138](https://github.com/xmake-io/xmake/issues/2138): 支持模板包 +* [#2185](https://github.com/xmake-io/xmake/issues/2185): 添加 `--appledev=simulator` 去改进 Apple 模拟器目标编译支持 ### 改进 diff --git a/xmake/core/package/package.lua b/xmake/core/package/package.lua index 239bbb928..5c55850bb 100644 --- a/xmake/core/package/package.lua +++ b/xmake/core/package/package.lua @@ -854,6 +854,19 @@ function _instance:build_envs(lazy_loading) return build_envs end +-- get the given toolchain +function _instance:toolchain(name) + local toolchains_map = self._TOOLCHAINS_MAP + if toolchains_map == nil then + toolchains_map = {} + for _, toolchain_inst in ipairs(self:toolchains()) do + toolchains_map[toolchain_inst:name()] = toolchain_inst + end + self._TOOLCHAINS_MAP = toolchains_map + end + return toolchains_map[name] +end + -- get toolchains function _instance:toolchains() local toolchains = self._TOOLCHAINS diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 05e4a1476..78b620165 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1921,6 +1921,19 @@ function _instance:pcoutputfile(langkind) end end +-- get the given toolchain +function _instance:toolchain(name) + local toolchains_map = self:_memcache():get("toolchains_map") + if toolchains_map == nil then + toolchains_map = {} + for _, toolchain_inst in ipairs(self:toolchains()) do + toolchains_map[toolchain_inst:name()] = toolchain_inst + end + self:_memcache():set("toolchains_map", toolchains_map) + end + return toolchains_map[name] +end + -- get the toolchains function _instance:toolchains() local toolchains = self:_memcache():get("toolchains") diff --git a/xmake/modules/package/tools/xmake.lua b/xmake/modules/package/tools/xmake.lua index 53f977911..a0934db1e 100644 --- a/xmake/modules/package/tools/xmake.lua +++ b/xmake/modules/package/tools/xmake.lua @@ -52,8 +52,12 @@ function _get_configs(package, configs) if vs_runtime then table.insert(configs, "--vs_runtime=" .. vs_runtime) end - end - if package:is_plat("cross") then + elseif package:is_plat("iphoneos", "watchos", "appletvos") then + local appledev = package:config("appledev") + if appledev then + table.insert(configs, "--appledev=" .. appledev) + end + elseif package:is_plat("cross") then local cross = _get_config_from_toolchains(package, "cross") or get_config("cross") if cross then table.insert(configs, "--cross=" .. cross) diff --git a/xmake/modules/private/detect/find_platform.lua b/xmake/modules/private/detect/find_platform.lua index 54f8a2182..d00809e47 100644 --- a/xmake/modules/private/detect/find_platform.lua +++ b/xmake/modules/private/detect/find_platform.lua @@ -91,12 +91,13 @@ function _find_arch(plat, arch) arch = project.default_arch(plat) end if not arch then + local appledev = config.get("appledev") if plat == "android" then arch = "armeabi-v7a" elseif plat == "iphoneos" or plat == "appletvos" then - arch = "arm64" + arch = appledev == "simulator" and os.arch() or "arm64" elseif plat == "watchos" then - arch = "armv7k" + arch = appledev == "simulator" and os.arch() or "armv7k" elseif plat == "wasm" then arch = "wasm32" elseif plat == "mingw" then diff --git a/xmake/modules/private/xrepo/action/install.lua b/xmake/modules/private/xrepo/action/install.lua index a4e4f7551..bd77e7b00 100644 --- a/xmake/modules/private/xrepo/action/install.lua +++ b/xmake/modules/private/xrepo/action/install.lua @@ -64,6 +64,7 @@ function menu_options() {nil, "xcode", "kv", nil, "The Xcode Application Directory" }, {nil, "xcode_sdkver", "kv", nil, "The SDK Version for Xcode" }, {nil, "target_minver", "kv", nil, "The Target Minimal Version" }, + {nil, "appledev", "kv", nil, "The Apple Device Type" }, {category = "Other Configuration" }, {nil, "force", "k", nil, "Force to reinstall all package dependencies."}, {nil, "shallow", "k", nil, "Does not install dependent packages."}, @@ -200,6 +201,9 @@ function _install_packages(packages) if option.get("target_minver") then table.insert(config_argv, "--target_minver=" .. option.get("target_minver")) end + if option.get("appledev") then + table.insert(config_argv, "--appledev=" .. option.get("appledev")) + end local envs = {} if #rcfiles > 0 then envs.XMAKE_RCFILES = path.joinenv(rcfiles) diff --git a/xmake/platforms/appletvos/xmake.lua b/xmake/platforms/appletvos/xmake.lua index c3f21f8f4..2b4510028 100644 --- a/xmake/platforms/appletvos/xmake.lua +++ b/xmake/platforms/appletvos/xmake.lua @@ -18,32 +18,23 @@ -- @file xmake.lua -- --- define platform platform("appletvos") - - -- set os set_os("ios") - - -- set hosts set_hosts("macosx") - -- set archs if os.arch() == "arm64" then -- on apple m1 device set_archs("arm64", "x86_64") else set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") end - -- set formats set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- set toolchains set_toolchains("envs", "xcode") - -- set menu set_menu { config = { @@ -54,6 +45,8 @@ platform("appletvos") , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } + , {nil, "appledev", "kv", nil, "The Apple Device Type", + values = {"simulator", "iphone", "watchtv", "appletv"}} } , global = diff --git a/xmake/platforms/iphoneos/xmake.lua b/xmake/platforms/iphoneos/xmake.lua index 8677218fa..057a2704b 100644 --- a/xmake/platforms/iphoneos/xmake.lua +++ b/xmake/platforms/iphoneos/xmake.lua @@ -18,32 +18,23 @@ -- @file xmake.lua -- --- define platform platform("iphoneos") - - -- set os set_os("ios") - - -- set hosts set_hosts("macosx") - -- set archs if os.arch() == "arm64" then -- on apple m1 device set_archs("arm64", "x86_64") else set_archs("arm64", "armv7", "armv7s", "i386", "x86_64") end - -- set formats set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- set toolchains set_toolchains("envs", "xcode") - -- set menu set_menu { config = { @@ -54,6 +45,8 @@ platform("iphoneos") , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } + , {nil, "appledev", "kv", nil, "The Apple Device Type", + values = {"simulator", "iphone", "watchtv", "appletv"}} } , global = diff --git a/xmake/platforms/watchos/xmake.lua b/xmake/platforms/watchos/xmake.lua index 3eff1ec11..f89b2fa51 100644 --- a/xmake/platforms/watchos/xmake.lua +++ b/xmake/platforms/watchos/xmake.lua @@ -18,28 +18,18 @@ -- @file xmake.lua -- --- define platform platform("watchos") - - -- set os set_os("ios") - - -- set hosts set_hosts("macosx") - - -- set archs set_archs("armv7k", "i386") - -- set formats set_formats("static", "lib$(name).a") set_formats("object", "$(name).o") set_formats("shared", "lib$(name).dylib") set_formats("symbol", "$(name).dSYM") - -- set toolchains set_toolchains("envs", "xcode") - -- set menu set_menu { config = { @@ -49,7 +39,9 @@ platform("watchos") , {nil, "xcode_bundle_identifier", "kv", "auto", "The Bundle Identifier for Xcode" } , {nil, "xcode_codesign_identity", "kv", "auto", "The Codesign Identity for Xcode" } , {nil, "xcode_mobile_provision", "kv", "auto", "The Mobile Provision for Xcode" } - , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } + , {nil, "target_minver", "kv", "auto", "The Target Minimal Version" } + , {nil, "appledev", "kv", nil, "The Apple Device Type", + values = {"simulator", "iphone", "watchtv", "appletv"}} } , global = diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index ed0d917db..927eadceb 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -59,19 +59,30 @@ function main(toolchain) end end + -- get apple device + local simulator + local appledev = toolchain:config("appledev") or config.get("appledev") + if appledev and appledev == "simulator" then + simulator = true + appledev = "simulator" + elseif not toolchain:is_plat("macosx") and toolchain:is_arch("i386", "x86_64") then + simulator = true + appledev = "simulator" + end + -- save xcode sysroot directory local xcode_sysroot if xcode.sdkdir and xcode_sdkver then if toolchain:is_plat("macosx") then xcode_sysroot = xcode.sdkdir .. "/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk" elseif toolchain:is_plat("iphoneos") then - local platname = toolchain:is_arch("i386", "x86_64") and "iPhoneSimulator" or "iPhoneOS" + local platname = simulator and "iPhoneSimulator" or "iPhoneOS" xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver) elseif toolchain:is_plat("watchos") then - local platname = toolchain:is_arch("i386", "x86_64") and "WatchSimulator" or "WatchOS" + local platname = simulator and "WatchSimulator" or "WatchOS" xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver) elseif toolchain:is_plat("appletvos") then - local platname = toolchain:is_arch("i386", "x86_64") and "AppleTVSimulator" or "AppleTVOS" + local platname = simulator and "AppleTVSimulator" or "AppleTVOS" xcode_sysroot = format("%s/Contents/Developer/Platforms/%s.platform/Developer/SDKs/%s%s.sdk", xcode.sdkdir, platname, platname, xcode_sdkver) end end @@ -102,6 +113,7 @@ function main(toolchain) toolchain:config_set("xcode", xcode.sdkdir) toolchain:config_set("xcode_sdkver", xcode_sdkver) toolchain:config_set("target_minver", target_minver) + toolchain:config_set("appledev", appledev) 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) diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua index c251e85b1..aad701ad5 100644 --- a/xmake/toolchains/xcode/load_appletvos.lua +++ b/xmake/toolchains/xcode/load_appletvos.lua @@ -30,7 +30,7 @@ function main(toolchain) local xcode_sysroot = toolchain:config("xcode_sysroot") -- is simulator? - local simulator = toolchain:is_arch("x86_64", "i386") + local simulator = toolchain:config("appledev") == "simulator" -- init target minimal version local target_minver = toolchain:config("target_minver") diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index c437ce975..77a581b0c 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -30,7 +30,7 @@ function main(toolchain) local xcode_sysroot = toolchain:config("xcode_sysroot") -- is simulator? - local simulator = toolchain:is_arch("x86_64", "i386") + local simulator = toolchain:config("appledev") == "simulator" -- init target minimal version local target_minver = toolchain:config("target_minver") diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index b0929ed5e..a727776bd 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -30,7 +30,7 @@ function main(toolchain) local xcode_sysroot = toolchain:config("xcode_sysroot") -- is simulator? - local simulator = toolchain:is_arch("x86_64", "i386") + local simulator = toolchain:config("appledev") == "simulator" -- init target minimal version local target_minver = toolchain:config("target_minver") |
