diff options
| author | ruki <[email protected]> | 2024-12-03 10:15:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-03 10:15:52 +0800 |
| commit | fcabe5855eed5daa8e134e91da17c6acf40f5db0 (patch) | |
| tree | a0652f175c45d35af2a77297ffa28cda0fa2bf54 /xmake/modules | |
| parent | 46ec7f87125cd7824c9ad7b1256693b575f0c576 (diff) | |
| parent | d9bc6250c4cab08285cbeab73293886527098f14 (diff) | |
Merge pull request #5919 from star-hengxing/ccache
Use ccache when debug cmake package
Diffstat (limited to 'xmake/modules')
| -rw-r--r-- | xmake/modules/package/tools/cmake.lua | 7 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/install.lua | 23 | ||||
| -rw-r--r-- | xmake/modules/private/tools/ccache.lua | 10 |
3 files changed, 36 insertions, 4 deletions
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" |
