Skip to content
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

Merged
merged 5 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/projects/other/ispc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


8 changes: 8 additions & 0 deletions tests/projects/other/ispc/src/main.cpp
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();
}
1 change: 1 addition & 0 deletions tests/projects/other/ispc/src/test.ispc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export void test_ispc() {}
8 changes: 8 additions & 0 deletions tests/projects/other/ispc/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")
74 changes: 74 additions & 0 deletions xmake/rules/utils/ispc/ispc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
rule("utils.ispc")
set_extensions(".ispc")

on_load(function (target)
local header_outputdir = path.join(target:autogendir(), "ispc_headers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers")

os.mkdir(header_outputdir)
target:add("includedirs", header_outputdir, {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!")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing local keyword

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 obj_extension = ".o"
if target:is_plat("windows") then
obj_extension = ".obj"
end

local headersdir = path.join(target:autogendir(), "ispc_headers")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        local headersdir = path.join(target:autogendir(), "rules", "utils", "ispc", "headers")

local objectdir = path.join(target:autogendir(), "ispc_objs")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

local objectfile = path.join(objectdir, path.filename(sourcefile_ispc) .. obj_extension)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local objectfile = target:objectfile(sourcefile_ispc)

batchcmds:mkdir(objectdir)

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 %s", sourcefile_ispc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

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)