Skip to content

Commit d236733

Browse files
committed
make build pass on zig master
1 parent 497c80c commit d236733

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

build.zig

+47-26
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,52 @@
11
const std = @import("std");
2-
const ws = @import("websocket.zig");
2+
const zlib_build = @import("zlib/zlib.zig");
33

4-
pub fn build(b: *std.build.Builder) void {
5-
// Standard release options allow the person running `zig build` to select
6-
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
7-
const mode = b.standardReleaseOptions();
4+
pub fn build(b: *std.Build) void {
85
const target = b.standardTargetOptions(.{});
6+
const optimize = b.standardOptimizeOption(.{});
97

10-
const lib = ws.create(b, target, mode);
11-
lib.step.install();
12-
13-
const main_tests = b.addTest("src/main.zig");
14-
lib.link(main_tests);
15-
main_tests.setBuildMode(mode);
16-
17-
const test_step = b.step("test", "Run library tests");
18-
test_step.dependOn(&main_tests.step);
19-
20-
const example_step = b.step("examples", "Build examples");
21-
inline for (.{
22-
"autobahn_client",
23-
}) |example_name| {
24-
const exe = b.addExecutable(example_name, "examples/" ++ example_name ++ ".zig");
25-
lib.link(exe);
26-
exe.setBuildMode(mode);
27-
exe.setTarget(target);
28-
exe.install();
29-
example_step.dependOn(&exe.step);
30-
}
8+
const zlib = zlib_build.create(b, target, optimize);
9+
//b.installArtifact(zlib.step);
10+
11+
const zlib_module = b.addModule("zlib", .{
12+
.source_file = .{ .path = "zlib/src/main.zig" },
13+
});
14+
const ws_module = b.addModule("ws", .{
15+
.source_file = .{ .path = "src/main.zig" },
16+
.dependencies = &[_]std.Build.ModuleDependency{.{ .name = "zlib", .module = zlib_module }},
17+
});
18+
19+
const ws_lib = b.addStaticLibrary(.{
20+
.name = "ws",
21+
.root_source_file = .{ .path = "src/main.zig" },
22+
.target = target,
23+
.optimize = optimize,
24+
});
25+
zlib.link(ws_lib, .{ .import_name = "zlib" });
26+
b.installArtifact(ws_lib);
27+
28+
// zig build test
29+
const test_compile = b.addTest(.{
30+
.root_source_file = .{ .path = "src/main.zig" },
31+
.target = target,
32+
.optimize = optimize,
33+
});
34+
zlib.link(test_compile, .{ .import_name = "zlib" });
35+
36+
const test_step = b.step("test", "Run unit tests");
37+
test_step.dependOn(&test_compile.step);
38+
39+
// build examples
40+
const bin = b.addExecutable(.{
41+
.name = "autobahn_client",
42+
.root_source_file = .{ .path = "examples/autobahn_client.zig" },
43+
.target = target,
44+
.optimize = optimize,
45+
});
46+
bin.linkLibrary(ws_lib);
47+
bin.addModule("ws", ws_module);
48+
b.installArtifact(bin);
3149
}
50+
51+
// to test single file
52+
// $ zig test src/main.zig --deps zlib=zlib --mod zlib::zlib/src/main.zig -l z

0 commit comments

Comments
 (0)