Files
omtoy/build.zig

122 lines
4.2 KiB
Zig

//
// Omtoy build script
//
// Build required OMT parts and link against our code
//
// Run `zig build build-omt` to build dependencies before anything else.
//
// TODO: I don't know if libvmx needs to be in the same directory as libomt _for libomt.so_
// or for the final executables. Right now I just move it next to libomt which is also
// passed as libLibrary for the executables
// TODO: Use install commands to move the libomt artifacts to a more sensible place
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const triple = target.result;
if (triple.os.tag != .linux or triple.cpu.arch != .x86_64) {
std.log.warn("The build file only supports Linux x86-64 right now.\n", .{});
std.log.warn(
"You can extend the build.zig to call the appropriate platform scripts " ++
"in 3rd/libomtnet/build/ and 3rd/libomt/build and 3rd/libvmx/build/\n",
.{},
);
}
// Build libomtnet
const libomtnet_build_script = b.addSystemCommand(&.{"bash"});
libomtnet_build_script.cwd = b.path("3rd/libomtnet/build");
libomtnet_build_script.addFileArg(b.path("3rd/libomtnet/build/buildall.sh"));
// Build libomt
const libomt_build_script = b.addSystemCommand(&.{"bash"});
libomt_build_script.cwd = b.path("3rd/libomt/build");
libomt_build_script.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh"));
libomt_build_script.step.dependOn(&libomtnet_build_script.step);
// const libvmx_build = b.addSystemCommand(&.{"bash"});
// libvmx_build.cwd = b.path("3rd/libvmx/build");
// libvmx_build.addFileArg(b.path("3rd/libvmx/build/buildlinuxx64.sh"));
// b.installArtifact(libvmx_build);
const omt_out_path = "3rd/libomt/bin/Release/net8.0/linux-x64/publish/";
const copy_omt_h = b.addInstallFileWithDir(
b.path(b.pathJoin(&.{ omt_out_path, "libomt.h" })),
.header,
"libomt.h",
);
copy_omt_h.step.dependOn(&libomt_build_script.step);
const copy_omt_so = b.addInstallFileWithDir(
b.path(b.pathJoin(&.{ omt_out_path, "libomt.so" })),
.lib,
"libomt.so",
);
copy_omt_so.step.dependOn(&libomt_build_script.step);
// Define executable
const sender_exe = b.addExecutable(.{
.name = "omtoy-sender",
.root_module = b.createModule(.{
.root_source_file = b.path("src/sender.zig"),
.target = target,
.optimize = optimize,
}),
});
sender_exe.linkSystemLibrary("omt");
sender_exe.linkLibC();
const receiver_exe = b.addExecutable(.{
.name = "omtoy-receiver",
.root_module = b.createModule(.{
.root_source_file = b.path("src/receiver.zig"),
.target = target,
.optimize = optimize,
}),
});
receiver_exe.linkSystemLibrary("omt");
receiver_exe.linkLibC();
b.installArtifact(sender_exe);
b.installArtifact(receiver_exe);
// Manual build step for libomt dependencies
const build_omt_step = b.step("omt", "Build libomtnet, libomt and libvmx");
build_omt_step.dependOn(&copy_omt_h.step);
build_omt_step.dependOn(&copy_omt_so.step);
// Add run step for sender
const run_sender_step = b.step("sender-run", "Run the sender client");
const run_sender_cmd = b.addRunArtifact(sender_exe);
run_sender_step.dependOn(&run_sender_cmd.step);
const run_receiver_step = b.step("receiver-run", "Run the receiver client");
const run_receiver_cmd = b.addRunArtifact(receiver_exe);
run_receiver_step.dependOn(&run_receiver_cmd.step);
// Add run step for receiver
run_sender_cmd.step.dependOn(b.getInstallStep());
run_receiver_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_sender_cmd.addArgs(args);
run_receiver_cmd.addArgs(args);
}
// TODO: write tests and stuff
// const exe_tests = b.addTest(.{
// .root_module = sender_exe.root_module,
// });
// const run_exe_tests = b.addRunArtifact(exe_tests);
// const test_step = b.step("test", "Run tests");
// test_step.dependOn(&run_exe_tests.step);
}