summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-06-27 13:14:57 +0800
committerGitHub <[email protected]>2025-06-27 13:14:57 +0800
commit6341e551e5543349a6bec3ee7636a9065a8b7b0d (patch)
treef52b03e9e6f8c28f64b512f3f3bd9bce7de37cb2
parente2c60ab5bc58d4e0a769591b1ad58285d638ccca (diff)
parent3e793c4de711bf7870ad12b6fefb1603d0047e57 (diff)
Merge pull request #6592 from xmake-io/objectonly
Fix objectonly targets
-rw-r--r--tests/projects/other/object_only/.gitignore8
-rw-r--r--tests/projects/other/object_only/src/foo.cpp5
-rw-r--r--tests/projects/other/object_only/src/foo.h9
-rw-r--r--tests/projects/other/object_only/src/main.cpp7
-rw-r--r--tests/projects/other/object_only/test.lua3
-rw-r--r--tests/projects/other/object_only/xmake.lua16
-rw-r--r--xmake/modules/private/action/build/build_binary.lua14
7 files changed, 57 insertions, 5 deletions
diff --git a/tests/projects/other/object_only/.gitignore b/tests/projects/other/object_only/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/other/object_only/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/other/object_only/src/foo.cpp b/tests/projects/other/object_only/src/foo.cpp
new file mode 100644
index 000000000..1a1fb3425
--- /dev/null
+++ b/tests/projects/other/object_only/src/foo.cpp
@@ -0,0 +1,5 @@
+#include "foo.h"
+
+int add(int a, int b) {
+ return a + b;
+}
diff --git a/tests/projects/other/object_only/src/foo.h b/tests/projects/other/object_only/src/foo.h
new file mode 100644
index 000000000..d2506bca9
--- /dev/null
+++ b/tests/projects/other/object_only/src/foo.h
@@ -0,0 +1,9 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int add(int a, int b);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/projects/other/object_only/src/main.cpp b/tests/projects/other/object_only/src/main.cpp
new file mode 100644
index 000000000..d55d4d342
--- /dev/null
+++ b/tests/projects/other/object_only/src/main.cpp
@@ -0,0 +1,7 @@
+#include "foo.h"
+#include <iostream>
+
+int main(int argc, char** argv) {
+ std::cout << "add(1, 2) = " << add(1, 2) << std::endl;
+ return 0;
+}
diff --git a/tests/projects/other/object_only/test.lua b/tests/projects/other/object_only/test.lua
new file mode 100644
index 000000000..b57362078
--- /dev/null
+++ b/tests/projects/other/object_only/test.lua
@@ -0,0 +1,3 @@
+function main(t)
+ t:build()
+end
diff --git a/tests/projects/other/object_only/xmake.lua b/tests/projects/other/object_only/xmake.lua
new file mode 100644
index 000000000..94f42407f
--- /dev/null
+++ b/tests/projects/other/object_only/xmake.lua
@@ -0,0 +1,16 @@
+add_rules("mode.debug", "mode.release")
+
+target("bar")
+ set_kind("object")
+ add_files("src/foo.cpp")
+
+target("foo")
+ set_kind("static")
+ add_deps("bar")
+ add_rules("c++")
+
+target("test")
+ set_kind("binary")
+ add_deps("foo")
+ add_files("src/main.cpp")
+
diff --git a/xmake/modules/private/action/build/build_binary.lua b/xmake/modules/private/action/build/build_binary.lua
index 3863b8550..a29ed4f60 100644
--- a/xmake/modules/private/action/build/build_binary.lua
+++ b/xmake/modules/private/action/build/build_binary.lua
@@ -28,11 +28,15 @@ function main(jobgraph, target, opt)
jobgraph:group(objects_group, function ()
build_object(jobgraph, target, opt)
end)
- if jobgraph:size() > jobsize then
- local link_group = target:fullname() .. "/link"
- jobgraph:group(link_group, function ()
- target_buildutils.add_linkjobs(jobgraph, target, opt)
- end)
+ local has_object_jobs = jobgraph:size() > jobsize
+
+ -- @note We always need the link task, even if the current target does not have any object files
+ -- https://github.com/xmake-io/xmake-repo/pull/7479#issuecomment-3007049158
+ local link_group = target:fullname() .. "/link"
+ jobgraph:group(link_group, function ()
+ target_buildutils.add_linkjobs(jobgraph, target, opt)
+ end)
+ if has_object_jobs then
jobgraph:add_orders(objects_group, link_group)
end
end