You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/zls/guides/build-on-save.smd
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -31,39 +31,39 @@ Here is an example:
31
31
32
32
## Add a "check" step to your build.zig
33
33
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.
35
35
36
36
I'll use for this example the executable definition step you get generated automatically from `zig init`.
37
37
38
38
```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", .{
42
41
.root_source_file = b.path("src/main.zig"),
43
42
.target = target,
44
43
.optimize = optimize,
45
44
});
46
-
47
45
// Any other code to define dependencies would probably be here.
48
46
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
+
});
49
53
b.installArtifact(exe);
50
54
51
-
52
55
// 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
54
57
// we're binding it to a dedicated build step.
55
58
const exe_check = b.addExecutable(.{
56
59
.name = "foo",
57
-
.root_source_file = b.path("src/main.zig"),
58
-
.target = target,
59
-
.optimize = optimize,
60
+
.root_module = module,
60
61
});
62
+
// There is no `b.installArtifact(exe_check);` here.
61
63
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'
67
67
const check = b.step("check", "Check if foo compiles");
0 commit comments