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

zig build: add env_map entries to hash for Step.Run #20874

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dweiller
Copy link
Contributor

@dweiller dweiller commented Jul 30, 2024

This change fixes false-positive cache hits for run steps that get run with different sets of environment variables due the the environment map being excluded from the cache hash.

I assume the exclusion of the env_map field from the cache hash of a Step.Run was an oversight as it is important for use cases where environment variables are used to control program behaviour (I encountered this issue when using AFLPlusPlus where environment variables are used to enable different instrumentation options). If it was intentional I can open an issue to discuss changing this behaviour.

The implementation in this PR sorts the environment variables by the variable name to ensure that any reordering does not cause a cache miss. I have not implemented special-case logic for windows to normalise environment variable name case before hashing, so you can get cache misses if different codes paths in build.zig add the same environment variable (and value) but use different casing for the variable name.

lib/std/Build/Step/Run.zig Outdated Show resolved Hide resolved
@dweiller dweiller force-pushed the build-env-var branch 2 times, most recently from bac8640 to 44d1544 Compare August 2, 2024 00:55
Copy link
Member

@andrewrk andrewrk left a comment

Choose a reason for hiding this comment

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

still wrong... please use std.mem.sortUnstable

@dweiller
Copy link
Contributor Author

dweiller commented Aug 2, 2024

still wrong... please use std.mem.sortUnstable

Done.

This change fixes false-positive cache hits for run steps that get run
with different sets of environment variables due the the environment map
being excluded from the cache hash.
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.

2 participants