Skip to content

reduce garbage for repeated zig cc - calls #15772

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

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

motiejus
Copy link
Contributor

@motiejus motiejus commented May 19, 2023

Context: user provides - to read from stdin instead of a file.

Before: it would create a file in $ZIG_LOCAL_CACHE_DIR/tmp/ for each invocation and leave it there.

After: it hashes the file contents and renames the file to the hash.

Result: repeated invocations of zig cc do not cause so much trash to be created.

Context: user provides `-` to read from stdin instead of a file.

Before: it would create a file in $ZIG_LOCAL_CACHE_DIR/tmp/ for each
invocation and leave it there.
After: it hashes the file contents and renames the file to the hash.

Result: repeated invocations of `zig cc` do not cause so much trash to
be created.
@andrewrk andrewrk enabled auto-merge (rebase) March 14, 2024 03:06
@andrewrk
Copy link
Member

Sorry for the delay - I should have merged this a long time ago. I was sad to see the writeFileAll call go, but this is perfectly fine.

// for the hashing algorithm here and in the cache are the same.
// We are providing our own cache key, because this file has nothing
// to do with the cache manifest.
var hasher = Cache.Hasher.init("0123456789abcdef");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this not be random?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the purpose is for the file path to be a hash of the contents

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know, but the string passed here is a seed, right? So it ought to be a hardcoded string of random bytes, like what std.Build.Cache.hasher_init does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

random bytes, all zeroes, 123abc, it really doesn't matter. I think best would be using Cache.hasher_init.

@andrewrk andrewrk merged commit 400145e into ziglang:master Mar 14, 2024
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

Successfully merging this pull request may close these issues.

3 participants