### Building All Zig Examples Source: https://github.com/tardy-org/tardy/blob/main/README.md Provides the command to build all examples defined in the `build.zig` file using the Zig build system. The `-Dexample=all` flag instructs the build system to compile all available examples. ```Shell zig build -Dexample=all ``` -------------------------------- ### Building and Running a Specific Zig Example Source: https://github.com/tardy-org/tardy/blob/main/README.md Shows the commands to build a single example or build and immediately execute it using the Zig build system. The `-Dexample=[nameOfExample]` flag specifies which example to target. ```Shell zig build -Dexample=[nameOfExample] ``` ```Shell zig build run -Dexample=[nameOfExample] ``` -------------------------------- ### Listing Available Zig Build Options Source: https://github.com/tardy-org/tardy/blob/main/README.md Provides the command to display the help message for the Zig build system, which includes information on available build options and targets, such as listing the examples defined in the `build.zig`. ```Shell zig build --help ``` -------------------------------- ### Installing tardy Dependency with Zig Fetch Source: https://github.com/tardy-org/tardy/blob/main/README.md Demonstrates how to fetch and save the tardy dependency at a specific version using the `zig fetch` command. This command adds the dependency to the project's `build.zig.zon` file. ```Shell zig fetch --save git+https://github.com/tardy-org/tardy#v0.3.0 ``` -------------------------------- ### Cloning Tardy Repository - Bash Source: https://github.com/tardy-org/tardy/blob/main/README.md Clones the tardy Git repository from GitHub and changes the current directory to the newly cloned project directory. This is the initial step to get the project source code. ```bash git clone https://github.com/tardy-org/tardy.git cd tardy ``` -------------------------------- ### Implementing a Basic tardy TCP Echo Server Source: https://github.com/tardy-org/tardy/blob/main/README.md Presents the core code for a TCP echo server using the tardy runtime. It demonstrates initializing the runtime, creating and binding a TCP socket, accepting connections, and spawning tasks (`echo_frame`) to handle client communication asynchronously. It shows how to use tardy's `Socket`, `Runtime`, and `Task` types. ```Zig const std = @import("std"); const log = std.log.scoped(.@"tardy/example/echo"); const Pool = @import("tardy").Pool; const Runtime = @import("tardy").Runtime; const Task = @import("tardy").Task; const Tardy = @import("tardy").Tardy(.auto); const Cross = @import("tardy").Cross; const Socket = @import("tardy").Socket; const Timer = @import("tardy").Timer; const AcceptResult = @import("tardy").AcceptResult; const RecvResult = @import("tardy").RecvResult; const SendResult = @import("tardy").SendResult; fn echo_frame(rt: *Runtime, server: *const Socket) !void { const socket = try server.accept(rt); defer socket.close_blocking(); // you can use the standard Zig Reader/Writer if you want! const reader = socket.reader(rt); const writer = socket.writer(rt); log.debug( "{d} - accepted socket [{}]", .{ std.time.milliTimestamp(), socket.addr }, ); try rt.spawn(.{ rt, server }, echo_frame, 1024 * 16); var buffer: [1024]u8 = undefined; while (true) { const recv_length = reader.read(&buffer) catch |e| { log.err("Failed to recv on socket | {}", .{e}); return; }; writer.writeAll(buffer[0..recv_length]) catch |e| { log.err("Failed to send on socket | {}", .{e}); return; }; log.debug("Echoed: {s}", .{buffer[0..recv_length]}); } } pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); defer _ = gpa.deinit(); // tardy by default is // - multithreaded // - unbounded in terms of spawnable tasks var tardy = try Tardy.init(allocator, .{}); defer tardy.deinit(); const server = try Socket.init(.{ .tcp = .{ .host = "127.0.0.1", .port = 9862 } }); try server.bind(); try server.listen(256); try tardy.entry( &server, struct { fn start(rt: *Runtime, tcp_server: *const Socket) !void { try rt.spawn(.{ rt, tcp_server }, echo_frame, 1024 * 1024 * 4); } }.start, ); } ``` -------------------------------- ### Entering Nix Development Shell - Bash Source: https://github.com/tardy-org/tardy/blob/main/README.md Uses the Nix package manager to enter a development shell environment defined by the project's flake.nix file. This shell contains all necessary tools and dependencies for development. ```bash nix develop ``` -------------------------------- ### Adding tardy Dependency to Zig Build File Source: https://github.com/tardy-org/tardy/blob/main/README.md Shows how to reference the fetched tardy dependency within a `build.zig` file and add it as an import to a Zig executable module. This makes the tardy library available for use in the project's source code. ```Zig const tardy = b.dependency("tardy", .{ .target = target, .optimize = optimize, }).module("tardy"); exe_mod.addImport("tardy", tardy); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.