build-your-own-redis icon indicating copy to clipboard operation
build-your-own-redis copied to clipboard

Add zig support

Open ippsav opened this issue 1 year ago • 14 comments

ippsav avatar Apr 27 '24 23:04 ippsav

For some reason the zig test just hangs with no error thrown whatsoever, so for now i ve made it fail on purpose to not run for a long time

ippsav avatar Apr 28 '24 00:04 ippsav

Ah, looks like this adds support for the package manager (Zon)? We'll need to look into better caching here - else we'd end up downloading deps on every push.

We've got docs for this here (might not be extremely friendly): https://docs.codecrafters.io/contributors/adding-language-support/test-runner-image-interface#performance. @ippsav do you want to take a look at this and see if we can get build.zig and build.zig.zon used via the CODECRAFTERS_DEPENDENCY_FILE_PATHS mechanism?

No worries if you're short on time, someone from our team should be able to take a look at this within ~2 weeks (we're currently focused on improving the HTTP & Redis challenge logs to be more user-friendly)

rohitpaulk avatar Apr 29 '24 23:04 rohitpaulk

@rohitpaulk will take a look at it and give it a try ! i am basically free these 2 weeks off holidays so i ve got time to spare 😂

ippsav avatar Apr 29 '24 23:04 ippsav

@rohitpaulk is there a link that points to how does CODECRAFTERS_DEPENDENCY_FILE_PATHS works behind the scenes ? from the look of it, it should work fine from the get go

ippsav avatar Apr 30 '24 00:04 ippsav

@ippsav awesome!

Just dropping some links here in case they're helpful:

rohitpaulk avatar Apr 30 '24 00:04 rohitpaulk

@rohitpaulk i think what should be done is add something like "Do not edit this file" to build.zig as the user don t need to edit it (at least for doing challenges and any changes to it can make the docker image not work properly), and add build.zig.zon to CODECRAFTERS_DEPENDENCY_FILE_PATHS as it's the one related to dependencies

ippsav avatar Apr 30 '24 00:04 ippsav

@rohitpaulk is there a link that points to how does CODECRAFTERS_DEPENDENCY_FILE_PATHS works behind the scenes ? from the look of it, it should work fine from the get go

Sorry, didn't see this before I posted the previous comment. The behaviour of the env var is that whenever any files listed there change, the docker container is re-built using the Dockerfile.

The test runner will look for a CODECRAFTERS_DEPENDENCY_FILE_PATHS environment variable in the image. It will only re-build the image if the files listed in the variable change.

We only use this "re-build container" flow for cases like dependencies, which (a) don't change often and (b) need to be downloaded, so it's usually slow and (c) can easily be identified by checking hashes of files to see if they've changed.

rohitpaulk avatar Apr 30 '24 00:04 rohitpaulk

@rohitpaulk i think what should be done is add something like "Do not edit this file" to build.zig as the user don t need to edit it (at least for doing challenges and any changes to it can make the docker image not work properly), and add build.zig.zon to CODECRAFTERS_DEPENDENCY_FILE_PATHS as it's the one related to dependencies

Yep, I think that'd work! Quick question - if someone wanted to add another .zig file inside src, how would that work? Would they need to edit build.zig then? Would https://docs.codecrafters.io/challenges/language-support/zig#adding-more-files still work as-is?

rohitpaulk avatar Apr 30 '24 00:04 rohitpaulk

@rohitpaulk, no they do not need to edit the build.zig, basically you can just edit how do you want your project to be built, and in some cases if you re adding some libraries you might want to edit it from what i ve seen is people who includes C libraries tend to edit the file (never had to), and you can more commands ex: zig build run:

    // This *creates* a Run step in the build graph, to be executed when another
    // step is evaluated that depends on it. The next line below will establish
    // such a dependency.
    const run_cmd = b.addRunArtifact(exe);

    run_cmd.step.dependOn(b.getInstallStep());

    // command itself, like this: `zig build run -- arg1 arg2 etc`
    if (b.args) |args| {
        run_cmd.addArgs(args);
    }

    const run_step = b.step("run", "Run the app");
    run_step.dependOn(&run_cmd.step);

ippsav avatar Apr 30 '24 00:04 ippsav

@rohitpaulk adding dependencies requires adding changes to build.zig, but i don't think it would be a problem

ippsav avatar Apr 30 '24 00:04 ippsav

@rohitpaulk adding dependencies requires adding changes to build.zig, but i don't think it would be a problem

Cool, sounds good!

rohitpaulk avatar Apr 30 '24 00:04 rohitpaulk

Thanks so much for your help here, we've been dreading having to figure this out ourselves 🙂

rohitpaulk avatar Apr 30 '24 00:04 rohitpaulk

Thanks so much for your help here, we've been dreading having to figure this out ourselves 🙂

@rohitpaulk Glad i ve managed to help !

ippsav avatar Apr 30 '24 00:04 ippsav

@rohitpaulk let me know if there is anything else, the caching should be working now

ippsav avatar May 01 '24 21:05 ippsav