summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-10-23 23:41:03 +0200
committerArthur LAURENT <[email protected]>2025-10-23 23:41:03 +0200
commit05908f8cb3490b42deb90bdb9e92a797e3ad3e9d (patch)
tree6533eb3120f23c8af243520caab555307e8b4f98
parentc1b73a9a9dc3eba4dc96efc9cab7314b5eca9b9b (diff)
feat(swift) improve swift toolchain and enable swift for llvm on macos host
-rw-r--r--xmake/toolchains/llvm/xmake.lua43
-rw-r--r--xmake/toolchains/swift/xmake.lua14
2 files changed, 28 insertions, 29 deletions
diff --git a/xmake/toolchains/llvm/xmake.lua b/xmake/toolchains/llvm/xmake.lua
index de2e775d7..bac7f2705 100644
--- a/xmake/toolchains/llvm/xmake.lua
+++ b/xmake/toolchains/llvm/xmake.lua
@@ -39,6 +39,11 @@ toolchain("llvm")
set_toolset("mrc", "llvm-rc")
set_toolset("dlltool", "llvm-dlltool")
+ set_toolset("sc", "$(env SC)", "swift-frontend", "swiftc")
+ set_toolset("scsh", "$(env SC)", "swiftc")
+ set_toolset("scar", "$(env SC)", "swiftc")
+ set_toolset("scld", "$(env SC)", "swiftc")
+
on_check("check")
on_load(function (toolchain)
@@ -56,16 +61,6 @@ toolchain("llvm")
else
target = "x86_64-pc-windows-msvc"
end
- elseif toolchain:is_plat("macosx") then
- local arch = toolchain:arch()
- local target_minver = toolchain:config("target_minver")
- local appledev = toolchain:config("appledev")
- if target_minver then
- target = ("%s-apple-macos%s"):format(arch, target_minver)
- if appledev == "catalyst" then
- target = ("%s-apple-ios%s-macabi"):format(arch, target_minver)
- end
- end
elseif toolchain:is_plat("cross") then
target = toolchain:cross():gsub("(.*)%-$", "%1")
end
@@ -83,6 +78,9 @@ toolchain("llvm")
toolchain:add("asflags", target_flags)
toolchain:add("ldflags", target_flags)
toolchain:add("shflags", target_flags)
+ toolchain:add("scasflags", "--target=" .. target_flags)
+ toolchain:add("scldflags", "--target=" .. target_flags)
+ toolchain:add("scshflags", "--target=" .. target_flags)
end
-- init flags for platform
@@ -90,25 +88,16 @@ toolchain("llvm")
toolchain:add("ldflags", "-fuse-ld=lld")
toolchain:add("shflags", "-fuse-ld=lld")
elseif toolchain:is_plat("macosx") then
- local xcode_dir = get_config("xcode")
- 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"
- toolchain:add("cxflags", {"-isysroot", xcode_sdkdir})
- toolchain:add("mxflags", {"-isysroot", xcode_sdkdir})
- toolchain:add("ldflags", {"-isysroot", xcode_sdkdir})
- toolchain:add("shflags", {"-isysroot", xcode_sdkdir})
- else
- -- @see https://github.com/xmake-io/xmake/issues/1179
- local macsdk = "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
- if os.exists(macsdk) then
- toolchain:add("cxflags", {"-isysroot", macsdk})
- toolchain:add("mxflags", {"-isysroot", macsdk})
- toolchain:add("ldflags", {"-isysroot", macsdk})
- toolchain:add("shflags", {"-isysroot", macsdk})
+ if not toolchain:config("xcode_sysroot") then
+ local xcode_dir = get_config("xcode")
+ local xcode_sdkver = toolchain:config("xcode_sdkver")
+ local xcode_sdkdir = path.join(xcode_dir, "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk")
+ if os.isdir(xcode_sdkdir) then
+ toolchain:config_set("xcode_sysroot", xcode_sdkdir)
end
end
+ -- load configurations
+ import(".xcode.load_" .. toolchain:plat())(toolchain)
toolchain:add("mxflags", "-fobjc-arc")
elseif toolchain:is_plat("cross") then
local sysroot
diff --git a/xmake/toolchains/swift/xmake.lua b/xmake/toolchains/swift/xmake.lua
index 38c263a65..ff433b04c 100644
--- a/xmake/toolchains/swift/xmake.lua
+++ b/xmake/toolchains/swift/xmake.lua
@@ -33,6 +33,16 @@ toolchain("swift")
-- on load
on_load(function (toolchain)
- toolchain:set("scshflags", "")
- toolchain:set("scldflags", "")
+ if toolchain:is_plat("macosx") then
+ if not toolchain:config("xcode_sysroot") then
+ local xcode_dir = get_config("xcode")
+ local xcode_sdkver = toolchain:config("xcode_sdkver")
+ local xcode_sdkdir = path.join(xcode_dir, "Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. ".sdk")
+ if os.isdir(xcode_sdkdir) then
+ toolchain:config_set("xcode_sysroot", xcode_sdkdir)
+ end
+ end
+ -- load configurations
+ import(".xcode.load_" .. toolchain:plat())(toolchain)
+ end
end)