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

Cache #7631

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Cache #7631

wants to merge 1 commit into from

Conversation

jfkonecn
Copy link
Contributor

closes #7517

Still as work in progress

Copy link
Collaborator

@smores56 smores56 left a comment

Choose a reason for hiding this comment

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

Good start, excited to see caching of build artifacts for the first time since Roc was created!

src/cache.zig Outdated

pub const RocCacheFile = union(RocCacheFileTag) {
compiler: CompilerCacheFile,
build: void,
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • if you want to make a tagged union and don't need the enum by itself, you can just write union(enum) and it'll create the enum for you
  • if a tagged union variant doesn't have a payload, you don't need to put void, you can just do build, instead of build: void,

src/cache.zig Outdated
return default_cache_folder;
},
else => {
// SKILL_ISSUE: I want to include the os name in the error message, but
Copy link
Collaborator

Choose a reason for hiding this comment

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

You're looking for comptimePrint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I got the ++ operator to work. I can't remember what I was doing wrong...

src/cache.zig Outdated
return try getBaseRocCacheFolder(allocator, xdg_cache_home, sub_path);
}

fn getXdgCacheHome(allocator: Allocator) ?[]u8 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

On Unix, this should be used first when looking for the cache root, then $HOME/.cache/roc after that

Copy link
Contributor Author

@jfkonecn jfkonecn Mar 3, 2025

Choose a reason for hiding this comment

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

I made this a separate function because I didn't want the tests to break because someone set XDG_CACHE_HOME. I wanted to mock it out, but it's probably making the code too confusing so I'll refactor.

I'm sure we can figure out something better to solve the problem.

src/cache.zig Outdated
const roc_cache_folder = std.fs.path.dirname(file_cache_path);
if (roc_cache_folder) |x| {
cwd.makePath(x) catch {
return SaveCacheFileError.FailedToMakeCacheFolder;
Copy link
Collaborator

Choose a reason for hiding this comment

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

very minor nitpick: I think generally Zig uses error.NameOfError when creating an error variant from a custom error union.

Copy link
Contributor Author

@jfkonecn jfkonecn Mar 3, 2025

Choose a reason for hiding this comment

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

I added it so that I can pass a callback function for saving to the file system in saveToCacheInternal. I wanted to add the callback so that I can mock it out during testing.

src/cache.zig Outdated
packages_build,
};

pub const RocCacheFile = union(RocCacheFileTag) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two naming things:

An example of how I might nest it would be:

pub const CacheFile = union(enum) {
    compiler: Compiler,
    build,
    packages_src,
    packages_build,

    pub const Compiler = struct {
        version_name: []const u8,
        binary: []const u8,
    };
};

@bhansconnect
Copy link
Member

@jfkonecn can you interactive rebase to either squash the commits or at least give them minorly meaningful names? A bunch of commits just with the name a aren't meaningful and nice to merge.

@jfkonecn
Copy link
Contributor Author

Yeah, I was going to do that when I'm ready for an official review, but if you prefer I do that now I can do that as well.

@bhansconnect
Copy link
Member

but if you prefer I do that now I can do that as well

Doesn't matter when. Just was noting in general.

@jfkonecn
Copy link
Contributor Author

jfkonecn commented Mar 3, 2025

@smores56 this is a nitpick, but for getPackageRootAbsDir the allocator comes last in the arguments. It seems like the zig standard library generally has the allocator come first. I was thinking about sticking to that convention for this PR.

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.

Set up global caching of Roc assets
3 participants