wttr/build.zig

172 lines
5.4 KiB
Zig

const std = @import("std");
const GitVersion = @import("build/GitVersion.zig");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const httpz = b.dependency("httpz", .{
.target = target,
.optimize = optimize,
});
const zeit = b.dependency("zeit", .{
.target = target,
.optimize = optimize,
});
const openflights = b.dependency("openflights", .{});
const maxminddb_upstream = b.dependency("maxminddb", .{});
// Build sunriset as a static library
const sunriset = b.addLibrary(.{
.name = "sunriset",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
sunriset.addIncludePath(b.path("libs/sunriset"));
sunriset.addCSourceFiles(.{
.root = b.path("libs/sunriset"),
.files = &.{
"sunriset.c",
},
.flags = &.{ "-D_DEFAULT_SOURCE", "-DSUNRISET_NO_MAIN" },
});
sunriset.linkLibC();
sunriset.linkSystemLibrary("m");
// Build phoon as a static library
const phoon = b.addLibrary(.{
.name = "phoon",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
phoon.addIncludePath(b.path("libs/phoon_14Aug2014"));
phoon.addCSourceFiles(.{
.root = b.path("libs/phoon_14Aug2014"),
.files = &.{
"astro.c",
"date_parse.c",
},
.flags = &.{ "-std=c99", "-D_DEFAULT_SOURCE" },
});
phoon.linkLibC();
phoon.linkSystemLibrary("m");
// Build libmaxminddb as a static library
const maxminddb = b.addLibrary(.{
.name = "maxminddb",
.linkage = .static,
.root_module = b.createModule(.{
.target = target,
.optimize = optimize,
.link_libc = true,
}),
});
// Generate maxminddb_config.h
const maxminddb_config = b.addConfigHeader(.{
.style = .blank,
.include_path = "maxminddb_config.h",
}, .{
.PACKAGE_VERSION = "1.11.0",
.MMDB_UINT128_USING_MODE = 1,
});
maxminddb.addConfigHeader(maxminddb_config);
maxminddb.addIncludePath(maxminddb_upstream.path("include"));
maxminddb.addIncludePath(maxminddb_upstream.path("src"));
maxminddb.addCSourceFiles(.{
.root = maxminddb_upstream.path(""),
.files = &.{
"src/data-pool.c",
"src/maxminddb.c",
},
.flags = &.{},
});
maxminddb.installHeadersDirectory(maxminddb_upstream.path("include"), "", .{});
const version = GitVersion.getVersion(b, .{});
const build_options = b.addOptions();
build_options.addOption([]const u8, "version", version);
const exe = b.addExecutable(.{
.name = "wttr",
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
exe.root_module.addImport("httpz", httpz.module("httpz"));
exe.root_module.addImport("zeit", zeit.module("zeit"));
exe.root_module.addAnonymousImport("airports.dat", .{
.root_source_file = openflights.path("data/airports.dat"),
});
exe.root_module.addOptions("build_options", build_options);
exe.root_module.addIncludePath(maxminddb_upstream.path("include"));
exe.root_module.addIncludePath(b.path("libs/phoon_14Aug2014"));
exe.root_module.addIncludePath(b.path("libs/sunriset"));
exe.root_module.addConfigHeader(maxminddb_config);
exe.linkLibrary(maxminddb);
exe.linkLibrary(phoon);
exe.linkLibrary(sunriset);
exe.linkLibC();
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const download_geoip = b.option(bool, "download-geoip", "Download GeoIP database for tests") orelse false;
const test_options = b.addOptions();
test_options.addOption(bool, "download_geoip", download_geoip);
test_options.addOption([]const u8, "version", version);
const tests = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
}),
});
tests.root_module.addImport("httpz", httpz.module("httpz"));
tests.root_module.addImport("zeit", zeit.module("zeit"));
tests.root_module.addAnonymousImport("airports.dat", .{
.root_source_file = openflights.path("data/airports.dat"),
});
tests.root_module.addOptions("build_options", test_options);
tests.root_module.addIncludePath(maxminddb_upstream.path("include"));
tests.root_module.addIncludePath(b.path("libs/phoon_14Aug2014"));
tests.root_module.addIncludePath(b.path("libs/sunriset"));
tests.root_module.addConfigHeader(maxminddb_config);
tests.linkLibrary(maxminddb);
tests.linkLibrary(phoon);
tests.linkLibrary(sunriset);
tests.linkLibC();
const run_tests = b.addRunArtifact(tests);
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_tests.step);
}