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

Make hashes less dependent on source and build paths #207

Closed
mbitsnbites opened this issue Dec 5, 2017 · 6 comments
Closed

Make hashes less dependent on source and build paths #207

mbitsnbites opened this issue Dec 5, 2017 · 6 comments

Comments

@mbitsnbites
Copy link
Contributor

mbitsnbites commented Dec 5, 2017

Currently I was not able to properly use a shared cache between two machines without them using the exact same source and build folders, which seems quite unnecessary.

Apparently (according to #4 ), there are already some thoughts for how to fix this?

My gut feeling is that since the preprocessed result is what's being hashed (together with the command line flags that affect how the compilation is performed), things like file names (input, output) and include paths should not be important at all, so you should be able to remove them from the hash completely, right? (this includes -I, -o, -MT, -MF, -include etc, plus the source file name)

@mbitsnbites
Copy link
Contributor Author

mbitsnbites commented Dec 6, 2017

Forget everything I've said about compiler flags and paths. I did some debugging of generate_hash_key(), and parsed_args.common_args seems to be very clean, containing only flags that affect the post-preprocessing compilation step.

Same thing for the environment flags, where only MACOSX_DEPLOYMENT_TARGET and IPHONEOS_DEPLOYMENT_TARGET affect the hash.

However, the preprocessor output contains lots of paths, at least for gcc. These are typically of the form:

# 1 "/home/alice/git/coolproject/modules/foo/src/cool_source.cpp"
# 1 "/home/alice/git/coolproject-build/Release//"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "/home/alice/git/coolproject/modules/foo/src/cool_source.cpp"
...

A relatively simple solution (that hopefully works) would be to strip the preprocessor output of all lines starting with # .

Edit: Or simply pass -P (Inhibit generation of linemarkers in the output from the preprocessor) to cpp, which seems to do the trick.

@mbitsnbites
Copy link
Contributor Author

mbitsnbites commented Dec 6, 2017

PR #208 addresses this issue for GCC (and hopefully Clang).

I'm not sure if the corresponding problem exists for MSVC.

@mqudsi
Copy link

mqudsi commented Feb 18, 2018

Does this issue affect other languages like rust?

@luser
Copy link
Contributor

luser commented Feb 20, 2018

Does this issue affect other languages like rust?

It does! #196 has some discussion. There's a PR with a potential fix for Rust, but it'll have the same problem as C compilations (paths in debug info will be wrong), and I'm not sure it'll work properly even with that fix, since it looks like the build directory winds up in one of the internal rlib hashes, which might make rustc unhappy.

@mqudsi
Copy link

mqudsi commented Feb 27, 2018

Thank you for that kind reply. I think cargo could structure things differently on its end to remove some unnecessary duplication and simultaneously make sccache's life easier; I had originally proposed some sort of fs-local cache on cargo's end in a github issue and that's when I was first informed about sccache and the difficult problems it was trying to solve :)

luser added a commit to luser/sccache that referenced this issue Dec 17, 2018
…lla#207

Some rustc arguments like --out-dir, -L, and --extern contain absolute paths
which make building the same crate (from crates.io) in different projects
unable to get cache hits despite being otherwise the same. This patch omits
those arguments from the hash calculation which makes sccache much more useful
for local development.

For additional safety we add the cwd to the hash key, since that winds up in
the rlib and otherwise this patch could result in some compiles returning invalid results from cache.
@luser luser closed this as completed in 1087c20 Dec 17, 2018
@daniel-sherwood
Copy link

Hi - I have just upgraded to a build including these fixes and it seems to work with two directories on the same machine, however I am still getting 100% cache misses when running on a different machine. Can you suggest how I go about debugging this to establish the cause of the cache misses?

drahnr pushed a commit to drahnr/sccache that referenced this issue Mar 24, 2019
…lla#207

Some rustc arguments like --out-dir, -L, and --extern contain absolute paths
which make building the same crate (from crates.io) in different projects
unable to get cache hits despite being otherwise the same. This patch omits
those arguments from the hash calculation which makes sccache much more useful
for local development.

For additional safety we add the cwd to the hash key, since that winds up in
the rlib and otherwise this patch could result in some compiles returning invalid results from cache.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants