Skip to content

Commit ae06567

Browse files
committed
clanup build.zig
1 parent 04ceee1 commit ae06567

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

build.zig

+10-32
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
11
const std = @import("std");
2-
const zlib = @import("zlib/zlib.zig");
3-
const Pkg = std.build.Pkg;
4-
5-
pub const pkgs = struct {
6-
pub const zlib = Pkg{
7-
.name = "zlib",
8-
.source = std.build.FileSource.relative("zlib/src/main.zig"),
9-
};
10-
11-
pub const websocket = Pkg{
12-
.name = "websocket",
13-
.source = .{ .path = "src/main.zig" },
14-
.dependencies = &[_]Pkg{
15-
pkgs.zlib,
16-
},
17-
};
18-
};
2+
const ws = @import("websocket.zig");
193

204
pub fn build(b: *std.build.Builder) void {
215
// Standard release options allow the person running `zig build` to select
226
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
237
const mode = b.standardReleaseOptions();
248
const target = b.standardTargetOptions(.{});
259

26-
const zlib_lib = zlib.create(b, target, mode);
27-
28-
const lib = b.addStaticLibrary("websocket", "src/main.zig");
29-
lib.setBuildMode(mode);
30-
b.installArtifact(lib);
10+
const lib = ws.create(b, target, mode);
11+
lib.step.install();
3112

3213
const main_tests = b.addTest("src/main.zig");
33-
zlib_lib.link(main_tests, .{ .import_name = "zlib" });
14+
lib.link(main_tests);
3415
main_tests.setBuildMode(mode);
3516

3617
const test_step = b.step("test", "Run library tests");
@@ -40,14 +21,11 @@ pub fn build(b: *std.build.Builder) void {
4021
inline for (.{
4122
"autobahn_client",
4223
}) |example_name| {
43-
const example = b.addExecutable(example_name, "examples/" ++ example_name ++ ".zig");
44-
45-
zlib_lib.link(example, .{ .import_name = "zlib" });
46-
example.addPackage(pkgs.websocket);
47-
48-
example.setBuildMode(mode);
49-
example.setTarget(target);
50-
example.install();
51-
example_step.dependOn(&example.step);
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);
5230
}
5331
}

websocket.zig

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const std = @import("std");
2+
const zlib = @import("zlib/zlib.zig");
3+
const Pkg = std.build.Pkg;
4+
5+
fn root() []const u8 {
6+
return std.fs.path.dirname(@src().file) orelse ".";
7+
}
8+
9+
const root_path = root() ++ "/";
10+
const package_path = root_path ++ "src/main.zig";
11+
12+
pub const Library = struct {
13+
step: *std.build.LibExeObjStep,
14+
zlib: zlib.Library,
15+
16+
pub fn link(self: Library, other: *std.build.LibExeObjStep) void {
17+
other.linkLibrary(self.step);
18+
self.zlib.link(other, .{ .import_name = "zlib" });
19+
other.addPackage(Pkg{
20+
.name = "websocket",
21+
.source = .{ .path = root_path ++ "src/main.zig" },
22+
.dependencies = &[_]Pkg{
23+
Pkg{
24+
.name = "zlib",
25+
.source = .{ .path = root_path ++ "zlib/src/main.zig" },
26+
},
27+
},
28+
});
29+
}
30+
};
31+
32+
pub fn create(b: *std.build.Builder, target: std.zig.CrossTarget, mode: std.builtin.Mode) Library {
33+
var ret = b.addStaticLibrary("websocket", package_path);
34+
ret.setTarget(target);
35+
ret.setBuildMode(mode);
36+
const zl = zlib.create(b, target, mode);
37+
zl.link(ret, .{ .import_name = "zlib" });
38+
return Library{ .step = ret, .zlib = zl };
39+
}

zlib/src/main.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ pub fn Decompressor(comptime ReaderType: type) type {
279279
}
280280

281281
pub fn read(self: *Self, buf: []u8) ReaderError!usize {
282-
std.debug.print("pos: {d} buf.len {d}\n", .{ self.pos, buf.len });
282+
//std.debug.print("pos: {d} buf.len {d}\n", .{ self.pos, buf.len });
283283
self.pos += try self.inner.readAll(self.tmp[self.pos..]);
284284

285285
self.stream.next_in = &self.tmp;

0 commit comments

Comments
 (0)