summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2025-10-23 22:09:29 +0200
committerArthur LAURENT <[email protected]>2025-10-23 22:09:29 +0200
commit3a9b7a4db2c851415be0282a36e60deecd7f53f1 (patch)
tree93d4ac8986b464eb686c4a03696ebdbceb55f8e3
parent16dc28b62144cdcc42cb7597e39d2d9499ac7f49 (diff)
feat(swift) enable swift library to be linked by other targets
-rw-r--r--xmake/modules/core/tools/swiftc/has_flags.lua4
-rw-r--r--xmake/rules/swift/xmake.lua12
2 files changed, 16 insertions, 0 deletions
diff --git a/xmake/modules/core/tools/swiftc/has_flags.lua b/xmake/modules/core/tools/swiftc/has_flags.lua
index 290a6de83..943277110 100644
--- a/xmake/modules/core/tools/swiftc/has_flags.lua
+++ b/xmake/modules/core/tools/swiftc/has_flags.lua
@@ -73,6 +73,10 @@ function _check_try_running(flags, opt)
-- check it
local objectfile = os.tmpfile() .. ".o"
local ok, errors = _try_running(opt.program, table.join(flags, "-o", objectfile, sourcefile))
+ if errors and errors:match("no frontend action") then
+ ok = true
+ errors = nil
+ end
-- remove files
os.tryrm(objectfile)
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 3ab44c600..42611b79c 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -23,6 +23,10 @@ rule("swift.build")
set_sourcekinds("sc")
on_build_files("private.action.build.object", {jobgraph = true, batch = true})
on_config(function (target)
+ if target:is_library() then
+ target:add("scflags", "-parse-as-library")
+ end
+
-- we use swift-frontend to support multiple modules
-- @see https://github.com/xmake-io/xmake/issues/3916
if target:has_tool("sc", "swift_frontend") then
@@ -42,6 +46,14 @@ rule("swift")
-- add build rules
add_deps("swift.build")
+ -- set compiler runtime, e.g. vs runtime
+ add_deps("utils.compiler.runtime")
+
+ -- inherit links and linkdirs of all dependent targets by default
+ add_deps("utils.inherit.links")
+
-- support `add_files("src/*.o")` to merge object files to target
add_deps("utils.merge.object")
+ -- add linker rules
+ add_deps("linker")