adding mic headers, switching to runtime dynamic libloading

This commit is contained in:
2026-07-01 20:48:52 +02:00
parent 9d99ef63bf
commit f46bd2a058
8 changed files with 2695 additions and 251 deletions
+11 -39
View File
@@ -6,48 +6,32 @@ pub fn build(b: *std.Build) void {
const use_llvm = b.option(bool, "use-llvm", "LLVM build") orelse (b.release_mode != .off);
const miclib_include = b.option(
[]const u8,
"miclib_include",
"Directory containing miclib.h and scif.h. Example: -Dmiclib_include=/usr/local/include",
);
const c_includes = b.addTranslateC(.{
.root_source_file = b.path("third_party/miclib.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
const miclib_libdir = b.option(
[]const u8,
"miclib_libdir",
"Directory containing libmicmgmt.so/libscif.so. Example: -Dmiclib_libdir=/usr/local/lib",
);
const miclib_name = b.option(
[]const u8,
"miclib_name",
"System library name for miclib without lib/extension. Default: micmgmt",
) orelse "micmgmt";
const miclib_c = c_includes.createModule();
const module = b.addModule("miclib", .{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{.{ .name = "miclib_c", .module = miclib_c }},
});
configureMiclibModule(module, miclib_include, miclib_libdir, miclib_name);
module.linkSystemLibrary("dl", .{});
const test_module = b.createModule(.{
.root_source_file = b.path("src/lib.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.imports = &.{.{ .name = "miclib_c", .module = miclib_c }},
});
configureMiclibModule(test_module, miclib_include, miclib_libdir, miclib_name);
const c_includes = b.addTranslateC(.{
.root_source_file = b.path("src/c_includes.h"),
.target = target,
.optimize = optimize,
.link_libc = true,
});
module.addImport("miclib_c", c_includes.createModule());
test_module.linkSystemLibrary("dl", .{});
const lib_tests = b.addTest(.{
.root_module = test_module,
@@ -76,15 +60,3 @@ pub fn build(b: *std.Build) void {
const run_step = b.step("example", "Run examples/enumerate.zig");
run_step.dependOn(&run_enumerate.step);
}
fn configureMiclibModule(module: *std.Build.Module, miclib_include: ?[]const u8, miclib_libdir: ?[]const u8, miclib_name: []const u8) void {
if (miclib_include) |path|
module.addIncludePath(.{ .cwd_relative = path });
if (miclib_libdir) |path|
module.addLibraryPath(.{ .cwd_relative = path });
module.link_libcpp = true;
module.linkSystemLibrary(miclib_name, .{});
module.linkSystemLibrary("scif", .{});
}