summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-01-11 21:31:44 -0300
committerGabriel Schneider <[email protected]>2026-01-11 21:31:44 -0300
commit264a66ac5327c85434d0df0b1821ddb61f1ce2ae (patch)
treedeeefae67f1494ee12ed141184dc28743df6a0fb /build.zig
downloadcodenomicon-264a66ac5327c85434d0df0b1821ddb61f1ce2ae.tar.gz
codenomicon-264a66ac5327c85434d0df0b1821ddb61f1ce2ae.zip
initial commit
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig67
1 files changed, 67 insertions, 0 deletions
diff --git a/build.zig b/build.zig
new file mode 100644
index 0000000..1b199d3
--- /dev/null
+++ b/build.zig
@@ -0,0 +1,67 @@
+const std = @import("std");
+
+fn capstone(b: *std.Build, options: struct {
+ target: std.Build.ResolvedTarget,
+ optimize: std.builtin.OptimizeMode,
+}) struct {
+ dep: *std.Build.Dependency,
+ artifact: *std.Build.Step.Compile,
+ mod: *std.Build.Module,
+} {
+ const capstone_dep = b.dependency("capstone", .{
+ .target = options.target,
+ .optimize = options.optimize,
+ });
+
+ const compiled_capstone = capstone_dep.artifact("capstone");
+
+ // I don't really know what I'm doing here, but it works
+ const capstone_c = b.addTranslateC(.{
+ .root_source_file = b.path("deps/tmp/capstone-6.0.0-Alpha4/include/capstone/capstone.h"),
+ // .root_source_file = capstone_dep.path("capstone.h"),
+ .target = options.target,
+ .optimize = options.optimize,
+ .link_libc = true,
+ });
+
+ const capstone_c_mod = capstone_c.createModule();
+ return .{
+ .dep = capstone_dep,
+ .artifact = compiled_capstone,
+ .mod = capstone_c_mod,
+ };
+}
+
+pub fn build(b: *std.Build) !void {
+ const target = b.standardTargetOptions(.{});
+ const optimize = b.standardOptimizeOption(.{});
+
+ const elfo_module = b.createModule(.{
+ .root_source_file = b.path("src/elfo-pretty.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
+
+ const cs = capstone(b, .{
+ .target = target,
+ .optimize = optimize,
+ });
+ elfo_module.addImport("capstone", cs.mod);
+ elfo_module.addLibraryPath(cs.artifact.getEmittedBin().dirname());
+ elfo_module.linkLibrary(cs.artifact);
+ elfo_module.addIncludePath(cs.artifact.getEmittedIncludeTree());
+
+ const elfo = b.addExecutable(.{
+ .name = "elfo-pretty",
+ .root_module = elfo_module,
+ });
+
+ elfo.linkLibrary(cs.artifact);
+ b.installArtifact(elfo);
+
+ const run_cmd = b.addRunArtifact(elfo);
+ const run_step = b.step("elfo", "See the pretty elfo!");
+ run_step.dependOn(&run_cmd.step);
+
+ // TODO: add flag to run on pwndbg
+}