You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
3.8 KiB
96 lines
3.8 KiB
rule("generate.ispc")
|
|
set_extensions(".ispc")
|
|
|
|
on_config(function (target)
|
|
local headersdir = path.join(target:autogendir(), "rules", "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", "ispc", "headers")
|
|
local objectfile = target:objectfile(sourcefile_ispc)
|
|
local objectdir = path.directory(objectfile)
|
|
local headersfile
|
|
local header_extension = target:extraconf("rules", "generate.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
|
|
local arch = target:extraconf("rules", "generate.ispc", "arch")
|
|
if arch then
|
|
table.insert(flags, "--arch=" .. arch)
|
|
end
|
|
local target_list = target:extraconf("rules", "generate.ispc", "target_list")
|
|
if target_list then
|
|
local targets = ""
|
|
for _, target_item in ipairs(target_list) do
|
|
targets = targets .. target_item .. ","
|
|
end
|
|
table.insert(flags, "--target=" .. targets)
|
|
end
|
|
|
|
table.insert(flags, "-o")
|
|
table.insert(flags, path(objectfile))
|
|
table.insert(flags, "-h")
|
|
table.insert(flags, path(headersfile))
|
|
table.insert(flags, "-I")
|
|
table.insert(flags, os.projectdir())
|
|
table.insert(flags, path(sourcefile_ispc))
|
|
|
|
local compile_flags = "ispc "
|
|
for _, flag in ipairs(flags) do
|
|
compile_flags = compile_flags .. tostring(flag) .. " "
|
|
end
|
|
print("try building ispc file: %s", compile_flags)
|
|
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)
|
|
if table.getn(target_list) > 1 then
|
|
for _, target_item in ipairs(target_list) do
|
|
i, _ = string.find(target_item, "[.-]")
|
|
obj_suffix = string.sub(target_item, 1, i-1)
|
|
obj_suffix = string.gsub(obj_suffix, "avx1", "avx")
|
|
table.insert(target:objectfiles(), target:objectfile(sourcefile_ispc .. "_" .. obj_suffix))
|
|
end
|
|
end
|
|
|
|
batchcmds:add_depfiles(sourcefile_ispc, headersfile)
|
|
batchcmds:set_depmtime(os.mtime(objectfile))
|
|
batchcmds:set_depcache(target:dependfile(objectfile))
|
|
end)
|