summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-09-30 22:45:25 +0800
committerruki <[email protected]>2025-09-30 22:45:25 +0800
commit3462dede0458b1bf755dcdb24bdc98b6f947188c (patch)
tree0a9c9c7fb33918fc51ed7b1fd39706b8f597d7df
parent703dec087d98946bc2ba5384d2274e588f8ee96d (diff)
improve build cache key
-rw-r--r--xmake/core/base/hash.lua10
-rw-r--r--xmake/core/base/scheduler.lua2
-rw-r--r--xmake/modules/private/cache/build_cache.lua2
3 files changed, 9 insertions, 5 deletions
diff --git a/xmake/core/base/hash.lua b/xmake/core/base/hash.lua
index b40f7b885..342b59e78 100644
--- a/xmake/core/base/hash.lua
+++ b/xmake/core/base/hash.lua
@@ -25,6 +25,7 @@ local hash = hash or {}
local io = require("base/io")
local utils = require("base/utils")
local bytes = require("base/bytes")
+local libc = require("base/libc")
-- save metatable and builtin functions
hash._md5 = hash._md5 or hash.md5
@@ -101,15 +102,18 @@ function hash.uuid(str)
return hash.uuid4(str)
end
--- TODO, we should optimize it
-- generate hash32 from string, e.g. "91e8ecf1"
function hash.strhash32(str)
- return hash.xxhash64(bytes(str)):sub(1, 8)
+ local data = libc.dataptr(str)
+ local size = #str
+ return hash._xxhash(64, data, size):sub(1, 8)
end
-- generate hash128 from string, e.g. "91e8ecf1417f4edfa574e22d7d8d204a"
function hash.strhash128(str)
- return hash.xxhash128(bytes(str))
+ local data = libc.dataptr(str)
+ local size = #str
+ return hash._xxhash(128, data, size)
end
-- return module: hash
diff --git a/xmake/core/base/scheduler.lua b/xmake/core/base/scheduler.lua
index c96b32441..63c9fe009 100644
--- a/xmake/core/base/scheduler.lua
+++ b/xmake/core/base/scheduler.lua
@@ -299,7 +299,7 @@ function scheduler:_co_curenvs_update(envs)
for _, key in ipairs(table.orderkeys(envs)) do
envs_hash = envs_hash .. key:upper() .. envs[key]
end
- envs_hash = hash.uuid4(envs_hash):sub(1, 8)
+ envs_hash = hash.strhash32(envs_hash)
self._CO_CURENVS_HASH = envs_hash
-- save the current directory for each coroutine
diff --git a/xmake/modules/private/cache/build_cache.lua b/xmake/modules/private/cache/build_cache.lua
index 3b82578e5..905426ef5 100644
--- a/xmake/modules/private/cache/build_cache.lua
+++ b/xmake/modules/private/cache/build_cache.lua
@@ -128,7 +128,7 @@ function cachekey(program, cppinfo, envs)
end
end
end
- return hash.xxhash128(bytes(table.concat(items, "")))
+ return hash.strhash128(table.concat(items, ""))
end
-- get cache root directory