137 lines
5.0 KiB
Zig
137 lines
5.0 KiB
Zig
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);
|
|
addRunProfileStep(b, profile, profile_exe);
|
|
addServerInstallSteps(b, profile, profile_exe);
|
|
}
|
|
|
|
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 addRunProfileStep(b: *std.Build, profile: Profile, exe: *std.Build.Step.Compile) void {
|
|
const run_profile = b.addRunArtifact(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);
|
|
}
|
|
|
|
fn addServerInstallSteps(b: *std.Build, profile: Profile, exe: *std.Build.Step.Compile) void {
|
|
const suffix = if (std.mem.eql(u8, profile.exe_name, "mim-min")) "min" else if (std.mem.eql(u8, profile.exe_name, "mim-code")) "code" else "full";
|
|
const install_name = b.fmt("install-{s}", .{suffix});
|
|
const verify_name = b.fmt("verify-install-{s}", .{suffix});
|
|
|
|
const install_file = b.addInstallBinFile(exe.getEmittedBin(), "mim");
|
|
const install_step = b.step(install_name, "Install selected profile binary as bin/mim");
|
|
install_step.dependOn(&install_file.step);
|
|
|
|
const installed_path = b.getInstallPath(.bin, "mim");
|
|
const verify_cmd = b.addSystemCommand(&.{ installed_path, "--version" });
|
|
verify_cmd.step.dependOn(&install_file.step);
|
|
const verify_step = b.step(verify_name, "Verify installed selected profile binary");
|
|
verify_step.dependOn(&verify_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;
|
|
}
|