install libomt in a sensible place (wip)

This commit is contained in:
2025-10-18 21:39:27 +03:00
parent 0421c88fd7
commit 40f2915595

View File

@@ -20,65 +20,39 @@ pub fn build(b: *std.Build) void {
std.log.warn("The build file only supports Linux x86-64 right now.\n", .{}); std.log.warn("The build file only supports Linux x86-64 right now.\n", .{});
std.log.warn( std.log.warn(
"You can extend the build.zig to call the appropriate platform scripts " ++ "You can extend the build.zig to call the appropriate platform scripts " ++
"in 3rd/libomtnet/build/ and 3rd/libomt/build.\n", "in 3rd/libomtnet/build/ and 3rd/libomt/build and 3rd/libvmx/build/\n",
.{}, .{},
); );
} }
// Build libomtnet // Build libomtnet
const libomtnet_build = b.addSystemCommand(&.{"bash"}); const libomtnet_build_script = b.addSystemCommand(&.{"bash"});
libomtnet_build.cwd = b.path("3rd/libomtnet/build"); libomtnet_build_script.cwd = b.path("3rd/libomtnet/build");
libomtnet_build.addFileArg(b.path("3rd/libomtnet/build/buildall.sh")); libomtnet_build_script.addFileArg(b.path("3rd/libomtnet/build/buildall.sh"));
// Build libomt // Build libomt
const libomt_build = b.addSystemCommand(&.{"bash"}); const libomt_build_script = b.addSystemCommand(&.{"bash"});
libomt_build.cwd = b.path("3rd/libomt/build"); libomt_build_script.cwd = b.path("3rd/libomt/build");
libomt_build.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh")); libomt_build_script.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh"));
libomt_build.step.dependOn(&libomtnet_build.step); libomt_build_script.step.dependOn(&libomtnet_build_script.step);
// TODO: install libomt.so and libomt.h in a more convenient location
const libvmx_build = b.addLibrary(.{ // const libvmx_build = b.addSystemCommand(&.{"bash"});
.root_module = b.createModule(.{ // libvmx_build.cwd = b.path("3rd/libvmx/build");
.root_source_file = null, // libvmx_build.addFileArg(b.path("3rd/libvmx/build/buildlinuxx64.sh"));
.target = target, // b.installArtifact(libvmx_build);
.optimize = optimize,
}),
.name = "libvmx",
.linkage = .dynamic,
});
libvmx_build.linkLibC(); const omt_out_path = "3rd/libomt/bin/Release/net8.0/linux-x64/publish/";
libvmx_build.linkLibCpp(); const lib_dir = b.getInstallPath(.lib, "");
const libvmx_sources = [_][]const u8{
"3rd/libvmx/src/vmxcodec_x86.cpp",
"3rd/libvmx/src/vmxcodec_avx2.cpp",
"3rd/libvmx/src/vmxcodec.cpp",
};
const libvmx_cflags = [_][]const u8{
"-O3",
"-std=c++17",
"-fdeclspec",
"-fPIC",
"-mlzcnt",
"-mavx2",
"-mbmi",
"-shared",
"-Wl,-rpath,'$ORIGIN'",
};
libvmx_build.root_module.addCSourceFiles(.{
.files = &libvmx_sources,
.flags = &libvmx_cflags,
.language = null,
});
b.installArtifact(libvmx_build); const copy_omt_h = b.installFile(
omt_out_path ++ "libomt.h",
lib_dir ++ "libomt.h",
);
// Copy libvmx to a place of happiness const copy_omt_so = b.installFile(
// TODO: Runs but doesn't do what I'd expect it to. What's going on? omt_out_path ++ "libomt.so",
// const libvmx_copy = b.addSystemCommand(&.{"cp"}); lib_dir ++ "libomt.so",
// libvmx_copy.addFileArg(b.path("3rd/libvmx/build/libvmx.so")); );
// _ = libvmx_copy.addOutputFileArg("3rd/libomt/bin/Release/net8.0/linux-x64/publish/libvmx.so");
// libvmx_copy.step.dependOn(&libvmx_build.step);
// Define executable // Define executable
const sender_exe = b.addExecutable(.{ const sender_exe = b.addExecutable(.{
@@ -90,6 +64,9 @@ pub fn build(b: *std.Build) void {
}), }),
}); });
sender_exe.linkSystemLibrary("omt");
sender_exe.linkLibC();
const receiver_exe = b.addExecutable(.{ const receiver_exe = b.addExecutable(.{
.name = "omtoy-receiver", .name = "omtoy-receiver",
.root_module = b.createModule(.{ .root_module = b.createModule(.{
@@ -99,26 +76,17 @@ pub fn build(b: *std.Build) void {
}), }),
}); });
// Link libomt with the sender and receiver
{
const omt_output_dir = b.path("3rd/libomt/bin/Release/net8.0/linux-x64/publish");
sender_exe.addIncludePath(omt_output_dir);
sender_exe.addLibraryPath(omt_output_dir);
sender_exe.linkSystemLibrary("omt");
sender_exe.linkLibC();
receiver_exe.addIncludePath(omt_output_dir);
receiver_exe.addLibraryPath(omt_output_dir);
receiver_exe.linkSystemLibrary("omt"); receiver_exe.linkSystemLibrary("omt");
receiver_exe.linkLibC(); receiver_exe.linkLibC();
} receiver_exe.step.dependOn(&copy_omt_h);
receiver_exe.step.dependOn(&copy_omt_so);
b.installArtifact(sender_exe); b.installArtifact(sender_exe);
b.installArtifact(receiver_exe); b.installArtifact(receiver_exe);
// Manual build step for libomt dependencies // Manual build step for libomt dependencies
const build_omt_step = b.step("build-omt", "Build libomtnet, libomt and libvmx"); const build_omt_step = b.step("build-omt", "Build libomtnet, libomt and libvmx");
build_omt_step.dependOn(&libomt_build.step); build_omt_step.dependOn(&libomt_build_script.step);
build_omt_step.dependOn(&libvmx_build.step);
// Add run step for sender // Add run step for sender
const run_sender_step = b.step("sender-run", "Run the sender client"); const run_sender_step = b.step("sender-run", "Run the sender client");