summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-07-10 23:18:47 +0800
committerruki <[email protected]>2023-07-10 23:18:47 +0800
commite0cc53f53a0e40bd0cf3b4bbd0ca032627e981ae (patch)
treefe397ea4be1283b2c9f6119db06d111e468ac123
parentb3627c504fb1c65f829f92c5cd709b23a6776895 (diff)
support multiple modules
-rw-r--r--tests/projects/swift/cross_modules/src/A.swift4
-rw-r--r--tests/projects/swift/cross_modules/src/main.swift2
-rw-r--r--tests/projects/swift/cross_modules/xmake.lua5
-rw-r--r--xmake/modules/core/tools/swift_frontend.lua10
-rw-r--r--xmake/rules/swift/xmake.lua13
5 files changed, 33 insertions, 1 deletions
diff --git a/tests/projects/swift/cross_modules/src/A.swift b/tests/projects/swift/cross_modules/src/A.swift
new file mode 100644
index 000000000..746d33dcd
--- /dev/null
+++ b/tests/projects/swift/cross_modules/src/A.swift
@@ -0,0 +1,4 @@
+
+func test() {
+ print("xxxxx")
+}
diff --git a/tests/projects/swift/cross_modules/src/main.swift b/tests/projects/swift/cross_modules/src/main.swift
new file mode 100644
index 000000000..93f0bf310
--- /dev/null
+++ b/tests/projects/swift/cross_modules/src/main.swift
@@ -0,0 +1,2 @@
+
+test()
diff --git a/tests/projects/swift/cross_modules/xmake.lua b/tests/projects/swift/cross_modules/xmake.lua
new file mode 100644
index 000000000..3accaf54e
--- /dev/null
+++ b/tests/projects/swift/cross_modules/xmake.lua
@@ -0,0 +1,5 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+ set_kind("binary")
+ add_files("src/*.swift")
diff --git a/xmake/modules/core/tools/swift_frontend.lua b/xmake/modules/core/tools/swift_frontend.lua
index 25cb08ade..b0edbfa9f 100644
--- a/xmake/modules/core/tools/swift_frontend.lua
+++ b/xmake/modules/core/tools/swift_frontend.lua
@@ -131,8 +131,16 @@ function nf_frameworkdir(self, frameworkdir)
end
-- make the compile arguments list
+-- @see https://github.com/xmake-io/xmake/issues/3916
function compargv(self, sourcefile, objectfile, flags)
- return self:program(), table.join("-c", flags, "-o", objectfile, "-primary-file", sourcefile)
+ local flags_new = {}
+ for _, flag in ipairs(flags) do
+ -- we need remove primary file in swift.build rule
+ if flag ~= sourcefile then
+ table.insert(flags_new, flag)
+ end
+ end
+ return self:program(), table.join("-c", flags_new, "-o", objectfile, "-primary-file", sourcefile)
end
-- compile the source file
diff --git a/xmake/rules/swift/xmake.lua b/xmake/rules/swift/xmake.lua
index 5ebd919c9..d1ea0e886 100644
--- a/xmake/rules/swift/xmake.lua
+++ b/xmake/rules/swift/xmake.lua
@@ -22,6 +22,19 @@
rule("swift.build")
set_sourcekinds("sc")
on_build_files("private.action.build.object", {batch = true})
+ on_config(function (target)
+ -- 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
+ target:add("scflags", "-module-name", target:name(), {force = true})
+ local sourcebatch = target:sourcebatches()["swift.build"]
+ if sourcebatch then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ target:add("scflags", sourcefile, {force = true})
+ end
+ end
+ end
+ end)
-- define rule: swift
rule("swift")