-
-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support ispc compiler #3017
support ispc compiler #3017
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Xmake cache | ||
.xmake/ | ||
build/ | ||
|
||
# MacOS Cache | ||
.DS_Store | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include "test_ispc.h" | ||
|
||
using namespace ispc; | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
test_ispc(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export void test_ispc() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use object kind? Example projects should be as simple as possible 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") |
||
|
||
target("test") | ||
set_kind("binary") | ||
add_deps("test_ispc") | ||
add_files("src/*.cpp") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
rule("utils.ispc") | ||
set_extensions(".ispc") | ||
add_deps("utils.inherit.links") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove it |
||
|
||
on_load(function (target) | ||
local header_outputdir = path.join(target:autogendir(), "ispc_headers") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers") |
||
local obj_outputdir = path.join(target:autogendir(), "ispc_objs") | ||
os.mkdir(target:autogendir()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use |
||
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!") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing local keyword
|
||
|
||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. headersdir |
||
local obj_outputdir = path.join(target:autogendir(), "ispc_objs") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. objectdir |
||
local obj_file = path.join(obj_outputdir, path.filename(sourcefile_ispc) .. obj_extension) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename to objectfile |
||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove
|
||
batchcmds:vrunv(ispc.program, table.join2(flags, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use table.insert to insert flags first. it will avoid once object copy. |
||
{"-o", obj_file, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. path(objectfile) |
||
"-h", header_file, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need use |
||
path.join(os.projectdir(), sourcefile_ispc)})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use |
||
|
||
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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate |
||
end) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remove it.