From 6b64c865bf9f07cf77cb9b63d4b4e6a150dd11d2 Mon Sep 17 00:00:00 2001 From: iddev5 Date: Sun, 19 Jun 2022 23:13:47 +0530 Subject: [PATCH] mach: build: Install folders containing resources as a build step --- build.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/build.zig b/build.zig index 4d99a5f1..cab5d275 100644 --- a/build.zig +++ b/build.zig @@ -58,6 +58,7 @@ pub fn build(b: *std.build.Builder) void { .src = "examples/" ++ example.name ++ "/main.zig", .target = target, .deps = example.packages, + .res_dirs = &.{thisDir() ++ "/examples/assets"}, }, ); example_app.setBuildMode(mode); @@ -133,12 +134,14 @@ pub const App = struct { b: *std.build.Builder, name: []const u8, step: *std.build.LibExeObjStep, + res_dirs: ?[]const []const u8, pub fn init(b: *std.build.Builder, options: struct { name: []const u8, src: []const u8, target: std.zig.CrossTarget, deps: ?[]const Pkg = null, + res_dirs: ?[]const []const u8 = null, }) App { const mach_deps: []const Pkg = &.{ glfw.pkg, gpu.pkg, pkg }; const deps = if (options.deps) |app_deps| @@ -175,6 +178,7 @@ pub const App = struct { .b = b, .step = step, .name = options.name, + .res_dirs = options.res_dirs, }; } @@ -204,6 +208,19 @@ pub const App = struct { run_html_generator.cwd = app.b.getInstallPath(web_install_dir, ""); app.getInstallStep().?.step.dependOn(&run_html_generator.step); } + + // Install resources + if (app.res_dirs) |res_dirs| { + for (res_dirs) |res| { + const install_res = app.b.addInstallDirectory(.{ + .source_dir = res, + .install_dir = app.getInstallStep().?.dest_dir, + .install_subdir = std.fs.path.basename(res), + .exclude_extensions = &.{}, + }); + app.getInstallStep().?.step.dependOn(&install_res.step); + } + } } pub fn link(app: *const App, options: Options) void {