oslib/server/build.zig

75 lines
2.5 KiB
Zig
Raw Normal View History

2024-06-24 12:54:49 -06:00
const std = @import("std");
const Build = std.Build;
const Step = Build.Step;
2024-06-24 12:54:49 -06:00
pub fn build(b: *std.Build) !void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const translate_c = b.addTranslateC(.{
.root_source_file = b.path("libvirt/include/libvirt/libvirt.h"),
.target = target,
.optimize = optimize,
});
translate_c.addIncludeDir("libvirt/include");
const output = b.addInstallFile(translate_c.getOutput(), "libvirt.zig");
const exe = b.addExecutable(.{
.name = "server",
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
exe.step.dependOn(&output.step);
exe.linkLibC();
exe.root_module.addIncludePath(b.path("libvirt/include"));
// exe.linkSystemLibrary("libvirt");
exe.addLibraryPath(b.path("libvirt/lib"));
exe.addObjectFile(b.path("libvirt/lib/libvirt.so.0.10000.0"));
exe.addObjectFile(b.path("libvirt/lib/libvirt-admin.so.0.10000.0"));
exe.addObjectFile(b.path("libvirt/lib/libvirt-qemu.so.0.10000.0"));
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 libvirt_test = b.addTest(.{
.root_source_file = b.path("src/libvirt.zig"),
2024-06-24 12:54:49 -06:00
.target = target,
.optimize = optimize,
.link_libc = true,
2024-06-24 12:54:49 -06:00
});
const libvirt_connection_test = b.addTest(.{
.root_source_file = b.path("src/libvirt-connection.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const libvirt_unit_tests = [_]*Step.Compile{
libvirt_test,
libvirt_connection_test,
};
for (libvirt_unit_tests) |tests| {
tests.root_module.addIncludePath(b.path("libvirt/include"));
tests.addLibraryPath(b.path("libvirt/lib"));
tests.addObjectFile(b.path("libvirt/lib/libvirt.so.0.10000.0"));
tests.addObjectFile(b.path("libvirt/lib/libvirt-admin.so.0.10000.0"));
tests.addObjectFile(b.path("libvirt/lib/libvirt-qemu.so.0.10000.0"));
}
2024-06-24 12:54:49 -06:00
const run_libvirt_tests = [_]*Step.Run{
b.addRunArtifact(libvirt_test),
b.addRunArtifact(libvirt_connection_test),
};
2024-06-24 12:54:49 -06:00
const test_step = b.step("test", "Run unit tests");
for (run_libvirt_tests) |tests| test_step.dependOn(&tests.step);
2024-06-24 12:54:49 -06:00
}