atproto relay in zig zlay.waow.tech
relay zig atproto
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{});
const zat = b.dependency("zat", .{ .target = target, .optimize = optimize, }); const websocket = b.dependency("websocket", .{ .target = target, .optimize = optimize, }); const pg = b.dependency("pg", .{ .target = target, .optimize = optimize, }); const rocksdb = b.dependency("rocksdb", .{ .target = target, .optimize = optimize, }); const zio = b.dependency("zio", .{ .target = target, .optimize = optimize, });
// -Dbackend=zio swaps the std.Io implementation under the whole relay. // Both variants must compile from the same source; see docs/design.md. const backend = b.option(enum { threaded, zio }, "backend", "std.Io backend (default: threaded)") orelse .threaded; const backend_opts = b.addOptions(); backend_opts.addOption(bool, "use_zio", backend == .zio);
const imports: []const std.Build.Module.Import = &.{ .{ .name = "zat", .module = zat.module("zat") }, .{ .name = "websocket", .module = websocket.module("websocket") }, .{ .name = "pg", .module = pg.module("pg") }, .{ .name = "rocksdb", .module = rocksdb.module("bindings") }, .{ .name = "zio", .module = zio.module("zio") }, .{ .name = "backend_config", .module = backend_opts.createModule() }, };
// embed build info (git SHA + optimize mode) for canary metric const build_options = b.addOptions(); build_options.addOption([]const u8, "git_sha", git_sha: { var code: u8 = 0; const result = b.runAllowFail(&.{ "git", "rev-parse", "--short", "HEAD" }, &code, .ignore); if (result) |output| { break :git_sha std.mem.trimEnd(u8, output, "\n \t"); } else |_| { break :git_sha "unknown"; } }); build_options.addOption([]const u8, "optimize", @tagName(optimize)); const use_gpa = b.option(bool, "use_gpa", "use GeneralPurposeAllocator for leak detection (slow)") orelse false; build_options.addOption(bool, "use_gpa", use_gpa);
// relay executable const relay_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = imports, }); relay_mod.addImport("build_options", build_options.createModule()); relay_mod.link_libc = true; relay_mod.link_libcpp = true; const relay = b.addExecutable(.{ .name = "zlay", .root_module = relay_mod, }); b.installArtifact(relay);
const run_relay = b.addRunArtifact(relay); run_relay.addPassthruArgs(); const run_step = b.step("run", "run the relay"); run_step.dependOn(&run_relay.step);
// conformance harness — runs the atmoq relay-conformance corpora through // the real decode + validation path (see src/conformance_main.zig) const conformance_mod = b.createModule(.{ .root_source_file = b.path("src/conformance_main.zig"), .target = target, .optimize = optimize, .imports = imports, }); conformance_mod.addImport("build_options", build_options.createModule()); conformance_mod.link_libc = true; conformance_mod.link_libcpp = true; const conformance = b.addExecutable(.{ .name = "conformance", .root_module = conformance_mod, }); b.installArtifact(conformance);
const run_conformance = b.addRunArtifact(conformance); run_conformance.addPassthruArgs(); const conformance_step = b.step("conformance", "run the relay conformance harness"); conformance_step.dependOn(&run_conformance.step);
// tests // tests — a single module rooted at src/ so every internal/ import resolves const test_step = b.step("test", "run unit tests"); const test_mod = b.createModule(.{ .root_source_file = b.path("src/tests.zig"), .target = target, .optimize = optimize, .imports = imports, }); test_mod.addImport("build_options", build_options.createModule()); test_mod.link_libc = true; test_mod.link_libcpp = true; const t = b.addTest(.{ .root_module = test_mod, }); test_step.dependOn(&b.addRunArtifact(t).step);}