Skip to content

Instantly share code, notes, and snippets.

@nothke
Last active August 9, 2024 14:41
Show Gist options
  • Save nothke/a371f68ea3ac6a0335341ee042973556 to your computer and use it in GitHub Desktop.
Save nothke/a371f68ea3ac6a0335341ee042973556 to your computer and use it in GitHub Desktop.
Zig check step - how to enable live compile errors

Make sure ZLS is installed.

In build.zig, add a check step after exe:

const exe_check = b.addExecutable(.{
    .name = "YOUR_PROJECT",
    .root_source_file = b.path("src/main.zig"),
    .target = target,
    .optimize = optimize,
});

// Add all deps here just like your exe

const check = b.step("check", "Check if it compiles");
check.dependOn(&exe_check.step);

Your ZLS settings must now be:

{
  "enable_build_on_save": true,
  "build_on_save_step": "check"
}

In VSCode, I suggest you also install Error Lens extension to see errors in-line.

Now you should have live error checks!

For full description, read the full article by Loris Cro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment