105 lines
3.3 KiB
Zig
105 lines
3.3 KiB
Zig
const std = @import("std");
|
|
|
|
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 openflights = b.dependency("openflights", .{});
|
|
|
|
const maxminddb_upstream = b.dependency("maxminddb", .{});
|
|
|
|
// 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 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.addAnonymousImport("airports.dat", .{
|
|
.root_source_file = openflights.path("data/airports.dat"),
|
|
});
|
|
exe.root_module.addIncludePath(maxminddb_upstream.path("include"));
|
|
exe.root_module.addConfigHeader(maxminddb_config);
|
|
exe.linkLibrary(maxminddb);
|
|
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);
|
|
|
|
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.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.addConfigHeader(maxminddb_config);
|
|
tests.linkLibrary(maxminddb);
|
|
tests.linkLibC();
|
|
|
|
const run_tests = b.addRunArtifact(tests);
|
|
const test_step = b.step("test", "Run tests");
|
|
test_step.dependOn(&run_tests.step);
|
|
}
|