From e5396cb0e5cb526617f7a5a68cb6ef2d111b4bb1 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Thu, 5 Oct 2023 15:31:11 -0700 Subject: [PATCH] add flexilib-interface module for flexilib client builds --- src/flexilib_build.zig | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/flexilib_build.zig b/src/flexilib_build.zig index 60fb56f..0623d6b 100644 --- a/src/flexilib_build.zig +++ b/src/flexilib_build.zig @@ -6,9 +6,17 @@ const builtin = @import("builtin"); /// For flexilib, we will need the main file to have a pub fn named /// "handler". If it is not called that, a pub const handler = ... can be /// used instead -pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile, build_root_src: []const u8) !void { +pub fn configureBuild(b: *std.build.Builder, cs: *std.Build.Step.Compile, build_root_src: []const u8) !void { const package_step = b.step("flexilib", "Create a flexilib dynamic library"); + // We'll need to add the interface module here as well + const flexilib_dep = b.dependency("flexilib", .{ + .target = cs.target, + .optimize = cs.optimize, + }); + const flexilib_module = flexilib_dep.module("flexilib-interface"); + cs.addModule("flexilib-interface", flexilib_module); + // const exe = b.addExecutable(.{ // .name = "universal-lambda-example", // // In this case the main source file is merely a path, however, in more @@ -19,16 +27,16 @@ pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile, build // }); // const lib = b.addSharedLibrary(.{ - .name = exe.name, + .name = cs.name, .root_source_file = .{ .path = b.pathJoin(&[_][]const u8{ build_root_src, "flexilib.zig" }) }, - .target = exe.target, - .optimize = exe.optimize, + .target = cs.target, + .optimize = cs.optimize, }); // We will not free this, as the rest of the build system will use it. // This should be ok because our allocator is, I believe, an arena - var module_dependencies = try b.allocator.alloc(std.Build.ModuleDependency, exe.modules.count()); - var iterator = exe.modules.iterator(); + var module_dependencies = try b.allocator.alloc(std.Build.ModuleDependency, cs.modules.count()); + var iterator = cs.modules.iterator(); var i: usize = 0; while (iterator.next()) |entry| : (i += 1) { @@ -40,7 +48,7 @@ pub fn configureBuild(b: *std.build.Builder, exe: *std.Build.Step.Compile, build } lib.addAnonymousModule("flexilib_handler", .{ // Source file can be anywhere on disk, does not need to be a subdirectory - .source_file = exe.root_src.?, + .source_file = cs.root_src.?, .dependencies = module_dependencies, }); package_step.dependOn(&b.addInstallArtifact(lib, .{}).step);