Add 'build-resource-generation/' from commit '05bb7e2b91130df744f12ffd62f644315b771697'

git-subtree-dir: build-resource-generation
git-subtree-mainline: 7f29076a93
git-subtree-split: 05bb7e2b91
This commit is contained in:
2025-08-04 22:14:49 -04:00
6 changed files with 138 additions and 0 deletions

3
build-resource-generation/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
/.idea/
/zig-out/
/zig-cache/

View File

@@ -0,0 +1,52 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "scratchzig",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
const gen = b.addExecutable(.{
.name = "gen",
.root_source_file = .{ .path = "src/gen.zig"},
.target = target,
.optimize = optimize,
});
const run_gen = b.addRunArtifact(gen);
const foobar_path = run_gen.addOutputFileArg("foobar");
const install_foobar = b.addInstallFileWithDir(foobar_path, .{ .custom = "res" }, "foobar");
b.getInstallStep().dependOn(&install_foobar.step);
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
// const fizzbuzz = b.addInstallFile(.{ .path = "src/fizzbuzz" } , "res");
// b.getInstallStep().dependo
// b.installFile("src/fizzbuzz", "res");
// b.addInstallFileWithDir(.{ .path = "src/fizzbuzz" }, .{ .custom = "res" }, "fizzbuzz");
const res = b.addInstallDirectory(.{ .source_dir = .{ .path = "res" }, .install_dir = .{ .prefix = {} }, .install_subdir = "res" });
b.getInstallStep().dependOn(&res.step);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
const exe_unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_exe_unit_tests.step);
}

View File

@@ -0,0 +1,13 @@
.{
.name = "scratchzig",
.version = "0.0.0",
//.minimum_zig_version = "0.11.0",
.dependencies = .{
},
.paths = .{
"",
},
}

View File

@@ -0,0 +1 @@
hello world!

View File

@@ -0,0 +1,15 @@
const std = @import("std");
pub fn main() !void {
var args = std.process.args();
_ = args.skip(); // skip exe
const out_path = args.next().?;
var cwd = std.fs.cwd();
var out = try cwd.createFile(out_path, .{});
defer out.close();
const now = std.time.timestamp();
try out.writer().print("timestamp: {d}", .{now});
}

View File

@@ -0,0 +1,54 @@
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const ally = gpa.allocator();
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
try stdout.print("Run `zig build test` to run the tests.\n", .{});
try bw.flush();
const exe_dir_path = try std.fs.selfExeDirPathAlloc(ally);
defer ally.free(exe_dir_path);
const res_dir_path = try std.fs.path.resolve(ally, &.{ exe_dir_path, "..", "res" });
defer ally.free(res_dir_path);
// std.debug.print("exe path: '{s}'\n", .{exe_dir_path});
var res_dir = try std.fs.openDirAbsolute(res_dir_path, .{});
defer res_dir.close();
{
var fb = try res_dir.openFile("fizzbuzz", .{});
defer fb.close();
const content = try fb.reader().readAllAlloc(ally, 1024);
defer ally.free(content);
std.debug.print("Read: '{s}'\n", .{content});
}
{
var stamp = try res_dir.openFile("foobar", .{});
defer stamp.close();
const content = try stamp.reader().readAllAlloc(ally, 1024);
defer ally.free(content);
std.debug.print("generated foobar: '{s}'\n", .{content});
}
}
test "simple test" {
var list = std.ArrayList(i32).init(std.testing.allocator);
defer list.deinit();
try list.append(42);
try std.testing.expectEqual(@as(i32, 42), list.pop());
}