// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie // SPDX-License-Identifier: MIT //! The geodesic port, run against the C it was ported from. //! //! Its own project, so that Karney's C is its own project's business: nothing //! that merely builds the library should have to fetch it or compile C. The //! library comes from the checkout this sits inside, by path, so the two are //! always the same code. const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); // ReleaseSafe unless asked otherwise: fast enough for millions of cases, // and a panic in the port is one of the things being looked for. const optimize = b.option(std.lang.Optimize, "optimize", "Prioritize performance, safety, or binary size") orelse .safe; const geo = b.dependency("geo", .{ .target = target, .optimize = optimize, }); const karney = b.dependency("geographiclib_c", .{}); const geodesic_h = b.addTranslateC(.{ .root_source_file = karney.path("src/geodesic.h"), .target = target, .optimize = optimize, }); const runner = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "geo", .module = geo.module("geo") }, .{ .name = "geodesic", .module = geodesic_h.createModule() }, }, }); runner.addIncludePath(karney.path("src")); runner.addCSourceFile(.{ .file = karney.path("src/geodesic.c"), // Zig never fuses a multiply and an add unless told to, and C by // default may, which would be a difference between the two that is // the compiler's rather than either implementation's. .flags = &.{ "-std=c99", "-ffp-contract=off" }, }); const exe = b.addExecutable(.{ .name = "geodesic-reference", .root_module = runner, }); b.installArtifact(exe); const run = b.addRunArtifact(exe); run.stdio = .inherit; run.addPassthruArgs(); const run_step = b.step("run", "Compare the port with Karney's C"); run_step.dependOn(&run.step); // The hard cases on their own, as an ordinary test. const test_step = b.step("test", "Compare the port with Karney's C on the hard cases"); test_step.dependOn(&b.addRunArtifact(b.addTest(.{ .root_module = runner })).step); const check_step = b.step("check", "Compile everything without running it"); check_step.dependOn(&exe.step); }