summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-08-22 00:49:04 +0800
committerruki <[email protected]>2024-08-22 00:49:04 +0800
commit906fa7a6d77e20190ebe943361e53c595237e52e (patch)
tree960ee5521e3112addc64d214930abeb8cbd8fa29
parent7b05f6e814dedea34ca11a27833e7c39c3afe246 (diff)
archive xmake.xmz
-rw-r--r--core/src/demo/xmake.lua12
-rw-r--r--core/xmake.lua7
-rw-r--r--xmake/modules/utils/archive/archive_xmz.lua7
3 files changed, 23 insertions, 3 deletions
diff --git a/core/src/demo/xmake.lua b/core/src/demo/xmake.lua
index f519dd88a..f0900402d 100644
--- a/core/src/demo/xmake.lua
+++ b/core/src/demo/xmake.lua
@@ -88,3 +88,15 @@ target("demo")
end
end)
+ -- embed all script files
+ add_rules("utils.bin2c", {linewidth = 16, extensions = ".xmz"})
+ on_config(function (target)
+ import("utils.archive.archive")
+ if has_config("embed") then
+ local archivefile = path.join(target:autogendir(), "bin2c", "xmake.xmz")
+ print("archiving %s ..", archivefile)
+ os.tryrm(archivefile)
+ local rootdir = path.normalize(path.join(os.projectdir(), "..", "xmake"))
+ archive(archivefile, rootdir, {recurse = true, curdir = rootdir})
+ end
+ end)
diff --git a/core/xmake.lua b/core/xmake.lua
index 28bf4f22b..45fd9b2c1 100644
--- a/core/xmake.lua
+++ b/core/xmake.lua
@@ -55,8 +55,11 @@ if has_config("cosmocc") then
set_policy("build.ccache", false)
end
--- the cosmocc option
-option("cosmocc", {default = false, category = "option", description = "Use cosmocc toolchain to build once and run anywhere."})
+-- use cosmocc toolchain
+option("cosmocc", {default = false, description = "Use cosmocc toolchain to build once and run anywhere."})
+
+-- embed all script files
+option("embed", {default = false, description = "Embed all script files."})
-- the runtime option
option("runtime")
diff --git a/xmake/modules/utils/archive/archive_xmz.lua b/xmake/modules/utils/archive/archive_xmz.lua
index 6cf2c13aa..7f4425578 100644
--- a/xmake/modules/utils/archive/archive_xmz.lua
+++ b/xmake/modules/utils/archive/archive_xmz.lua
@@ -25,9 +25,14 @@ import("core.compress.lz4")
-- archive files
function _archive_files(archivefile, inputfiles, opt)
+ local curdir = opt.curdir
local outputfile = io.open(archivefile, "wb")
for _, inputfile in ipairs(inputfiles) do
- outputfile:write(bytes(2):u16be_set(1, #inputfile))
+ local filepath = inputfile
+ if curdir then
+ filepath = path.relative(filepath, curdir)
+ end
+ outputfile:write(bytes(2):u16be_set(1, #filepath))
outputfile:write(inputfile)
local data = io.readfile(inputfile, {encoding = "binary"})
vprint("archiving %s, %d bytes", inputfile, data and #data or 0)