summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-12-03 10:15:52 +0800
committerGitHub <[email protected]>2024-12-03 10:15:52 +0800
commitfcabe5855eed5daa8e134e91da17c6acf40f5db0 (patch)
treea0652f175c45d35af2a77297ffa28cda0fa2bf54
parent46ec7f87125cd7824c9ad7b1256693b575f0c576 (diff)
parentd9bc6250c4cab08285cbeab73293886527098f14 (diff)
Merge pull request #5919 from star-hengxing/ccache
Use ccache when debug cmake package
-rw-r--r--xmake/core/project/policy.lua2
-rw-r--r--xmake/modules/package/tools/cmake.lua7
-rw-r--r--xmake/modules/private/action/require/impl/actions/install.lua23
-rw-r--r--xmake/modules/private/tools/ccache.lua10
-rw-r--r--xmake/rules/platform/linux/driver/driver_modules.lua1
5 files changed, 38 insertions, 5 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 1eb28130f..3f7915b84 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -143,6 +143,8 @@ function policy.policies()
["package.cmake_generator.ninja"] = {description = "Set cmake package use ninja for build", type = "boolean"},
-- Enable msbuild MultiToolTask
["package.msbuild.multi_tool_task"] = {description = "Enable msbuild MultiToolTask.", default = false, type = "boolean"},
+ -- C/C++ build cache
+ ["package.build.ccache"] = {description = "Enable C/C++ package build cache.", default = false, type = "boolean"},
-- Stop to test on the first failure
["test.stop_on_first_failure"] = {description = "Stop to test on the first failure", default = false, type = "boolean"},
-- Return zero as exit code on failure
diff --git a/xmake/modules/package/tools/cmake.lua b/xmake/modules/package/tools/cmake.lua
index b0bc9f34d..6d7f15dce 100644
--- a/xmake/modules/package/tools/cmake.lua
+++ b/xmake/modules/package/tools/cmake.lua
@@ -952,6 +952,13 @@ function _get_configs(package, configs, opt)
end
end
_insert_configs_from_envs(configs, envs or {}, opt)
+
+ local ccache = package:data("ccache")
+ if ccache then
+ table.insert(configs, "-DCMAKE_C_COMPILER_LAUNCHER=" .. ccache)
+ table.insert(configs, "-DCMAKE_CXX_COMPILER_LAUNCHER=" .. ccache)
+ end
+
return configs
end
diff --git a/xmake/modules/private/action/require/impl/actions/install.lua b/xmake/modules/private/action/require/impl/actions/install.lua
index 04ecd0036..1e64be14e 100644
--- a/xmake/modules/private/action/require/impl/actions/install.lua
+++ b/xmake/modules/private/action/require/impl/actions/install.lua
@@ -23,8 +23,10 @@ import("core.base.option")
import("core.base.tty")
import("core.package.package", {alias = "core_package"})
import("core.project.target")
+import("core.project.project")
import("core.platform.platform")
import("lib.detect.find_file")
+import("private.tools.ccache")
import("private.action.require.impl.actions.test")
import("private.action.require.impl.actions.patch_sources")
import("private.action.require.impl.actions.download_resources")
@@ -343,6 +345,24 @@ function _enter_package_testenvs(package)
package:envs_enter()
end
+function _enable_ccache(package)
+ if package:is_local() then
+ return
+ end
+
+ if not project.policy("package.build.ccache") then
+ return
+ end
+
+ local ccache = ccache.get()
+ if ccache then
+ local name = path.basename(ccache.program)
+ package:data_set("ccache", name)
+ local ccache_dir = path.join(path.directory(package:cachedir()), name)
+ os.setenv(name:upper() .. "_DIR", ccache_dir)
+ end
+end
+
function main(package)
@@ -387,6 +407,9 @@ function main(package)
-- enter the environments of all package dependencies
_enter_package_installenvs(package)
+ -- set package ccache dir
+ _enable_ccache(package)
+
-- do install
if script ~= nil then
filter.call(script, package, {oldenvs = oldenvs})
diff --git a/xmake/modules/private/tools/ccache.lua b/xmake/modules/private/tools/ccache.lua
index 4a877d2b1..12bb0cdd0 100644
--- a/xmake/modules/private/tools/ccache.lua
+++ b/xmake/modules/private/tools/ccache.lua
@@ -23,18 +23,20 @@ import("core.project.config")
import("lib.detect.find_tool")
-- get ccache tool
-function _ccache()
+function get()
local ccache = _g.ccache
if ccache == nil and config.get("ccache") then
ccache = find_tool("ccache")
+ if not ccache then
+ ccache = find_tool("sccache")
+ end
_g.ccache = ccache or false
end
return ccache or nil
end
--- exists ccache?
function exists()
- return _ccache() ~= nil
+ return get() ~= nil
end
-- uses ccache to wrap the program and arguments
@@ -44,7 +46,7 @@ end
function cmdargv(program, argv)
-- uses ccache?
- local ccache = _ccache()
+ local ccache = get()
if ccache then
-- parse the filename and arguments, e.g. "xcrun -sdk macosx clang"
diff --git a/xmake/rules/platform/linux/driver/driver_modules.lua b/xmake/rules/platform/linux/driver/driver_modules.lua
index a89a28938..8218a972c 100644
--- a/xmake/rules/platform/linux/driver/driver_modules.lua
+++ b/xmake/rules/platform/linux/driver/driver_modules.lua
@@ -24,7 +24,6 @@ import("core.project.depend")
import("core.cache.memcache")
import("lib.detect.find_tool")
import("utils.progress")
-import("private.tools.ccache")
-- get linux-headers sdk
function _get_linux_headers_sdk(target)