From 9baf2b575ef8bcc4f8cefc143b19d70937110706 Mon Sep 17 00:00:00 2001 From: Interrupt Date: Tue, 28 May 2024 12:35:01 -0700 Subject: [PATCH] Updating build file to build the Delve static library again --- build.zig | 60 ++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/build.zig b/build.zig index e68907a8..9cff0af7 100644 --- a/build.zig +++ b/build.zig @@ -31,36 +31,29 @@ pub fn build(b: *std.Build) !void { .optimize = optimize, }).module("ziglua"); - // const zmesh_pkg = zmesh.package(b, target, optimize, .{}); const zstbi_pkg = zstbi.package(b, target, optimize, .{}); - // const zaudio_pkg = zaudio.package(b, target, optimize, .{}); - const zmesh = b.dependency("zmesh", .{}); const zaudio = b.dependency("zaudio", .{}); const sokol_item = .{ .module = dep_sokol.module("sokol"), .name = "sokol" }; const ziglua_item = .{ .module = ziglua_mod, .name = "ziglua" }; const zmesh_item = .{ .module = zmesh.module("root"), .name = "zmesh" }; - // const zmesh_options_item = .{ .module = zmesh_pkg.zmesh_options, .name = "zmesh_options" }; const zstbi_item = .{ .module = zstbi_pkg.zstbi, .name = "zstbi" }; const zaudio_item = .{ .module = zaudio.module("root"), .name = "zaudio" }; const delve_module_imports = [_]ModuleImport{ sokol_item, ziglua_item, zmesh_item, - // zmesh_options_item, zstbi_item, zaudio_item, }; const link_libraries = [_]*Build.Step.Compile{ - // zmesh_pkg.zmesh_c_cpp, zmesh.artifact("zmesh"), zstbi_pkg.zstbi_c_cpp, zaudio.artifact("miniaudio"), - // zaudio_pkg.zaudio_c_cpp, }; - var build_collection: BuildCollection = .{ + const build_collection: BuildCollection = .{ .add_imports = &delve_module_imports, .link_libraries = &link_libraries, }; @@ -79,17 +72,15 @@ pub fn build(b: *std.Build) !void { delve_mod.linkLibrary(lib); } - // create new list with delve included - const app_module_imports = [_]ModuleImport{ - sokol_item, - ziglua_item, - zmesh_item, - // zmesh_options_item, - zstbi_item, - zaudio_item, - .{ .module = delve_mod, .name = "delve" }, - }; - build_collection.add_imports = &app_module_imports; + // Delve Static Library artifact + const delve_lib = b.addStaticLibrary(.{ + .target = target, + .optimize = optimize, + .name = "delve", + .root_source_file = .{ .path = "src/framework/delve.zig" }, + }); + + b.installArtifact(delve_lib); // collection of all examples const examples = [_][]const u8{ @@ -112,8 +103,8 @@ pub fn build(b: *std.Build) !void { "stresstest", }; - inline for (examples) |example_item| { - try buildExample(b, example_item, build_collection); + for (examples) |example_item| { + try buildExample(b, example_item, delve_mod, delve_lib); } // TESTS @@ -127,9 +118,10 @@ pub fn build(b: *std.Build) !void { test_step.dependOn(&exe_tests.step); } -fn buildExample(b: *std.Build, comptime example: []const u8, build_collection: BuildCollection) !void { +fn buildExample(b: *std.Build, example: []const u8, delve_module: *Build.Module, delve_lib: *Build.Step.Compile) !void { const name: []const u8 = example; - const root_source_file: []const u8 = "src/examples/" ++ example ++ ".zig"; + var root_source_buffer = [_]u8{undefined} ** 256; + const root_source_file = try std.fmt.bufPrint(&root_source_buffer, "src/examples/{s}.zig", .{name}); var app: *Build.Step.Compile = undefined; // special case handling for native vs web build @@ -149,14 +141,12 @@ fn buildExample(b: *std.Build, comptime example: []const u8, build_collection: B }); } - for (build_collection.add_imports) |build_import| { - app.root_module.addImport(build_import.name, build_import.module); - } - for (build_collection.link_libraries) |lib| { - app.linkLibrary(lib); - } + app.root_module.addImport("delve", delve_module); + app.linkLibrary(delve_lib); if (target.result.isWasm()) { + // TODO: Still sorting out WASM builds + // // create a build step which invokes the Emscripten linker // const emsdk = dep_sokol.builder.dependency("emsdk", .{}); // const link_step = try sokol.emLinkStep(b, .{ @@ -169,10 +159,16 @@ fn buildExample(b: *std.Build, comptime example: []const u8, build_collection: B // .use_filesystem = false, // .shell_file_path = dep_sokol.path("3rdparty/sokol-zig/web/shell.html").getPath(b), // }); - // // ...and a special run step to start the web build output via 'emrun' - // const run = sokol.emRunStep(b, .{ .name = example[0], .emsdk = emsdk }); + // + // const dep_sokol = b.dependency("sokol", .{ + // .target = target, + // .optimize = optimize, + // }); + // + // // // ...and a special run step to start the web build output via 'emrun' + // const run = sokol.emRunStep(b, .{ .name = example, .emsdk = emsdk }); // run.step.dependOn(&link_step.step); - + // // var option_buffer = [_]u8{undefined} ** 100; // const run_name = try std.fmt.bufPrint(&option_buffer, "run-{s}", .{name}); // var description_buffer = [_]u8{undefined} ** 200;