const std = @import("std"); const Profile = struct { name: []const u8, exe_name: []const u8, local_socket: bool, remote_transport: bool, plugin_host: bool, bundled_pi: bool, background_agent: bool, tool_mutation: []const u8, }; pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const profiles = [_]Profile{ .{ .name = "dev-local", .exe_name = "mim", .local_socket = true, .remote_transport = false, .plugin_host = false, .bundled_pi = false, .background_agent = false, .tool_mutation = "protocol_logged", }, .{ .name = "minimal", .exe_name = "mim-min", .local_socket = false, .remote_transport = false, .plugin_host = false, .bundled_pi = false, .background_agent = false, .tool_mutation = "not_built", }, .{ .name = "coding", .exe_name = "mim-code", .local_socket = true, .remote_transport = false, .plugin_host = false, .bundled_pi = false, .background_agent = false, .tool_mutation = "protocol_logged", }, .{ .name = "full-local", .exe_name = "mim-full", .local_socket = true, .remote_transport = false, .plugin_host = false, .bundled_pi = false, .background_agent = false, .tool_mutation = "protocol_logged", }, }; const main_mod = profileModule(b, target, optimize, profiles[0]); const exe = b.addExecutable(.{ .name = profiles[0].exe_name, .root_module = main_mod, }); b.installArtifact(exe); inline for (profiles[1..]) |profile| { const profile_exe = b.addExecutable(.{ .name = profile.exe_name, .root_module = profileModule(b, target, optimize, profile), }); b.installArtifact(profile_exe); const run_profile = b.addRunArtifact(profile_exe); run_profile.step.dependOn(b.getInstallStep()); if (b.args) |args| run_profile.addArgs(args); const step_name = if (std.mem.eql(u8, profile.exe_name, "mim-min")) "run-min" else if (std.mem.eql(u8, profile.exe_name, "mim-code")) "run-code" else "run-full"; const run_profile_step = b.step(step_name, "Run profile variant"); run_profile_step.dependOn(&run_profile.step); } const run_cmd = b.addRunArtifact(exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step("run", "Run mim"); run_step.dependOn(&run_cmd.step); const tests = b.addTest(.{ .root_module = profileModule(b, target, optimize, profiles[0]), }); const test_cmd = b.addRunArtifact(tests); const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&test_cmd.step); } fn profileModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, profile: Profile) *std.Build.Module { const options = b.addOptions(); options.addOption([]const u8, "active_profile", profile.name); options.addOption(bool, "local_socket", profile.local_socket); options.addOption(bool, "remote_transport_built", profile.remote_transport); options.addOption(bool, "plugin_host_built", profile.plugin_host); options.addOption(bool, "bundled_pi_built", profile.bundled_pi); options.addOption(bool, "background_agent_built", profile.background_agent); options.addOption([]const u8, "tool_mutation", profile.tool_mutation); const mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); mod.addOptions("build_options", options); return mod; }