From f3e2f3cda0372e4d64c2aa83b1fd5c101e349417 Mon Sep 17 00:00:00 2001 From: star-hengxing Date: Thu, 3 Nov 2022 20:05:00 +0800 Subject: [PATCH 1/5] add ispc --- tests/projects/other/ispc/.gitignore | 8 +++ tests/projects/other/ispc/src/main.cpp | 8 +++ tests/projects/other/ispc/src/test.ispc | 1 + tests/projects/other/ispc/xmake.lua | 16 +++++ xmake/rules/utils/ispc/ispc.lua | 77 +++++++++++++++++++++++++ 5 files changed, 110 insertions(+) create mode 100644 tests/projects/other/ispc/.gitignore create mode 100644 tests/projects/other/ispc/src/main.cpp create mode 100644 tests/projects/other/ispc/src/test.ispc create mode 100644 tests/projects/other/ispc/xmake.lua create mode 100644 xmake/rules/utils/ispc/ispc.lua diff --git a/tests/projects/other/ispc/.gitignore b/tests/projects/other/ispc/.gitignore new file mode 100644 index 00000000000..15210576129 --- /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 00000000000..4694c47c5fd --- /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 00000000000..64506d6ef7b --- /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 00000000000..a7311abec69 --- /dev/null +++ b/tests/projects/other/ispc/xmake.lua @@ -0,0 +1,16 @@ +add_rules("mode.debug", "mode.release") + +includes("ispc.lua") + +target("test_ispc") + set_kind("object") + add_rules("utils.ispc", {header_extension = "_ispc.h"}) + add_files("src/*.ispc") + set_values("ispc.flags", "--target=host") + set_policy("build.across_targets_in_parallel", false) + +target("test") + set_kind("binary") + add_deps("test_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 00000000000..9a65e5d9446 --- /dev/null +++ b/xmake/rules/utils/ispc/ispc.lua @@ -0,0 +1,77 @@ +rule("utils.ispc") + set_extensions(".ispc") + add_deps("utils.inherit.links") + + on_load(function (target) + local header_outputdir = path.join(target:autogendir(), "ispc_headers") + local obj_outputdir = path.join(target:autogendir(), "ispc_objs") + os.mkdir(target:autogendir()) + os.mkdir(header_outputdir) + os.mkdir(obj_outputdir) + target:add("includedirs", header_outputdir, {public = true}) + end) + before_buildcmd_file(function (target, batchcmds, sourcefile_ispc, opt) + import("lib.detect.find_tool") + ispc = find_tool("ispc") + assert(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 obj_extension = ".o" + if target:is_plat("windows") then + obj_extension = ".obj" + end + + local header_outputdir = path.join(target:autogendir(), "ispc_headers") + local obj_outputdir = path.join(target:autogendir(), "ispc_objs") + local obj_file = path.join(obj_outputdir, path.filename(sourcefile_ispc) .. obj_extension) + + local header_file + local header_extension = target:extraconf("rules", "utils.ispc", "header_extension") + if header_extension then + header_file = path.join(header_outputdir, path.basename(sourcefile_ispc) .. header_extension) + else + header_file = path.join(header_outputdir, path.filename(sourcefile_ispc) .. ".h") + end + + batchcmds:show_progress(opt.progress, "${color.build.object}cache compiling %s", sourcefile_ispc) + batchcmds:vrunv(ispc.program, table.join2(flags, + {"-o", obj_file, + "-h", header_file, + path.join(os.projectdir(), sourcefile_ispc)})) + + table.insert(target:objectfiles(), obj_file) + + batchcmds:add_depfiles(sourcefile_ispc) + batchcmds:set_depmtime(os.mtime(obj_file)) + batchcmds:set_depcache(target:dependfile(obj_file)) + batchcmds:set_depmtime(os.mtime(header_file)) + batchcmds:set_depcache(target:dependfile(header_file)) + end) \ No newline at end of file From de83803cdb0c2ab94fbcd203f831602c7d418fe1 Mon Sep 17 00:00:00 2001 From: star-hengxing Date: Fri, 4 Nov 2022 15:16:23 +0800 Subject: [PATCH 2/5] improve utils.ispc --- tests/projects/other/ispc/xmake.lua | 14 +++------- xmake/rules/utils/ispc/ispc.lua | 41 +++++++++++++---------------- 2 files changed, 22 insertions(+), 33 deletions(-) diff --git a/tests/projects/other/ispc/xmake.lua b/tests/projects/other/ispc/xmake.lua index a7311abec69..577c6798b5f 100644 --- a/tests/projects/other/ispc/xmake.lua +++ b/tests/projects/other/ispc/xmake.lua @@ -1,16 +1,8 @@ add_rules("mode.debug", "mode.release") -includes("ispc.lua") - -target("test_ispc") - set_kind("object") - add_rules("utils.ispc", {header_extension = "_ispc.h"}) - add_files("src/*.ispc") - set_values("ispc.flags", "--target=host") - set_policy("build.across_targets_in_parallel", false) - target("test") set_kind("binary") - add_deps("test_ispc") + 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 index 9a65e5d9446..d5a4660d2a7 100644 --- a/xmake/rules/utils/ispc/ispc.lua +++ b/xmake/rules/utils/ispc/ispc.lua @@ -1,18 +1,14 @@ rule("utils.ispc") set_extensions(".ispc") - add_deps("utils.inherit.links") on_load(function (target) local header_outputdir = path.join(target:autogendir(), "ispc_headers") - local obj_outputdir = path.join(target:autogendir(), "ispc_objs") - os.mkdir(target:autogendir()) os.mkdir(header_outputdir) - os.mkdir(obj_outputdir) target:add("includedirs", header_outputdir, {public = true}) end) before_buildcmd_file(function (target, batchcmds, sourcefile_ispc, opt) import("lib.detect.find_tool") - ispc = find_tool("ispc") + local ispc = find_tool("ispc") assert(ispc, "ispc not found!") local flags = {} @@ -49,29 +45,30 @@ rule("utils.ispc") obj_extension = ".obj" end - local header_outputdir = path.join(target:autogendir(), "ispc_headers") - local obj_outputdir = path.join(target:autogendir(), "ispc_objs") - local obj_file = path.join(obj_outputdir, path.filename(sourcefile_ispc) .. obj_extension) + local headersdir = path.join(target:autogendir(), "ispc_headers") + local objectdir = path.join(target:autogendir(), "ispc_objs") + local objectfile = path.join(objectdir, path.filename(sourcefile_ispc) .. obj_extension) + batchcmds:mkdir(objectdir) - local header_file + local headersfile local header_extension = target:extraconf("rules", "utils.ispc", "header_extension") if header_extension then - header_file = path.join(header_outputdir, path.basename(sourcefile_ispc) .. header_extension) + headersfile = path.join(headersdir, path.basename(sourcefile_ispc) .. header_extension) else - header_file = path.join(header_outputdir, path.filename(sourcefile_ispc) .. ".h") + headersfile = path.join(headersdir, path.filename(sourcefile_ispc) .. ".h") end - batchcmds:show_progress(opt.progress, "${color.build.object}cache compiling %s", sourcefile_ispc) - batchcmds:vrunv(ispc.program, table.join2(flags, - {"-o", obj_file, - "-h", header_file, - path.join(os.projectdir(), sourcefile_ispc)})) + 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 %s", sourcefile_ispc) + batchcmds:vrunv(ispc.program, flags) - table.insert(target:objectfiles(), obj_file) + table.insert(target:objectfiles(), objectfile) - batchcmds:add_depfiles(sourcefile_ispc) - batchcmds:set_depmtime(os.mtime(obj_file)) - batchcmds:set_depcache(target:dependfile(obj_file)) - batchcmds:set_depmtime(os.mtime(header_file)) - batchcmds:set_depcache(target:dependfile(header_file)) + batchcmds:add_depfiles(sourcefile_ispc, headersfile) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) end) \ No newline at end of file From 19643c9de5f8f2277aaf2ff651acd53b2e97348c Mon Sep 17 00:00:00 2001 From: star-hengxing Date: Fri, 4 Nov 2022 17:18:45 +0800 Subject: [PATCH 3/5] fix util.iscp generate path --- xmake/rules/utils/ispc/ispc.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/xmake/rules/utils/ispc/ispc.lua b/xmake/rules/utils/ispc/ispc.lua index d5a4660d2a7..044681b448a 100644 --- a/xmake/rules/utils/ispc/ispc.lua +++ b/xmake/rules/utils/ispc/ispc.lua @@ -2,9 +2,9 @@ rule("utils.ispc") set_extensions(".ispc") on_load(function (target) - local header_outputdir = path.join(target:autogendir(), "ispc_headers") - os.mkdir(header_outputdir) - target:add("includedirs", header_outputdir, {public = true}) + 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") @@ -40,15 +40,9 @@ rule("utils.ispc") table.insert(flags, "--pic") end - local obj_extension = ".o" - if target:is_plat("windows") then - obj_extension = ".obj" - end - - local headersdir = path.join(target:autogendir(), "ispc_headers") - local objectdir = path.join(target:autogendir(), "ispc_objs") - local objectfile = path.join(objectdir, path.filename(sourcefile_ispc) .. obj_extension) - batchcmds:mkdir(objectdir) + local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers") + local objectdir = path.join(target:autogendir(), "rules", "utils", "ispc", "objs") + local objectfile = path.join(objectdir, path.filename(target:objectfile(sourcefile_ispc))) local headersfile local header_extension = target:extraconf("rules", "utils.ispc", "header_extension") @@ -64,6 +58,7 @@ rule("utils.ispc") table.insert(flags, path(headersfile)) table.insert(flags, path(sourcefile_ispc)) batchcmds:show_progress(opt.progress, "${color.build.object}compiling %s", sourcefile_ispc) + batchcmds:mkdir(objectdir) batchcmds:vrunv(ispc.program, flags) table.insert(target:objectfiles(), objectfile) From c33fd0e8124cf49e5397e46ff8b95ad1da715cb0 Mon Sep 17 00:00:00 2001 From: star-hengxing Date: Fri, 4 Nov 2022 22:59:28 +0800 Subject: [PATCH 4/5] mv ispc obj to targe objectdir --- xmake/rules/utils/ispc/ispc.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xmake/rules/utils/ispc/ispc.lua b/xmake/rules/utils/ispc/ispc.lua index 044681b448a..66a1fe6955c 100644 --- a/xmake/rules/utils/ispc/ispc.lua +++ b/xmake/rules/utils/ispc/ispc.lua @@ -41,8 +41,8 @@ rule("utils.ispc") end local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers") - local objectdir = path.join(target:autogendir(), "rules", "utils", "ispc", "objs") - local objectfile = path.join(objectdir, path.filename(target:objectfile(sourcefile_ispc))) + local objectfile = target:objectfile(sourcefile_ispc) + local objectdir = path.directory(objectfile) local headersfile local header_extension = target:extraconf("rules", "utils.ispc", "header_extension") From cd121fd4f8134fba82e6377e9c99c76d98c210e5 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 4 Nov 2022 23:58:37 +0800 Subject: [PATCH 5/5] Update ispc.lua --- xmake/rules/utils/ispc/ispc.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/xmake/rules/utils/ispc/ispc.lua b/xmake/rules/utils/ispc/ispc.lua index 66a1fe6955c..b1e924c6563 100644 --- a/xmake/rules/utils/ispc/ispc.lua +++ b/xmake/rules/utils/ispc/ispc.lua @@ -6,10 +6,10 @@ rule("utils.ispc") 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 = find_tool("ispc") - assert(ispc, "ispc not found!") + local ispc = assert(find_tool("ispc"), "ispc not found!") local flags = {} if target:values("ispc.flags") then @@ -43,7 +43,6 @@ rule("utils.ispc") 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 @@ -57,7 +56,8 @@ rule("utils.ispc") table.insert(flags, "-h") table.insert(flags, path(headersfile)) table.insert(flags, path(sourcefile_ispc)) - batchcmds:show_progress(opt.progress, "${color.build.object}compiling %s", sourcefile_ispc) + + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.ispc %s", sourcefile_ispc) batchcmds:mkdir(objectdir) batchcmds:vrunv(ispc.program, flags) @@ -66,4 +66,4 @@ rule("utils.ispc") batchcmds:add_depfiles(sourcefile_ispc, headersfile) batchcmds:set_depmtime(os.mtime(objectfile)) batchcmds:set_depcache(target:dependfile(objectfile)) - end) \ No newline at end of file + end)