Something went wrong. Try again.
Sender Policy Framework (RFC 7208) for Zig: the record grammar, the macro language, and an evaluator that takes its resolver from you.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130// SPDX-FileCopyrightText: 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
const std = @import("std");
pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const docs_port = b.option(u16, "docs-port", "Port for `zig build docs-serve` (default 8000)") orelse 8000;
// Addresses, networks and the comparison between them come from z46 // rather than from `std` or from a parser written here: its parsing // is as strict as §5.6's ABNF asks for, and `Network.contains` is // the whole of what an `ip4:` or `ip6:` mechanism does. const z46 = b.dependency("z46", .{ .target = target, .optimize = optimize });
// The asking half of `StubResolver`: sockets, `/etc/resolv.conf`, // unguessable identifiers, EDNS0 and the move to TCP when an answer // did not fit. It carries the same z46 this does, which is what lets // an address out of a reply be an address here without conversion. const dns_client = b.dependency("zig_dns_client", .{ .target = target, .optimize = optimize });
const mod = b.addModule("spf", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "z46", .module = z46.module("z46") }, .{ .name = "dns_client", .module = dns_client.module("dns_client") }, }, });
// The openspf.org conformance suite: 203 cases written as zone data // and expected results, which is exactly the shape `Zone` reads. It // is a lazy dependency fetched only on demand, and nothing from it is // copied into this repository. // // zig build test -Dconformance const conformance = b.option( bool, "conformance", "Fetch the openspf.org test suite and run it", ) orelse false; var conformance_available = false; if (conformance) { if (b.lazyDependency("spf_tests", .{})) |dep| { mod.addAnonymousImport("rfc7208_tests_yml", .{ .root_source_file = dep.path("test/rfc7208-tests.yml"), }); conformance_available = true; } } const test_options = b.addOptions(); test_options.addOption(bool, "conformance", conformance_available); mod.addOptions("build_options", test_options);
// A tool that runs a check against the live DNS, which is the one // thing a table-driven test cannot do. const exe = b.addExecutable(.{ .name = "spf", .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "spf", .module = mod }, .{ .name = "z46", .module = z46.module("z46") }, }, }), }); b.installArtifact(exe);
const run = b.addRunArtifact(exe); run.step.dependOn(b.getInstallStep()); run.addPassthruArgs(); b.step("run", "Run the spf tool").dependOn(&run.step);
// Compiled with LLVM: the self-hosted backend emits no coverage // instrumentation, so without it `zig build test --fuzz` and kcov // both see nothing. const mod_tests = b.addTest(.{ .root_module = mod, .use_llvm = true }); const run_mod_tests = b.addRunArtifact(mod_tests);
const test_step = b.step("test", "Run the unit tests"); test_step.dependOn(&run_mod_tests.step);
// The documentation comes out of the compiler as a side effect of // building the module as a library. const library = b.addLibrary(.{ .name = "spf", .root_module = mod }); const install_docs = b.addInstallDirectory(.{ .source_dir = library.getEmittedDocs(), .install_dir = .prefix, .install_subdir = "docs", }); const docs_step = b.step("docs", "Build the API documentation into zig-out/docs"); docs_step.dependOn(&install_docs.step);
// It has to be served rather than opened: the viewer fetches // sources.tar and main.wasm at runtime and a browser refuses either // from a file:// page. const docs_server = b.addExecutable(.{ .name = "docs-server", .root_module = b.createModule(.{ .root_source_file = b.path("tools/docs_server.zig"), // Always the machine running the build, never whatever // -Dtarget the library is being built for. .target = b.graph.host, .optimize = .Debug, }), }); const run_docs_server = b.addRunArtifact(docs_server); run_docs_server.step.dependOn(&install_docs.step); run_docs_server.addDirectoryArg(library.getEmittedDocs()); run_docs_server.addArg(b.fmt("{d}", .{docs_port})); run_docs_server.stdio = .inherit; const docs_serve_step = b.step("docs-serve", "Serve the API documentation over HTTP"); docs_serve_step.dependOn(&run_docs_server.step);
test_step.dependOn(&b.addRunArtifact( b.addTest(.{ .root_module = docs_server.root_module }), ).step);
// "Compile everything without running it", so that a file nothing // else reaches cannot quietly stop building. const check_step = b.step("check", "Type-check without emitting a binary"); check_step.dependOn(&mod_tests.step); check_step.dependOn(&docs_server.step); check_step.dependOn(&exe.step);}