summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-22 21:35:23 +0800
committerruki <[email protected]>2021-08-22 21:35:49 +0800
commitdf288a44eb6c8277d250306add709f9f5f59f0cd (patch)
treedb9fd22b116c7966e7df845e0d6cd4f81e3523cf
parentedf32980cd66c2ee5075ddd9e4a08c7e50f6985e (diff)
link metallib
-rw-r--r--xmake/actions/build/kinds/binary.lua20
-rw-r--r--xmake/actions/build/kinds/shared.lua20
-rw-r--r--xmake/actions/build/kinds/static.lua20
-rw-r--r--xmake/rules/xcode/metal/xmake.lua36
4 files changed, 90 insertions, 6 deletions
diff --git a/xmake/actions/build/kinds/binary.lua b/xmake/actions/build/kinds/binary.lua
index dd72fc21a..b84b518de 100644
--- a/xmake/actions/build/kinds/binary.lua
+++ b/xmake/actions/build/kinds/binary.lua
@@ -25,6 +25,7 @@ import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("private.utils.progress")
+import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
-- do link target
@@ -87,6 +88,13 @@ function _on_link_target(target, opt)
on_link(target, opt)
done = true
end
+ local on_linkcmd = r:script("linkcmd")
+ if on_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ on_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ done = true
+ end
end
if done then return end
@@ -109,6 +117,12 @@ function _link_target(target, opt)
if before_link then
before_link(target, opt)
end
+ local before_linkcmd = r:script("linkcmd_before")
+ if before_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ before_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
-- on link
@@ -126,6 +140,12 @@ function _link_target(target, opt)
if after_link then
after_link(target, opt)
end
+ local after_linkcmd = r:script("linkcmd_after")
+ if after_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ after_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
end
diff --git a/xmake/actions/build/kinds/shared.lua b/xmake/actions/build/kinds/shared.lua
index 2d2d9e507..376d73af3 100644
--- a/xmake/actions/build/kinds/shared.lua
+++ b/xmake/actions/build/kinds/shared.lua
@@ -25,6 +25,7 @@ import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("private.utils.progress")
+import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
-- do link target
@@ -102,6 +103,13 @@ function _on_link_target(target, opt)
on_link(target, opt)
done = true
end
+ local on_linkcmd = r:script("linkcmd")
+ if on_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ on_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ done = true
+ end
end
if done then return end
@@ -124,6 +132,12 @@ function _link_target(target, opt)
if before_link then
before_link(target, opt)
end
+ local before_linkcmd = r:script("linkcmd_before")
+ if before_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ before_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
-- on link
@@ -141,6 +155,12 @@ function _link_target(target, opt)
if after_link then
after_link(target, opt)
end
+ local after_linkcmd = r:script("linkcmd_after")
+ if after_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ after_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
end
diff --git a/xmake/actions/build/kinds/static.lua b/xmake/actions/build/kinds/static.lua
index 91fba6ed5..b3ac57e73 100644
--- a/xmake/actions/build/kinds/static.lua
+++ b/xmake/actions/build/kinds/static.lua
@@ -25,6 +25,7 @@ import("core.tool.linker")
import("core.tool.compiler")
import("core.project.depend")
import("private.utils.progress")
+import("private.utils.batchcmds")
import("object", {alias = "add_batchjobs_for_object"})
-- do link target
@@ -102,6 +103,13 @@ function _on_link_target(target, opt)
on_link(target, opt)
done = true
end
+ local on_linkcmd = r:script("linkcmd")
+ if on_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ on_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ done = true
+ end
end
if done then return end
@@ -124,6 +132,12 @@ function _link_target(target, opt)
if before_link then
before_link(target, opt)
end
+ local before_linkcmd = r:script("linkcmd_before")
+ if before_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ before_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
-- on link
@@ -141,6 +155,12 @@ function _link_target(target, opt)
if after_link then
after_link(target, opt)
end
+ local after_linkcmd = r:script("linkcmd_after")
+ if after_linkcmd then
+ local batchcmds_ = batchcmds.new({target = target})
+ after_linkcmd(target, batchcmds_, {progress = opt.progress})
+ batchcmds_:runcmds({dryrun = option.get("dry-run")})
+ end
end
end
diff --git a/xmake/rules/xcode/metal/xmake.lua b/xmake/rules/xcode/metal/xmake.lua
index d4bc50fea..a8b1fe16d 100644
--- a/xmake/rules/xcode/metal/xmake.lua
+++ b/xmake/rules/xcode/metal/xmake.lua
@@ -47,10 +47,8 @@ rule("xcode.metal")
local cross = target:data("xcode.metal.cross")
local metal = assert(find_tool("metal", {program = cross .. " metal"}), "metal command not found!")
- -- add objectfile (.air)
- local objectfile = target:objectfile(sourcefile) .. ".air"
-
-- add commands
+ local objectfile = target:objectfile(sourcefile) .. ".air"
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.metal %s", sourcefile)
batchcmds:mkdir(path.directory(objectfile))
batchcmds:vrunv(metal.program, {"-c", "-o", objectfile, sourcefile})
@@ -59,10 +57,36 @@ rule("xcode.metal")
batchcmds:add_depfiles(sourcefile)
batchcmds:set_depmtime(os.mtime(objectfile))
batchcmds:set_depcache(target:dependfile(objectfile))
-
end)
-- link *.air to *.metallib
- on_linkcmd(function (target, batchcmds, opt)
- print("linkcmd")
+ before_linkcmd(function (target, batchcmds, opt)
+
+ -- get metallib
+ import("lib.detect.find_tool")
+ local cross = target:data("xcode.metal.cross")
+ local metallib = assert(find_tool("metallib", {program = cross .. " metallib"}), "metallib command not found!")
+
+ -- get objectfiles
+ local objectfiles = {}
+ for rulename, sourcebatch in pairs(target:sourcebatches()) do
+ if rulename == "xcode.metal" then
+ for _, sourcefile in ipairs(sourcebatch.sourcefiles) do
+ table.insert(objectfiles, target:objectfile(sourcefile) .. ".air")
+ end
+ break
+ end
+ end
+ assert(#objectfiles > 0, "*.air files not found!")
+
+ -- add commands
+ local libraryfile = "default.metallib"
+ batchcmds:show_progress(opt.progress, "${color.build.target}linking.metal %s", libraryfile)
+ batchcmds:mkdir(path.directory(libraryfile))
+ batchcmds:vrunv(metallib.program, table.join({"-o", libraryfile}, objectfiles))
+
+ -- add deps
+ batchcmds:add_depfiles(objectfiles)
+ batchcmds:set_depmtime(os.mtime(libraryfile))
+ batchcmds:set_depcache(target:dependfile(libraryfile))
end)