diff --git a/build.zig b/build.zig index a16b09b..862771d 100644 --- a/build.zig +++ b/build.zig @@ -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( "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 - const libomtnet_build = b.addSystemCommand(&.{"bash"}); - libomtnet_build.cwd = b.path("3rd/libomtnet/build"); - libomtnet_build.addFileArg(b.path("3rd/libomtnet/build/buildall.sh")); + 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 = b.addSystemCommand(&.{"bash"}); - libomt_build.cwd = b.path("3rd/libomt/build"); - libomt_build.addFileArg(b.path("3rd/libomt/build/buildlinuxx64.sh")); - libomt_build.step.dependOn(&libomtnet_build.step); - // TODO: install libomt.so and libomt.h in a more convenient location + 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.addLibrary(.{ - .root_module = b.createModule(.{ - .root_source_file = null, - .target = target, - .optimize = optimize, - }), - .name = "libvmx", - .linkage = .dynamic, - }); + // 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); - libvmx_build.linkLibC(); - libvmx_build.linkLibCpp(); - 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, - }); + const omt_out_path = "3rd/libomt/bin/Release/net8.0/linux-x64/publish/"; + const lib_dir = b.getInstallPath(.lib, ""); - 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 - // TODO: Runs but doesn't do what I'd expect it to. What's going on? - // const libvmx_copy = b.addSystemCommand(&.{"cp"}); - // 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); + const copy_omt_so = b.installFile( + omt_out_path ++ "libomt.so", + lib_dir ++ "libomt.so", + ); // Define executable 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(.{ .name = "omtoy-receiver", .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.linkLibC(); - } + receiver_exe.linkSystemLibrary("omt"); + receiver_exe.linkLibC(); + receiver_exe.step.dependOn(©_omt_h); + receiver_exe.step.dependOn(©_omt_so); b.installArtifact(sender_exe); b.installArtifact(receiver_exe); // Manual build step for libomt dependencies const build_omt_step = b.step("build-omt", "Build libomtnet, libomt and libvmx"); - build_omt_step.dependOn(&libomt_build.step); - build_omt_step.dependOn(&libvmx_build.step); + build_omt_step.dependOn(&libomt_build_script.step); // Add run step for sender const run_sender_step = b.step("sender-run", "Run the sender client");