reorganize build script

This commit is contained in:
2025-10-20 22:56:38 +03:00
parent a8f1bf5d85
commit c84a256fba

174
build.zig
View File

@@ -26,46 +26,55 @@ pub fn build(b: *std.Build) void {
); );
return; return;
} }
// This comes from the libomt build scripts
const omt_out_path = "3rd/libomt/bin/Release/net8.0/linux-x64/publish/";
// Build libomtnet {
const libomtnet_build_script = b.addSystemCommand(&.{"bash"}); // This comes from the libomt build scripts
libomtnet_build_script.cwd = b.path("3rd/libomtnet/build"); const omt_out_path = "3rd/libomt/bin/Release/net8.0/linux-x64/publish/";
libomtnet_build_script.addFileArg(b.path("3rd/libomtnet/build/buildall.sh"));
// Doesn't need install, libomt/build scripts assume a folder hierarchy // 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 // Build libomt
const libomt_build_script = b.addSystemCommand(&.{"bash"}); const libomt_build_script = b.addSystemCommand(&.{"bash"});
libomt_build_script.cwd = b.path("3rd/libomt/build"); libomt_build_script.cwd = b.path("3rd/libomt/build");
libomt_build_script.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh")); libomt_build_script.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh"));
libomt_build_script.step.dependOn(&libomtnet_build_script.step); libomt_build_script.step.dependOn(&libomtnet_build_script.step);
// Install libomt // Install libomt
const install_omt_h = b.addInstallHeaderFile( const install_omt_h = b.addInstallHeaderFile(
b.path(b.pathJoin(&.{ omt_out_path, "libomt.h" })), b.path(b.pathJoin(&.{ omt_out_path, "libomt.h" })),
"libomt.h", "libomt.h",
); );
install_omt_h.step.dependOn(&libomt_build_script.step); install_omt_h.step.dependOn(&libomt_build_script.step);
const install_omt_so = b.addInstallLibFile( const install_omt_so = b.addInstallLibFile(
b.path(b.pathJoin(&.{ omt_out_path, "libomt.so" })), b.path(b.pathJoin(&.{ omt_out_path, "libomt.so" })),
"libomt.so", "libomt.so",
); );
install_omt_so.step.dependOn(&libomt_build_script.step); install_omt_so.step.dependOn(&libomt_build_script.step);
// Build libvmx // Build libvmx
const libvmx_build = b.addSystemCommand(&.{"bash"}); const libvmx_build = b.addSystemCommand(&.{"bash"});
libvmx_build.cwd = b.path("3rd/libvmx/build"); libvmx_build.cwd = b.path("3rd/libvmx/build");
libvmx_build.addFileArg(b.path("3rd/libvmx/build/buildlinuxx64.sh")); libvmx_build.addFileArg(b.path("3rd/libvmx/build/buildlinuxx64.sh"));
// Install libvmx // Install libvmx
const install_vmx_so = b.addInstallLibFile( const install_vmx_so = b.addInstallLibFile(
b.path("3rd/libvmx/build/libvmx.so"), b.path("3rd/libvmx/build/libvmx.so"),
"libvmx.so", "libvmx.so",
); );
install_vmx_so.step.dependOn(&libvmx_build.step); install_vmx_so.step.dependOn(&libvmx_build.step);
{
// Manual build step for libomt dependencies
const build_omt_step = b.step("omt", "Build libomtnet, libomt and libvmx");
build_omt_step.dependOn(&install_omt_h.step);
build_omt_step.dependOn(&install_omt_so.step);
build_omt_step.dependOn(&install_vmx_so.step);
}
}
// The output lib and header directories // The output lib and header directories
const lib_output_path: std.Build.LazyPath = .{ const lib_output_path: std.Build.LazyPath = .{
@@ -81,68 +90,69 @@ pub fn build(b: *std.Build) void {
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
omt_module.linkSystemLibrary("omt", .{}); omt_module.linkSystemLibrary("omt", .{});
// 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.root_module.addImport("omt", omt_module);
omt_module.addLibraryPath(lib_output_path); omt_module.addLibraryPath(lib_output_path);
omt_module.addIncludePath(include_output_path); omt_module.addIncludePath(include_output_path);
sender_exe.root_module.addLibraryPath(lib_output_path); {
sender_exe.root_module.addIncludePath(include_output_path); // Define executables
sender_exe.linkSystemLibrary("omt"); const sender_exe = b.addExecutable(.{
sender_exe.linkLibC(); .name = "omtoy-sender",
.root_module = b.createModule(.{
.root_source_file = b.path("src/sender.zig"),
.target = target,
.optimize = optimize,
}),
});
sender_exe.root_module.addImport("omt", omt_module);
const receiver_exe = b.addExecutable(.{ sender_exe.root_module.addLibraryPath(lib_output_path);
.name = "omtoy-receiver", sender_exe.root_module.addIncludePath(include_output_path);
.root_module = b.createModule(.{ sender_exe.linkSystemLibrary("omt");
.root_source_file = b.path("src/receiver.zig"), sender_exe.linkLibC();
.target = target,
.optimize = optimize,
}),
});
receiver_exe.root_module.addImport("omt", omt_module);
receiver_exe.root_module.addLibraryPath(lib_output_path); b.installArtifact(sender_exe);
receiver_exe.root_module.addIncludePath(include_output_path);
receiver_exe.linkSystemLibrary("omt");
receiver_exe.linkLibC();
b.installArtifact(sender_exe); // Add run step for sender
b.installArtifact(receiver_exe); 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);
run_sender_cmd.step.dependOn(b.getInstallStep());
// Manual build step for libomt dependencies // Don't actually have arguments, so this is moot
const build_omt_step = b.step("omt", "Build libomtnet, libomt and libvmx"); if (b.args) |args| {
build_omt_step.dependOn(&install_omt_h.step); run_sender_cmd.addArgs(args);
build_omt_step.dependOn(&install_omt_so.step); }
build_omt_step.dependOn(&install_vmx_so.step); }
// Add run step for sender {
const run_sender_step = b.step("sender-run", "Run the sender client"); const receiver_exe = b.addExecutable(.{
const run_sender_cmd = b.addRunArtifact(sender_exe); .name = "omtoy-receiver",
run_sender_step.dependOn(&run_sender_cmd.step); .root_module = b.createModule(.{
.root_source_file = b.path("src/receiver.zig"),
.target = target,
.optimize = optimize,
}),
});
receiver_exe.root_module.addImport("omt", omt_module);
const run_receiver_step = b.step("receiver-run", "Run the receiver client"); receiver_exe.root_module.addLibraryPath(lib_output_path);
const run_receiver_cmd = b.addRunArtifact(receiver_exe); receiver_exe.root_module.addIncludePath(include_output_path);
run_receiver_step.dependOn(&run_receiver_cmd.step); receiver_exe.linkSystemLibrary("omt");
receiver_exe.linkLibC();
// Add run step for receiver b.installArtifact(receiver_exe);
run_sender_cmd.step.dependOn(b.getInstallStep()); const run_receiver_step = b.step("receiver-run", "Run the receiver client");
run_receiver_cmd.step.dependOn(b.getInstallStep()); const run_receiver_cmd = b.addRunArtifact(receiver_exe);
run_receiver_step.dependOn(&run_receiver_cmd.step);
run_receiver_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| { // Don't actually have arguments so this is moot
run_sender_cmd.addArgs(args); if (b.args) |args| {
run_receiver_cmd.addArgs(args); run_receiver_cmd.addArgs(args);
}
} }
// TODO: write tests and stuff // TODO: write tests and stuff