mach: build: Install folders containing resources as a build step

This commit is contained in:
iddev5 2022-06-19 23:13:47 +05:30 committed by Stephen Gutekanst
parent fa5afee5bc
commit 6b64c865bf

View file

@ -58,6 +58,7 @@ pub fn build(b: *std.build.Builder) void {
.src = "examples/" ++ example.name ++ "/main.zig", .src = "examples/" ++ example.name ++ "/main.zig",
.target = target, .target = target,
.deps = example.packages, .deps = example.packages,
.res_dirs = &.{thisDir() ++ "/examples/assets"},
}, },
); );
example_app.setBuildMode(mode); example_app.setBuildMode(mode);
@ -133,12 +134,14 @@ pub const App = struct {
b: *std.build.Builder, b: *std.build.Builder,
name: []const u8, name: []const u8,
step: *std.build.LibExeObjStep, step: *std.build.LibExeObjStep,
res_dirs: ?[]const []const u8,
pub fn init(b: *std.build.Builder, options: struct { pub fn init(b: *std.build.Builder, options: struct {
name: []const u8, name: []const u8,
src: []const u8, src: []const u8,
target: std.zig.CrossTarget, target: std.zig.CrossTarget,
deps: ?[]const Pkg = null, deps: ?[]const Pkg = null,
res_dirs: ?[]const []const u8 = null,
}) App { }) App {
const mach_deps: []const Pkg = &.{ glfw.pkg, gpu.pkg, pkg }; const mach_deps: []const Pkg = &.{ glfw.pkg, gpu.pkg, pkg };
const deps = if (options.deps) |app_deps| const deps = if (options.deps) |app_deps|
@ -175,6 +178,7 @@ pub const App = struct {
.b = b, .b = b,
.step = step, .step = step,
.name = options.name, .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, ""); run_html_generator.cwd = app.b.getInstallPath(web_install_dir, "");
app.getInstallStep().?.step.dependOn(&run_html_generator.step); 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 { pub fn link(app: *const App, options: Options) void {