diff options
| author | ruki <[email protected]> | 2026-02-11 00:47:03 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-02-11 00:47:03 +0800 |
| commit | b1151620cca00ebf4f011ae5e3656359cba80f0c (patch) | |
| tree | b41c2b939e45dce5126a58153797d8f3af5e7f56 | |
| parent | de97caa61ab95c3a422dc9c494370f513e4ef535 (diff) | |
improve xcode toolchain
| -rw-r--r-- | xmake/modules/private/utils/toolchain.lua | 35 | ||||
| -rw-r--r-- | xmake/toolchains/llvm/check.lua | 15 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/check.lua | 6 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_appletvos.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_applexros.lua | 3 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_iphoneos.lua | 2 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_macosx.lua | 32 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_platform.lua | 34 | ||||
| -rw-r--r-- | xmake/toolchains/xcode/load_watchos.lua | 3 |
9 files changed, 77 insertions, 56 deletions
diff --git a/xmake/modules/private/utils/toolchain.lua b/xmake/modules/private/utils/toolchain.lua index bf24d3c73..b7064462c 100644 --- a/xmake/modules/private/utils/toolchain.lua +++ b/xmake/modules/private/utils/toolchain.lua @@ -184,6 +184,41 @@ function get_clang_target_flags(toolchain) end end +-- get xcode/apple target triple for clang -target, e.g. x86_64-apple-ios18.2-simulator +-- +-- configs: +-- - appledev: simulator/catalyst +-- - target_minver: deployment target version (ios 32-bit will be capped to 10) +function get_xcode_target_triple(toolchain) + local arch = toolchain:arch() + local plat = toolchain:plat() + if plat == "macosx" then + plat = "macos" + elseif plat == "iphoneos" then + plat = "ios" + elseif plat == "appletvos" then + plat = "tvos" + elseif plat == "applexros" then + plat = "xros" + end + local target_minver = toolchain:config("target_minver") or config.get("target_minver") + local appledev = toolchain:config("appledev") or config.get("appledev") + local target = format("%s-apple-%s", arch, plat) + if target_minver then + if plat == "ios" and tonumber(target_minver) > 10 and (arch == "armv7" or arch == "armv7s" or arch == "i386") then + target_minver = "10" + end + target = target .. target_minver + end + if appledev == "simulator" then + target = target .. "-simulator" + end + if appledev == "catalyst" then + target = target .. "-macabi" + end + return target +end + -- add vs environments function add_vsenvs(toolchain, opt) opt = opt or {} diff --git a/xmake/toolchains/llvm/check.lua b/xmake/toolchains/llvm/check.lua index 24bb229a7..b34e66e98 100644 --- a/xmake/toolchains/llvm/check.lua +++ b/xmake/toolchains/llvm/check.lua @@ -24,16 +24,19 @@ import("lib.detect.find_path") import("lib.detect.find_tool") import("detect.sdks.find_xcode") import("detect.sdks.find_cross_toolchain") +import("private.utils.toolchain", {alias = "toolchain_utils"}) -- print Xcode SDK summary (single line) -function _show_checkinfo(toolchain, xcode_sdkdir, xcode_sdkver, target_minver) +function _show_checkinfo(toolchain, xcode_sdkdir) if xcode_sdkdir then + local xcode_sdkver = toolchain:config("xcode_sdkver") local extras = {} if xcode_sdkver then table.insert(extras, "sdk: " .. xcode_sdkver) end - if target_minver then - table.insert(extras, "target: " .. target_minver) + local target_triple = toolchain_utils.get_xcode_target_triple(toolchain) + if target_triple then + table.insert(extras, target_triple) end local extra = "" if #extras > 0 then @@ -64,7 +67,9 @@ function _find_xcode(toolchain) plat = toolchain:plat(), arch = toolchain:arch()}) if not xcode then - cprint("checking for Xcode SDK ... ${color.nothing}${text.nothing}") + if toolchain:is_global() then + _show_checkinfo(toolchain, nil) + end return end @@ -82,7 +87,7 @@ function _find_xcode(toolchain) toolchain:config_set("target_minver", target_minver) toolchain:config_set("appledev", appledev) if toolchain:is_global() then - _show_checkinfo(toolchain, xcode.sdkdir, xcode_sdkver, target_minver) + _show_checkinfo(toolchain, xcode.sdkdir) end end diff --git a/xmake/toolchains/xcode/check.lua b/xmake/toolchains/xcode/check.lua index 5797170f5..b73ea426a 100644 --- a/xmake/toolchains/xcode/check.lua +++ b/xmake/toolchains/xcode/check.lua @@ -22,6 +22,7 @@ import("core.base.option") import("core.project.config") import("detect.sdks.find_xcode") +import("private.utils.toolchain", {alias = "toolchain_utils"}) import("private.utils.executable_path") import("private.tools.codesign") @@ -32,8 +33,9 @@ function _show_checkinfo(toolchain, xcode, xcode_sdkver, target_minver) if xcode_sdkver then table.insert(extras, "sdk: " .. xcode_sdkver) end - if target_minver then - table.insert(extras, "target: " .. target_minver) + local target_triple = toolchain_utils.get_xcode_target_triple(toolchain) + if target_triple then + table.insert(extras, target_triple) end local extra = "" if #extras > 0 then diff --git a/xmake/toolchains/xcode/load_appletvos.lua b/xmake/toolchains/xcode/load_appletvos.lua index cc3382a06..af1745bb7 100644 --- a/xmake/toolchains/xcode/load_appletvos.lua +++ b/xmake/toolchains/xcode/load_appletvos.lua @@ -21,6 +21,5 @@ import("load_platform") function main(toolchain) - load_platform(toolchain, "tvos") + load_platform(toolchain) end - diff --git a/xmake/toolchains/xcode/load_applexros.lua b/xmake/toolchains/xcode/load_applexros.lua index 497c5024c..98779a970 100644 --- a/xmake/toolchains/xcode/load_applexros.lua +++ b/xmake/toolchains/xcode/load_applexros.lua @@ -21,6 +21,5 @@ import("load_platform") function main(toolchain) - load_platform(toolchain, "xros") + load_platform(toolchain) end - diff --git a/xmake/toolchains/xcode/load_iphoneos.lua b/xmake/toolchains/xcode/load_iphoneos.lua index 7c7df157a..09e3c5b51 100644 --- a/xmake/toolchains/xcode/load_iphoneos.lua +++ b/xmake/toolchains/xcode/load_iphoneos.lua @@ -21,5 +21,5 @@ import("load_platform") function main(toolchain) - load_platform(toolchain, "ios") + load_platform(toolchain) end diff --git a/xmake/toolchains/xcode/load_macosx.lua b/xmake/toolchains/xcode/load_macosx.lua index ff484736b..ee0c8d17d 100644 --- a/xmake/toolchains/xcode/load_macosx.lua +++ b/xmake/toolchains/xcode/load_macosx.lua @@ -17,42 +17,34 @@ -- @author ruki -- @file load_macosx.lua -- +-- imports +import("private.utils.toolchain", {alias = "toolchain_utils"}) +-- main entry function main(toolchain) - -- init architecture - local arch = toolchain:arch() - local xcode_sysroot = toolchain:config("xcode_sysroot") -- is simulator? local appledev = toolchain:config("appledev") - local simulator = appledev == "simulator" - assert(not simulator) + assert(appledev ~= "simulator") local catalyst = appledev == "catalyst" - -- init target minimal version - local target_minver = toolchain:config("target_minver") - local targetflag = format("%s-apple-macos", arch) - if target_minver then - targetflag = targetflag .. target_minver - end - if catalyst then - targetflag = targetflag .. "-macabi" - end - targetflag = {"-target", targetflag} + -- init target triple flags + local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)} -- init flags for c/c++ - toolchain:add("cxflags", {"-arch", arch}, targetflag, {"-isysroot", xcode_sysroot}) - toolchain:add("ldflags", {"-arch", arch}, targetflag, {"-isysroot", xcode_sysroot}, "-lz") - toolchain:add("shflags", {"-arch", arch}, targetflag, {"-isysroot", xcode_sysroot}, "-lz") + local xcode_sysroot = toolchain:config("xcode_sysroot") + toolchain:add("cxflags", targetflag, {"-isysroot", xcode_sysroot}) + toolchain:add("ldflags", targetflag, {"-isysroot", xcode_sysroot}, "-lz") + toolchain:add("shflags", targetflag, {"-isysroot", xcode_sysroot}, "-lz") -- init flags for objc/c++ - toolchain:add("mxflags", {"-arch", arch}, targetflag, {"-isysroot", xcode_sysroot}) + toolchain:add("mxflags", targetflag, {"-isysroot", xcode_sysroot}) -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua toolchain:add("mxflags", "-fobjc-arc") -- init flags for asm - toolchain:add("asflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot) + toolchain:add("asflags", targetflag, "-isysroot", xcode_sysroot) -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) toolchain:add("scflags", {"-sdk", xcode_sysroot}, targetflag) diff --git a/xmake/toolchains/xcode/load_platform.lua b/xmake/toolchains/xcode/load_platform.lua index 74c5c616f..60dfd6d86 100644 --- a/xmake/toolchains/xcode/load_platform.lua +++ b/xmake/toolchains/xcode/load_platform.lua @@ -17,39 +17,29 @@ -- @author ruki -- @file load_platform.lua -- +-- imports +import("private.utils.toolchain", {alias = "toolchain_utils"}) -function main(toolchain, plat) - -- init architecture - local arch = toolchain:arch() - local xcode_sysroot = toolchain:config("xcode_sysroot") - - -- is simulator? - local appledev = toolchain:config("appledev") - local simulator = appledev == "simulator" +-- main entry +function main(toolchain) - -- init target minimal version - local target_minver = toolchain:config("target_minver") - if target_minver then - if plat == "ios" 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 - end - local targetflag = format("%s-apple-%s%s%s", arch, plat, target_minver or "", simulator and "-simulator" or "") - targetflag = {"-target", targetflag} + -- init target triple flags + local targetflag = {"-target", toolchain_utils.get_xcode_target_triple(toolchain)} -- init flags for c/c++ - toolchain:add("cxflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot) - toolchain:add("ldflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") - toolchain:add("shflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") + local xcode_sysroot = toolchain:config("xcode_sysroot") + toolchain:add("cxflags", targetflag, "-isysroot", xcode_sysroot) + toolchain:add("ldflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") + toolchain:add("shflags", targetflag, "-isysroot", xcode_sysroot, "-ObjC", "-fobjc-link-runtime") -- init flags for objc/c++ - toolchain:add("mxflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot) + toolchain:add("mxflags", targetflag, "-isysroot", xcode_sysroot) -- we can use `add_mxflags("-fno-objc-arc")` to override it in xmake.lua toolchain:add("mxflags", "-fobjc-arc") -- init flags for asm - toolchain:add("asflags", {"-arch", arch}, targetflag, "-isysroot", xcode_sysroot) + toolchain:add("asflags", targetflag, "-isysroot", xcode_sysroot) -- init flags for swift (with toolchain:add("ldflags and toolchain:add("shflags) toolchain:add("scflags", {"-sdk", xcode_sysroot}, targetflag) diff --git a/xmake/toolchains/xcode/load_watchos.lua b/xmake/toolchains/xcode/load_watchos.lua index fa3f9f785..39d071dfd 100644 --- a/xmake/toolchains/xcode/load_watchos.lua +++ b/xmake/toolchains/xcode/load_watchos.lua @@ -21,6 +21,5 @@ import("load_platform") function main(toolchain) - load_platform(toolchain, "watchos") + load_platform(toolchain) end - |
