From 9e57efe13c5d59fef226e9ed655d31e88bd47ea1 Mon Sep 17 00:00:00 2001 From: Peterino2 Date: Sat, 3 Jan 2026 02:06:43 -0800 Subject: [PATCH] what the helly --- .gitignore | 2 ++ build.zig | 38 ++++++++++++++++++++++++++++++++++++++ lib.zig | 5 +++++ main.zig | 20 ++++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 build.zig create mode 100644 lib.zig create mode 100644 main.zig diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3389c86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.zig-cache/ +zig-out/ diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..b47569a --- /dev/null +++ b/build.zig @@ -0,0 +1,38 @@ +const std = @import("std"); + +pub fn build(b: *std.Build) void { + const target = b.standardTargetOptions(.{}); + const optimize = b.standardOptimizeOption(.{}); + + const lib = b.addLibrary(.{ + .name = "shared", + .root_module = b.createModule(.{ + .root_source_file = b.path("lib.zig"), + .target = target, + .optimize = optimize, + }), + .linkage = .dynamic, + }); + lib.linkLibC(); + b.installArtifact(lib); + + const exe = b.addExecutable(.{ + .name = "repro", + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = optimize, + }), + }); + b.installArtifact(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 the test program"); + run_step.dependOn(&run_cmd.step); +} diff --git a/lib.zig b/lib.zig new file mode 100644 index 0000000..40f7300 --- /dev/null +++ b/lib.zig @@ -0,0 +1,5 @@ +const std = @import("std"); + +pub export fn test_debug_print() callconv(.c) void { + std.debug.print("hi, this crashes\n", .{}); +} diff --git a/main.zig b/main.zig new file mode 100644 index 0000000..c63342e --- /dev/null +++ b/main.zig @@ -0,0 +1,20 @@ +const std = @import("std"); + +pub fn main() !void { + // Load the shared library + var lib = try std.DynLib.open("./zig-out/lib/libshared.so"); + defer lib.close(); + + std.debug.print("Loaded that shizz\n", .{}); + + const test_debug_print = lib.lookup(*const fn () callconv(.c) void, "test_debug_print") orelse { + return error.CantFindIt; + }; + + std.debug.print("test_debug_print found... calling...\n", .{}); + + // Call the function from the shared library + test_debug_print(); + + std.debug.print("called \n", .{}); +}