diff options
| author | Gabriel Schneider <[email protected]> | 2026-02-19 23:21:06 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-02-19 23:21:06 -0300 |
| commit | 169ba71c6ca54be373a3bbccf17ba199bba17ca8 (patch) | |
| tree | ff7edd742f5e95f9e14e395434e124341696b7ab /build.zig | |
| parent | cea7000b4c911166faa90a6d0516ca0f12920fbb (diff) | |
| download | codenomicon-169ba71c6ca54be373a3bbccf17ba199bba17ca8.tar.gz codenomicon-169ba71c6ca54be373a3bbccf17ba199bba17ca8.zip | |
added option to run with gdb
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 53 |
1 files changed, 43 insertions, 10 deletions
@@ -12,11 +12,12 @@ pub fn build(b: *std.Build) !void { }); const elfo = b.addExecutable(.{ - .name = "elfo-pretty", + .name = "elfo", .root_module = b.createModule(.{ - .root_source_file = b.path("src/elfo-pretty.zig"), + .root_source_file = b.path("src/elfo.zig"), .target = target, .optimize = optimize, + .link_libc = true, }), }); @@ -47,15 +48,45 @@ pub fn build(b: *std.Build) !void { b.installArtifact(elfo); b.installArtifact(gloves); - const run_elfo_cmd = b.addRunArtifact(elfo); - const run_elfo_step = b.step("elfo", "See the pretty elfo!"); - run_elfo_step.dependOn(&run_elfo_cmd.step); + const gdb_opt = b.option(bool, "gdb", "Run executable under gdb") orelse false; + const comp_opts = b.addOptions(); + comp_opts.addOption(bool, "gdb", gdb_opt); - const run_gloves_cmd = b.addRunArtifact(gloves); + const unit_tests = b.addTest(.{ + .root_module = b.createModule(.{ + .optimize = optimize, + .target = target, + .root_source_file = b.path("tests/test.zig"), + }), + }); + + const test_step = b.step("test", "Test the library"); + + const run_elfo_step = b.step("elfo", "See the pretty elfo!"); const run_gloves_step = b.step("gloves", "See the pretty gloves!"); - run_gloves_step.dependOn(&run_gloves_cmd.step); - // TODO: add flag to run on gdb + const run_steps = [_]struct { *std.Build.Step, *std.Build.Step.Compile }{ + .{ test_step, unit_tests }, + .{ run_elfo_step, elfo }, + .{ run_gloves_step, gloves }, + }; + const gdbscript = b.addWriteFile("gdbscript", + \\r + ); + + for (run_steps) |run| { + run.@"1".root_module.addOptions("meta", comp_opts); + if (gdb_opt) { + const run_gdb = b.addSystemCommand(&.{"gdb"}); + run_gdb.addArg("-x"); + run_gdb.addFileArg(gdbscript.getDirectory().path(b, "gdbscript")); + run_gdb.addArtifactArg(run.@"1"); + run.@"0".dependOn(&run_gdb.step); + } else { + const run_unit = b.addRunArtifact(run.@"1"); + run.@"0".dependOn(&run_unit.step); + } + } } fn gum_stalker(b: *std.Build, opts: struct { @@ -87,7 +118,8 @@ fn gum_stalker(b: *std.Build, opts: struct { // C-only module (translate-c can't handle GLib's _Pragma macros) const c_mod = b.createModule(.{ .target = opts.target, - .optimize = opts.optimize, + // .optimize = opts.optimize, + .optimize = .Debug, .link_libc = true, }); @@ -239,7 +271,8 @@ fn capstone(b: *std.Build, opts: struct { const translate_c = b.addTranslateC(.{ .root_source_file = capstone_dep.path("include/capstone/capstone.h"), .target = opts.target, - .optimize = opts.optimize, + // .optimize = opts.optimize, + .optimize = .Debug, .link_libc = true, }); |
