Skip to content

Commit cc547bb

Browse files
committed
Upgrade example/exe
1 parent c1b14c1 commit cc547bb

3 files changed

Lines changed: 13 additions & 54 deletions

File tree

examples/exe/build.zig

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,33 @@
11
const std = @import("std");
22

3-
// Although this function looks imperative, note that its job is to
4-
// declaratively construct a build graph that will be executed by an external
5-
// runner.
63
pub fn build(b: *std.Build) void {
7-
// Standard target options allows the person running `zig build` to choose
8-
// what target to build for. Here we do not override the defaults, which
9-
// means any target is allowed, and the default is native. Other options
10-
// for restricting supported target set are available.
114
const target = b.standardTargetOptions(.{});
12-
13-
// Standard optimization options allow the person running `zig build` to select
14-
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15-
// set a preferred release mode, allowing the user to decide how to optimize.
165
const optimize = b.standardOptimizeOption(.{});
176

7+
const dep_opts = .{ .target = target, .optimize = optimize };
8+
const ws_module = b.dependency("ws", dep_opts).module("ws");
9+
1810
const exe = b.addExecutable(.{
1911
.name = "exe",
20-
// In this case the main source file is merely a path, however, in more
21-
// complicated build scripts, this could be a generated file.
22-
.root_source_file = .{ .path = "src/main.zig" },
12+
.root_source_file = b.path("src/main.zig"),
2313
.target = target,
2414
.optimize = optimize,
2515
});
16+
exe.root_module.addImport("ws", ws_module);
2617

27-
const ws = b.dependency("ws", .{});
28-
exe.linkLibrary(ws.artifact("ws"));
29-
exe.addModule("ws", ws.module("ws"));
30-
31-
// This declares intent for the executable to be installed into the
32-
// standard location when the user invokes the "install" step (the default
33-
// step when running `zig build`).
3418
b.installArtifact(exe);
3519

36-
// This *creates* a Run step in the build graph, to be executed when another
37-
// step is evaluated that depends on it. The next line below will establish
38-
// such a dependency.
3920
const run_cmd = b.addRunArtifact(exe);
40-
41-
// By making the run step depend on the install step, it will be run from the
42-
// installation directory rather than directly from within the cache directory.
43-
// This is not necessary, however, if the application depends on other installed
44-
// files, this ensures they will be present and in the expected location.
4521
run_cmd.step.dependOn(b.getInstallStep());
46-
47-
// This allows the user to pass arguments to the application in the build
48-
// command itself, like this: `zig build run -- arg1 arg2 etc`
49-
if (b.args) |args| {
50-
run_cmd.addArgs(args);
51-
}
52-
53-
// This creates a build step. It will be visible in the `zig build --help` menu,
54-
// and can be selected like this: `zig build run`
55-
// This will evaluate the `run` step rather than the default, which is "install".
5622
const run_step = b.step("run", "Run the app");
5723
run_step.dependOn(&run_cmd.step);
5824

59-
// Creates a step for unit testing. This only builds the test executable
60-
// but does not run it.
61-
const unit_tests = b.addTest(.{
62-
.root_source_file = .{ .path = "src/main.zig" },
25+
const exe_unit_tests = b.addTest(.{
26+
.root_source_file = b.path("src/main.zig"),
6327
.target = target,
6428
.optimize = optimize,
6529
});
66-
67-
const run_unit_tests = b.addRunArtifact(unit_tests);
68-
69-
// Similar to creating the run step earlier, this exposes a `test` step to
70-
// the `zig build --help` menu, providing a way for the user to request
71-
// running the unit tests.
30+
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
7231
const test_step = b.step("test", "Run unit tests");
73-
test_step.dependOn(&run_unit_tests.step);
32+
test_step.dependOn(&run_exe_unit_tests.step);
7433
}

examples/exe/build.zig.zon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
.version = "0.0.0",
44
.dependencies = .{
55
.ws = .{
6-
.url = "https://github.com/ianic/websocket.zig/archive/d7026fc0673719a8db23959c695d7597feed4666.tar.gz",
7-
.hash = "1220fc95ece0dc10888747b99b1202a9184fbf40393a0a90ea2f369a8a5940b3d2b0",
6+
.url = "https://github.com/ianic/websocket.zig/archive/c1b14c166befd7ede8f60d9ee7f30a2f2b60fc49.tar.gz",
7+
.hash = "1220666cad728c586c0c3da673abe5c6755e9db389872645da678327863dc16fb40a",
88
},
99
},
1010
.paths = .{""},

examples/wss/build.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ pub fn build(b: *std.Build) void {
99
const ws_module = b.dependency("ws", dep_opts).module("ws");
1010

1111
const exe = b.addExecutable(.{
12-
.name = "demo",
12+
.name = "wss",
1313
.root_source_file = b.path("src/main.zig"),
1414
.target = target,
1515
.optimize = optimize,
1616
});
1717
exe.root_module.addImport("tls", tls_module);
1818
exe.root_module.addImport("ws", ws_module);
19-
2019
b.installArtifact(exe);
20+
2121
const run_cmd = b.addRunArtifact(exe);
2222
run_cmd.step.dependOn(b.getInstallStep());
2323
const run_step = b.step("run", "Run the app");

0 commit comments

Comments
 (0)