what the helly

This commit is contained in:
Peterino2 2026-01-03 02:06:43 -08:00
commit 9e57efe13c
4 changed files with 65 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.zig-cache/
zig-out/

38
build.zig Normal file
View File

@ -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);
}

5
lib.zig Normal file
View File

@ -0,0 +1,5 @@
const std = @import("std");
pub export fn test_debug_print() callconv(.c) void {
std.debug.print("hi, this crashes\n", .{});
}

20
main.zig Normal file
View File

@ -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", .{});
}