summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-11-05 06:31:44 +0800
committerGitHub <[email protected]>2022-11-05 06:31:44 +0800
commitfbee3ddca4ce14ea537595ddf99067f5d7db6554 (patch)
treedb25b637b7ee15176ff84412ef3b8ba834809ba3
parenta0c0fc7e3517e10e400e6d48338fa596202bd21c (diff)
parentcd121fd4f8134fba82e6377e9c99c76d98c210e5 (diff)
Merge pull request #3017 from star-hengxing/ispc
support ispc compiler
-rw-r--r--tests/projects/other/ispc/.gitignore8
-rw-r--r--tests/projects/other/ispc/src/main.cpp8
-rw-r--r--tests/projects/other/ispc/src/test.ispc1
-rw-r--r--tests/projects/other/ispc/xmake.lua8
-rw-r--r--xmake/rules/utils/ispc/ispc.lua69
5 files changed, 94 insertions, 0 deletions
diff --git a/tests/projects/other/ispc/.gitignore b/tests/projects/other/ispc/.gitignore
new file mode 100644
index 000000000..152105761
--- /dev/null
+++ b/tests/projects/other/ispc/.gitignore
@@ -0,0 +1,8 @@
+# Xmake cache
+.xmake/
+build/
+
+# MacOS Cache
+.DS_Store
+
+
diff --git a/tests/projects/other/ispc/src/main.cpp b/tests/projects/other/ispc/src/main.cpp
new file mode 100644
index 000000000..4694c47c5
--- /dev/null
+++ b/tests/projects/other/ispc/src/main.cpp
@@ -0,0 +1,8 @@
+#include "test_ispc.h"
+
+using namespace ispc;
+
+int main(int argc, char *argv[])
+{
+ test_ispc();
+}
diff --git a/tests/projects/other/ispc/src/test.ispc b/tests/projects/other/ispc/src/test.ispc
new file mode 100644
index 000000000..64506d6ef
--- /dev/null
+++ b/tests/projects/other/ispc/src/test.ispc
@@ -0,0 +1 @@
+export void test_ispc() {} \ No newline at end of file
diff --git a/tests/projects/other/ispc/xmake.lua b/tests/projects/other/ispc/xmake.lua
new file mode 100644
index 000000000..577c6798b
--- /dev/null
+++ b/tests/projects/other/ispc/xmake.lua
@@ -0,0 +1,8 @@
+add_rules("mode.debug", "mode.release")
+
+target("test")
+ set_kind("binary")
+ add_rules("utils.ispc", {header_extension = "_ispc.h"})
+ set_values("ispc.flags", "--target=host")
+ add_files("src/*.ispc")
+ add_files("src/*.cpp")
diff --git a/xmake/rules/utils/ispc/ispc.lua b/xmake/rules/utils/ispc/ispc.lua
new file mode 100644
index 000000000..b1e924c65
--- /dev/null
+++ b/xmake/rules/utils/ispc/ispc.lua
@@ -0,0 +1,69 @@
+rule("utils.ispc")
+ set_extensions(".ispc")
+
+ on_load(function (target)
+ local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers")
+ os.mkdir(headersdir)
+ target:add("includedirs", headersdir, {public = true})
+ end)
+
+ before_buildcmd_file(function (target, batchcmds, sourcefile_ispc, opt)
+ import("lib.detect.find_tool")
+ local ispc = assert(find_tool("ispc"), "ispc not found!")
+
+ local flags = {}
+ if target:values("ispc.flags") then
+ table.join2(flags, target:values("ispc.flags"))
+ end
+
+ if target:get("symbols") == "debug" then
+ table.insert(flags, "-g")
+ end
+
+ if target:get("optimize") == "none" then
+ table.insert(flags, "-O0")
+ elseif target:get("optimize") == "fast" then
+ table.insert(flags, "-O2")
+ elseif target:get("optimize") == "faster" or target:get("optimize") == "fastest" then
+ table.insert(flags, "-O3")
+ elseif target:get("optimize") == "smallest" then
+ table.insert(flags, "-O1")
+ end
+
+ if target:get("warnings") == "none" then
+ table.insert(flags, "--woff")
+ elseif target:get("warnings") == "error" then
+ table.insert(flags, "--werror")
+ end
+
+ if not target:is_plat("windows") then
+ table.insert(flags, "--pic")
+ end
+
+ local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers")
+ local objectfile = target:objectfile(sourcefile_ispc)
+ local objectdir = path.directory(objectfile)
+ local headersfile
+ local header_extension = target:extraconf("rules", "utils.ispc", "header_extension")
+ if header_extension then
+ headersfile = path.join(headersdir, path.basename(sourcefile_ispc) .. header_extension)
+ else
+ headersfile = path.join(headersdir, path.filename(sourcefile_ispc) .. ".h")
+ end
+
+ table.insert(flags, "-o")
+ table.insert(flags, path(objectfile))
+ table.insert(flags, "-h")
+ table.insert(flags, path(headersfile))
+ table.insert(flags, path(sourcefile_ispc))
+
+ batchcmds:show_progress(opt.progress, "${color.build.object}compiling.ispc %s", sourcefile_ispc)
+ batchcmds:mkdir(objectdir)
+ batchcmds:vrunv(ispc.program, flags)
+
+ table.insert(target:objectfiles(), objectfile)
+
+ batchcmds:add_depfiles(sourcefile_ispc, headersfile)
+ batchcmds:set_depmtime(os.mtime(objectfile))
+ batchcmds:set_depcache(target:dependfile(objectfile))
+ end)