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

support ispc compiler #3017

merged 5 commits into from
Nov 4, 2022

Conversation

star-hengxing
Copy link
Contributor

No description provided.

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)
Copy link
Member

Choose a reason for hiding this comment

The 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")

@@ -0,0 +1,16 @@
add_rules("mode.debug", "mode.release")

includes("ispc.lua")
Copy link
Member

Choose a reason for hiding this comment

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

please remove it.

@@ -0,0 +1,77 @@
rule("utils.ispc")
set_extensions(".ispc")
add_deps("utils.inherit.links")
Copy link
Member

Choose a reason for hiding this comment

The 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")
local obj_outputdir = path.join(target:autogendir(), "ispc_objs")
os.mkdir(target:autogendir())
Copy link
Member

Choose a reason for hiding this comment

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

we should use batchcmds:mkdir in before_buildcmd_file, only obj_outputdir need be create here

before_buildcmd_file(function (target, batchcmds, sourcefile_ispc, opt)
import("lib.detect.find_tool")
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!")

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)
Copy link
Member

Choose a reason for hiding this comment

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

remove cache prefix

"${color.build.object}cache compiling.ispc %s"


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)
Copy link
Member

Choose a reason for hiding this comment

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

rename to objectfile

end

local header_outputdir = path.join(target:autogendir(), "ispc_headers")
local obj_outputdir = 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.

objectdir

obj_extension = ".obj"
end

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.

headersdir

batchcmds:vrunv(ispc.program, table.join2(flags,
{"-o", obj_file,
"-h", header_file,
path.join(os.projectdir(), 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.

why not use sourcefile_ispc directly

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,
Copy link
Member

Choose a reason for hiding this comment

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

you need use path(headerfile) to wrap it for supporting project generator.


batchcmds:show_progress(opt.progress, "${color.build.object}cache compiling %s", sourcefile_ispc)
batchcmds:vrunv(ispc.program, table.join2(flags,
{"-o", obj_file,
Copy link
Member

Choose a reason for hiding this comment

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

path(objectfile)

end

batchcmds:show_progress(opt.progress, "${color.build.object}cache compiling %s", sourcefile_ispc)
batchcmds:vrunv(ispc.program, table.join2(flags,
Copy link
Member

Choose a reason for hiding this comment

The 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.

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))
Copy link
Member

Choose a reason for hiding this comment

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

duplicate set_depmtime and set_depcache, you can only set once

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")

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

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")

end

local headersdir = path.join(target:autogendir(), "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 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)
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)


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)))
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)
        local objectdir = path.directory(objectfile)

@waruqi waruqi marked this pull request as ready for review November 4, 2022 15:59
@waruqi waruqi merged commit fbee3dd into xmake-io:dev Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants