add flexilib-interface module for flexilib client builds
All checks were successful
AWS-Zig Build / build-zig-0.11.0-amd64-host (push) Successful in 1m28s

This commit is contained in:
Emil Lerch 2023-10-05 15:31:11 -07:00
parent 30d27e3002
commit e5396cb0e5
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -6,9 +6,17 @@ const builtin = @import("builtin");
/// For flexilib, we will need the main file to have a pub fn named /// 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 /// "handler". If it is not called that, a pub const handler = ... can be
/// used instead /// 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"); 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(.{ // const exe = b.addExecutable(.{
// .name = "universal-lambda-example", // .name = "universal-lambda-example",
// // In this case the main source file is merely a path, however, in more // // 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(.{ const lib = b.addSharedLibrary(.{
.name = exe.name, .name = cs.name,
.root_source_file = .{ .path = b.pathJoin(&[_][]const u8{ build_root_src, "flexilib.zig" }) }, .root_source_file = .{ .path = b.pathJoin(&[_][]const u8{ build_root_src, "flexilib.zig" }) },
.target = exe.target, .target = cs.target,
.optimize = exe.optimize, .optimize = cs.optimize,
}); });
// We will not free this, as the rest of the build system will use it. // 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 // 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 module_dependencies = try b.allocator.alloc(std.Build.ModuleDependency, cs.modules.count());
var iterator = exe.modules.iterator(); var iterator = cs.modules.iterator();
var i: usize = 0; var i: usize = 0;
while (iterator.next()) |entry| : (i += 1) { 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", .{ lib.addAnonymousModule("flexilib_handler", .{
// Source file can be anywhere on disk, does not need to be a subdirectory // 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, .dependencies = module_dependencies,
}); });
package_step.dependOn(&b.addInstallArtifact(lib, .{}).step); package_step.dependOn(&b.addInstallArtifact(lib, .{}).step);