Skip to content

Commit e33896a

Browse files
committed
update the build system code in the build on save guide
1 parent fd405fa commit e33896a

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

content/zls/guides/build-on-save.smd

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,39 @@ Here is an example:
3131

3232
## Add a "check" step to your build.zig
3333

34-
This part is more deeply tied to your specific project but the gist is the following: whatever you do to define your main executable / module / library, you do it again in a new step named check.
34+
This part is more deeply tied to your specific project but the gist is the following: whatever you do to define your main executable or library, you do it again in a new step named check.
3535

3636
I'll use for this example the executable definition step you get generated automatically from `zig init`.
3737

3838
```zig
39-
// This is an example executable definition, no need to copy it.
40-
const exe = b.addExecutable(.{
41-
.name = "foo",
39+
// Create a "module" just like in the `zig init` template.
40+
const module = b.addModule("foo", .{
4241
.root_source_file = b.path("src/main.zig"),
4342
.target = target,
4443
.optimize = optimize,
4544
});
46-
4745
// Any other code to define dependencies would probably be here.
4846

47+
// Create an example from the given module.
48+
// Still the same as the `zig init` template.
49+
const exe = b.addExecutable(.{
50+
.name = "foo",
51+
.root_module = module,
52+
});
4953
b.installArtifact(exe);
5054

51-
5255
// This is where the interesting part begins.
53-
// As you can see we are re-defining the same executable but
56+
// As you can see we are re-defining the same executable but
5457
// we're binding it to a dedicated build step.
5558
const exe_check = b.addExecutable(.{
5659
.name = "foo",
57-
.root_source_file = b.path("src/main.zig"),
58-
.target = target,
59-
.optimize = optimize,
60+
.root_module = module,
6061
});
62+
// There is no `b.installArtifact(exe_check);` here.
6163

62-
// Any other code to define dependencies would probably be here.
63-
64-
65-
// These two lines you might want to copy
66-
// (make sure to rename 'exe_check')
64+
// Finally we add the "check" step which will be detected
65+
// by ZLS and automatically enable Build-On-Save.
66+
// If you copy this into your `build.zig`, make sure to rename 'foo'
6767
const check = b.step("check", "Check if foo compiles");
6868
check.dependOn(&exe_check.step);
6969
```

0 commit comments

Comments
 (0)