diff --git a/.gitmodules b/.gitmodules index 5e48e76..a5d0e04 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,15 +1,3 @@ -[submodule "3rd/libomt"] - path = 3rd/libomt - url = https://github.com/openmediatransport/libomt -[submodule "3rd/libomtnet"] - path = 3rd/libomtnet - url = https://github.com/openmediatransport/libomtnet -[submodule "3rd/omt-examples"] - path = 3rd/omt-examples - url = https://github.com/openmediatransport/Examples.git -[submodule "3rd/libvmx"] - path = 3rd/libvmx - url = https://github.com/openmediatransport/libvmx.git [submodule "3rd/glfw"] path = 3rd/glfw url = https://github.com/glfw/glfw.git diff --git a/3rd/libomt b/3rd/libomt deleted file mode 160000 index da0bc46..0000000 --- a/3rd/libomt +++ /dev/null @@ -1 +0,0 @@ -Subproject commit da0bc46685ab00d62699822469d0ceddd16aeb75 diff --git a/3rd/libomtnet b/3rd/libomtnet deleted file mode 160000 index d2a6251..0000000 --- a/3rd/libomtnet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d2a62512c595cea4e2ed44e59a46ddcd45765caa diff --git a/3rd/libvmx b/3rd/libvmx deleted file mode 160000 index 2831976..0000000 --- a/3rd/libvmx +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2831976d9fd37d7719d5350849eb0d6da7d49ee6 diff --git a/3rd/omt-examples b/3rd/omt-examples deleted file mode 160000 index 8963efe..0000000 --- a/3rd/omt-examples +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 8963efe0ce48f288c231fbedd76264144eea8d4a diff --git a/build.zig b/build.zig index 66bff8d..312eef5 100644 --- a/build.zig +++ b/build.zig @@ -100,7 +100,7 @@ pub fn build(b: *std.Build) void { const sender_exe = b.addExecutable(.{ .name = "omtoy-sender", .root_module = b.createModule(.{ - .root_source_file = b.path("src/sender.zig"), + .root_source_file = b.path("utils/sender.zig"), .target = target, .optimize = optimize, }), @@ -130,7 +130,7 @@ pub fn build(b: *std.Build) void { const receiver_exe = b.addExecutable(.{ .name = "omtoy-receiver", .root_module = b.createModule(.{ - .root_source_file = b.path("src/receiver.zig"), + .root_source_file = b.path("utils/receiver.zig"), .target = target, .optimize = optimize, }), diff --git a/omt/build.zig b/omt/build.zig new file mode 100644 index 0000000..104dfe1 --- /dev/null +++ b/omt/build.zig @@ -0,0 +1,167 @@ +// +// OMT module for zig +// +// Build required OMT parts and link against our code +// +// Run `zig build omt` to build dependencies before anything else. +// +// I don't know yet how to best create a conditional step to build and install +// the dependencies only if they aren't installed yet. Just putting the installs +// as dependencies runs the omt build scripts on every `zig build`. +// +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/ " ++ + "and modifying the install scripts", + .{}, + ); + 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"}); + 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); + + // Install libomt + const install_omt_h = b.addInstallHeaderFile( + b.path(b.pathJoin(&.{ omt_out_path, "libomt.h" })), + "libomt.h", + ); + install_omt_h.step.dependOn(&libomt_build_script.step); + + const install_omt_so = b.addInstallLibFile( + b.path(b.pathJoin(&.{ omt_out_path, "libomt.so" })), + "libomt.so", + ); + install_omt_so.step.dependOn(&libomt_build_script.step); + + // Build libvmx + const libvmx_build = b.addSystemCommand(&.{"bash"}); + libvmx_build.cwd = b.path("3rd/libvmx/build"); + libvmx_build.addFileArg(b.path("3rd/libvmx/build/buildlinuxx64.sh")); + + // Install libvmx + const install_vmx_so = b.addInstallLibFile( + b.path("3rd/libvmx/build/libvmx.so"), + "libvmx.so", + ); + 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 + const lib_output_path: std.Build.LazyPath = .{ + .cwd_relative = b.lib_dir, + }; + const include_output_path: std.Build.LazyPath = .{ + .cwd_relative = b.h_dir, + }; + + // Zig omt module + const omt_module = b.addModule("omt", .{ + .root_source_file = b.path("src/omt.zig"), + .target = target, + .optimize = optimize, + }); + + omt_module.linkSystemLibrary("omt", .{}); + omt_module.addLibraryPath(lib_output_path); + omt_module.addIncludePath(include_output_path); + + { + // Define executables + const sender_exe = b.addExecutable(.{ + .name = "omtoy-sender", + .root_module = b.createModule(.{ + .root_source_file = b.path("utils/sender.zig"), + .target = target, + .optimize = optimize, + }), + }); + sender_exe.root_module.addImport("omt", omt_module); + + sender_exe.root_module.addLibraryPath(lib_output_path); + sender_exe.root_module.addIncludePath(include_output_path); + sender_exe.linkSystemLibrary("omt"); + sender_exe.linkLibC(); + + b.installArtifact(sender_exe); + + // 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); + run_sender_cmd.step.dependOn(b.getInstallStep()); + + // Don't actually have arguments, so this is moot + if (b.args) |args| { + run_sender_cmd.addArgs(args); + } + } + + { + const receiver_exe = b.addExecutable(.{ + .name = "omtoy-receiver", + .root_module = b.createModule(.{ + .root_source_file = b.path("utils/receiver.zig"), + .target = target, + .optimize = optimize, + }), + }); + receiver_exe.root_module.addImport("omt", omt_module); + + receiver_exe.root_module.addLibraryPath(lib_output_path); + receiver_exe.root_module.addIncludePath(include_output_path); + receiver_exe.linkSystemLibrary("omt"); + receiver_exe.linkLibC(); + + b.installArtifact(receiver_exe); + + 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); + run_receiver_cmd.step.dependOn(b.getInstallStep()); + + // Don't actually have arguments so this is moot + if (b.args) |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); +} diff --git a/src/omt.zig b/omt/src/omt.zig similarity index 100% rename from src/omt.zig rename to omt/src/omt.zig diff --git a/src/receiver.zig b/omt/utils/receiver.zig similarity index 100% rename from src/receiver.zig rename to omt/utils/receiver.zig diff --git a/src/sender.zig b/omt/utils/sender.zig similarity index 100% rename from src/sender.zig rename to omt/utils/sender.zig