summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xmake/rules/rust/build/target.lua64
1 files changed, 63 insertions, 1 deletions
diff --git a/xmake/rules/rust/build/target.lua b/xmake/rules/rust/build/target.lua
index 2acff260e..812ba7f95 100644
--- a/xmake/rules/rust/build/target.lua
+++ b/xmake/rules/rust/build/target.lua
@@ -27,10 +27,72 @@ import("core.project.depend")
-- build the source files
function build_sourcefiles(target, sourcebatch, opt)
+
+ -- is verbose?
+ local verbose = option.get("verbose")
+
+ -- get progress range
+ local progress = assert(opt.progress, "no progress!")
+
+ -- get the target file
+ local targetfile = target:targetfile()
+
+ -- get source files and kind
+ local sourcefiles = sourcebatch.sourcefiles
+ local sourcekind = sourcebatch.sourcekind
+
+ -- get depend file
+ local dependfile = target:dependfile(targetfile)
+
+ -- load compiler
+ local compinst = compiler.load(sourcekind, {target = target})
+
+ -- get compile flags
+ local compflags = compinst:compflags({target = target})
+
+ -- load dependent info
+ local dependinfo = option.get("rebuild") and {} or (depend.load(dependfile) or {})
+
+ -- need build this object?
+ local depvalues = {compinst:program(), compflags}
+ if not depend.is_changed(dependinfo, {lastmtime = os.mtime(targetfile), values = depvalues}) then
+ return
+ end
+
+ -- trace progress into
+ cprintf("${color.build.progress}" .. theme.get("text.build.progress_format") .. ":${clear} ", progress.start)
+ if verbose then
+ cprint("${dim color.build.target}linking.$(mode) %s", path.filename(targetfile))
+ else
+ cprint("${color.build.target}linking.$(mode) %s", path.filename(targetfile))
+ end
+
+ -- trace verbose info
+ if verbose then
+ print(compinst:buildcmd(sourcefiles, targetfile, {target = target, compflags = compflags}))
+ end
+
+ -- flush io buffer to update progress info
+ io.flush()
+
+ -- compile it
+ dependinfo.files = {}
+ assert(compinst:build(sourcefiles, targetfile, {target = target, dependinfo = dependinfo, compflags = compflags}))
+
+ -- update files and values to the dependent file
+ dependinfo.values = depvalues
+ table.join2(dependinfo.files, sourcefiles)
+ depend.save(dependinfo, dependfile)
end
-- build target
function main(target, opt)
- print(opt)
+ -- @note only support one source kind!
+ for _, sourcebatch in pairs(target:sourcebatches()) do
+ if sourcebatch.sourcekind == "rc" then
+ build_sourcefiles(target, sourcebatch, opt)
+ break
+ end
+ end
end