Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build.ccache.global_storage policy is not working as expected #5793

Closed
for2years opened this issue Nov 6, 2024 · 11 comments
Closed

build.ccache.global_storage policy is not working as expected #5793

for2years opened this issue Nov 6, 2024 · 11 comments
Labels

Comments

@for2years
Copy link

Xmake Version

v2.9.6

Operating System Version and Architecture

ubuntu 2204

Describe Bug

I cloned two identical projects on the same machine and set set_policy("build.ccache.global_storage", true) for both.

However, after compilation the another repo, the cache hit rate is 0.

Expected Behavior

These two identical projects should share the same ccache in ~/.xmake/.build_cache.

Project Configuration

none

Additional Information and Error Logs

build cache stats:
cache directory: /root/.xmake/.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0.000s
cache miss: 453
cache miss total time: 0.209s
new cached files: 453
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 3
compile total time: 5406.370s
@for2years for2years added the bug label Nov 6, 2024
@waruqi
Copy link
Member

waruqi commented Nov 6, 2024

it works for me. you can debug here.

if not cachedir and project.policy("build.ccache.global_storage") then
cachedir = path.join(global.directory(), ".build_cache")
end

ruki-2:test ruki$ xmake -r
[ 50%]: cache compiling.release src/main.cpp
ccachedir
ccachedir2 /Users/ruki/.xmake/.build_cache
[ 75%]: linking.release test
[100%]: build ok, spent 0.772s
ruki-2:test ruki$ tree ~/.xmake/.build_cache/
/Users/ruki/.xmake/.build_cache/
└── 42
    └── 42f0b0efe4f63b66f9833ec1252d169d
add_rules("mode.debug", "mode.release")
set_policy("build.ccache.global_storage", true)

target("test")
    set_kind("binary")
    add_files("src/*.cpp")

@for2years
Copy link
Author

for2years commented Nov 6, 2024

if not cachedir and project.policy("build.ccache.global_storage") then
cachedir = path.join(global.directory(), ".build_cache")
end

set_policy("build.ccache.global_storage", true) do indeed redirect the ccache directory to ~/.xmake/.build_cache.

However, my question is that for two same projects in different directory but same machine, the cache hit rate should not be 0 after compiling them sequentially.

@for2years
Copy link
Author

I want to use this policy because I cloned the same project in different directories on the same machine, like ~/A/my_project and ~/B/my_project, so I expect them to share the same cache.

@waruqi
Copy link
Member

waruqi commented Nov 6, 2024

it still works for me.

ruki-2:tmp ruki$ cp -r test test2
ruki-2:test2 ruki$ xmake -r
[ 50%]: cache compiling.release src/main.cpp
ccachedir
ccachedir2 /Users/ruki/.xmake/.build_cache
[ 75%]: linking.release test
[100%]: build ok, spent 1.775s
ruki-2:test2 ruki$ tree ~/.xmake/.build_cache/
/Users/ruki/.xmake/.build_cache/
└── 42
    └── 42f0b0efe4f63b66f9833ec1252d169d
build cache stats:
cache directory: /Users/ruki/.xmake/.build_cache
cache hit rate: 100%
cache hit: 1
cache hit total time: 0.002s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s
ruki-2:test2 ruki$ cp -r test ../test3
cp: test: No such file or directory
ruki-2:test2 ruki$ cd ^C
ruki-2:test2 ruki$ cd ..
ruki-2:tmp ruki$ cp -r test test3
ruki-2:tmp ruki$ cd test3
ruki-2:test3 ruki$ xmake -rvD
checking for Xcode directory ... /Applications/Xcode.app
checking for Codesign Identity of Xcode ... Apple Development: [email protected] (T3NA4MRVPU)
checking for SDK version of Xcode for macosx (x86_64) ... 14.0
checking for Minimal target version of Xcode for macosx (x86_64) ... 14.0
checkinfo: cannot runv(zig version), No such file or directory
checking for zig ... no
checkinfo: cannot runv(zig version), No such file or directory
checking for zig ... no
checking for nim ... /usr/local/bin/nim
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr
/bin/clang ... ok
checking for the c   compiler (cxx) ... clang
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr
/bin/clang ... ok
checking for flags (-fPIC) ... ok
> clang "-fPIC" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applicati
ons/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
checking for flags (-fvisibility-inlines-hidden) ... ok
> clang "-fvisibility-inlines-hidden" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "
-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
/MacOSX14.0.sdk"
checking for flags (-O3) ... ok
> clang "-O3" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Application
s/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
checking for flags (-DNDEBUG) ... ok
> clang "-DNDEBUG" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applic
ations/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
[ 50%]: cache compiling.release src/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -c
 -Qunused-arguments -target x86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/D
eveloper/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -fvisibility=hidden -fvisibili
ty-inlines-hidden -O3 -DNDEBUG -o build/.objs/test/macosx/x86_64/release/src/main.cpp.o src/mai
n.cpp
checking for flags (-MMD -MF) ... ok
> clang "-MMD" "-MF" "/dev/null" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isys
root" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacO
SX14.0.sdk"
checking for flags (-fdiagnostics-color=always) ... ok
> clang "-fdiagnostics-color=always" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-
isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX14.0.sdk"
ccachedir
ccachedir2 /Users/ruki/.xmake/.build_cache
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr
/bin/clang   ... ok
checking for the linker (ld) ... clang  
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr
/bin/clang   ... ok
checking for flags (-fPIC) ... ok
> clang   "-fPIC" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applications/Xcode.app/Conte
nts/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk" "-lz" "-target" "x86_64-
apple-macos14.0" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platf
orm/Developer/SDKs/MacOSX14.0.sdk" "-lz"
[ 75%]: linking.release test
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  
-o build/macosx/x86_64/release/test build/.objs/test/macosx/x86_64/release/src/main.cpp.o -targ
et x86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX
.platform/Developer/SDKs/MacOSX14.0.sdk -lz -Wl,-x -Wl,-dead_strip

build cache stats:
cache directory: /Users/ruki/.xmake/.build_cache
cache hit rate: 100%
cache hit: 1
cache hit total time: 0.002s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s

[100%]: build ok, spent 0.925s

@for2years
Copy link
Author

ok thanks, I try to debug it.

@for2years
Copy link
Author

for2years commented Nov 7, 2024

The reason is that I used add_includedirs(os.projectdir()) which caused the compile parameters to be inconsistent.
I replace it with add_includedirs(".") and fix it.

Another issue is that if my target is a proto-target to generate *.h and *.cc according to *.proto files like:

target("my_proto_target")
    set_kind("object")
    add_rules("protobuf.cpp")
    add_files("proto/*.proto", {proto_public = true})
    add_packages("protobuf-cpp", {public = true})

It does not generate any cache files, rusulting in a cache hit rate of 0, what should I do to reuse the cache for proto files?

@waruqi
Copy link
Member

waruqi commented Nov 7, 2024

same cache policy. you can debug proto files compilation flags.

And this issue should have been resolved. build.ccache.global_storage policy has no any problem.

@for2years
Copy link
Author

ok thanks anyway~

@for2years
Copy link
Author

you can debug proto files compilation flags.

Do you have any suggestions to help me debug the no-cache-problem for proto files. I don't know where to start actually.

@waruqi
Copy link
Member

waruqi commented Nov 7, 2024

cppinfo = build_cache.build(program, argv, {envs = self:runenvs(),

local cachekey = cachekey(program, cppinfo, opt.envs)

check the cache key and cppinfo

@for2years
Copy link
Author

ok I will try it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants