Changes
6 changed files (+115/-47)
-
-
@@ -21,7 +21,7 @@ const target = b.standardTargetOptions(.{});const optimize = b.standardOptimizeOption(.{}); // Exports Zig API. A project depending on this package imports this module. const module = b.addModule("moo", .{ .root_source_file = b.path("src/lib.zig") }); _ = b.addModule("moo", .{ .root_source_file = b.path("src/lib.zig") }); // Tests const test_step = b.step("test", "Run unit tests");
-
@@ -56,36 +56,5 @@ });const step = b.step("docs", "Install API docs into $prefix/$docs-dir"); step.dependOn(&install_docs.step); } // Zig example // This is not a command due to steps can't trigger lazy dependencies' fetching. // <https://github.com/ziglang/zig/issues/21525> const example = b.option(bool, "example-zig", "Build Zig example program") orelse false; if (example) { const example_zig = b.addExecutable(.{ .name = "example-zig", .root_source_file = b.path("examples/basic.zig"), .target = target, .optimize = optimize, }); example_zig.root_module.addImport("moo", module); if (b.lazyDependency("websocket", .{ .target = target, .optimize = optimize, })) |websocket| { example_zig.root_module.addImport("websocket", websocket.module("websocket")); } if (b.lazyDependency("clap", .{ .target = target, .optimize = optimize, })) |clap| { example_zig.root_module.addImport("clap", clap.module("clap")); } b.installArtifact(example_zig); } }
-
-
-
@@ -13,20 +13,7 @@ .name = .libmoo,.version = "0.0.0", .fingerprint = 0xb49e17e4d2b05a1d, .minimum_zig_version = "0.14.0", .dependencies = .{ // For example program. .websocket = .{ .url = "https://github.com/karlseguin/websocket.zig/archive/c1c53b062eab871b95b70409daadfd6ac3d6df61.zip", .hash = "websocket-0.1.0-ZPISdYBIAwB1yO6AFDHRHLaZSmpdh4Bz4dCmaQUqNNWh", .lazy = true, }, // For example program. .clap = .{ .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.10.0.tar.gz", .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0", .lazy = true, }, }, .dependencies = .{}, .paths = .{ "build.zig", "build.zig.zon",
-
-
-
@@ -120,7 +120,7 @@fn handleResponse(allocator: std.mem.Allocator, message: []const u8) !void { const meta, const meta_ctx = try moo.Metadata.parse(message); const header, const header_ctx = try moo.WellKnownHeaders.parse(message, meta_ctx); const body = try moo.JsonBody(InfoResponse).parse(allocator, message, header_ctx); const body = try moo.JsonBody(InfoResponse).parse(allocator, message, header_ctx, .{}); defer body.deinit(); std.debug.print(
-
-
examples/zig/README.md (new)
-
@@ -0,0 +1,22 @@<!-- Copyright 2025 Shota FUJI Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. You may not use, copy, modify, or distribute this file except according to those terms. You can find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Zero-Clause BSD License at <https://opensource.org/license/0bsd> and a copy of the Apache License, Version 2.0 at <https://www.apache.org/licenses/LICENSE-2.0> SPDX-License-Identifier: 0BSD OR Apache-2.0 --> # Zig example This example program connects to a Roon server, displays the server information, then exits. ```sh zig build run -- --host $ip_address_of_roon_server --port $tcp_port_to_use ``` TCP port would be normally 9330, up to 9339 if other program using the port.
-
-
examples/zig/build.zig (new)
-
@@ -0,0 +1,56 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Zero-Clause BSD License // at <https://opensource.org/license/0bsd> and a copy of the Apache License, Version 2.0 at // <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 const std = @import("std"); pub fn build(b: *std.Build) !void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const moo = b.dependency("moo", .{ .target = target, .optimize = optimize, }).module("moo"); const websocket = b.dependency("websocket", .{ .target = target, .optimize = optimize, }).module("websocket"); const clap = b.dependency("clap", .{ .target = target, .optimize = optimize, }).module("clap"); const exe = b.addExecutable(.{ .name = "example-zig", .root_source_file = b.path("main.zig"), .target = target, .optimize = optimize, }); exe.root_module.addImport("moo", moo); exe.root_module.addImport("websocket", websocket); exe.root_module.addImport("clap", clap); b.installArtifact(exe); // "zig build run" { const run = b.addRunArtifact(exe); if (b.args) |args| { run.addArgs(args); } const step = b.step("run", "Run example application"); step.dependOn(&run.step); } }
-
-
-
@@ -0,0 +1,34 @@// Copyright 2025 Shota FUJI // // Licensed under the Zero-Clause BSD License or the Apache License, Version 2.0, at your option. // You may not use, copy, modify, or distribute this file except according to those terms. You can // find a copy of the Zero-Clause BSD License at LICENSES/0BSD.txt, and a copy of the Apache License, // Version 2.0 at LICENSES/Apache-2.0.txt. You may also obtain a copy of the Zero-Clause BSD License // at <https://opensource.org/license/0bsd> and a copy of the Apache License, Version 2.0 at // <https://www.apache.org/licenses/LICENSE-2.0> // // SPDX-License-Identifier: 0BSD OR Apache-2.0 .{ .name = .libmoo_examples, .version = "0.0.0", .fingerprint = 0x7a185cf209cde68d, .minimum_zig_version = "0.14.0", .dependencies = .{ .moo = .{ .path = "../../", }, .websocket = .{ .url = "https://github.com/karlseguin/websocket.zig/archive/c1c53b062eab871b95b70409daadfd6ac3d6df61.zip", .hash = "websocket-0.1.0-ZPISdYBIAwB1yO6AFDHRHLaZSmpdh4Bz4dCmaQUqNNWh", }, .clap = .{ .url = "https://github.com/Hejsil/zig-clap/archive/refs/tags/0.10.0.tar.gz", .hash = "clap-0.10.0-oBajB434AQBDh-Ei3YtoKIRxZacVPF1iSwp3IX_ZB8f0", }, }, .paths = .{ "build.zig", "build.zig.zon", "main.zig", }, }
-