build: extract example executable from default target

This commit is contained in:
torque 2024-03-07 22:33:57 -08:00
parent 5e3f2e0f91
commit cf21c48771
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
2 changed files with 13 additions and 7 deletions

View File

@ -20,14 +20,17 @@ pub fn build(b: *std.Build) void {
.optimize = optimize, .optimize = optimize,
}); });
const exe = b.addExecutable(.{ const example_step = b.step("example", "build example");
const ex_exe = b.addExecutable(.{
.name = "yamltest", .name = "yamltest",
.root_source_file = .{ .path = "src/main.zig" }, .root_source_file = .{ .path = "example/main.zig" },
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
exe.linkLibrary(libyaml); ex_exe.linkLibrary(libyaml);
exe.addModule("yaml", yaml_zig); ex_exe.addModule("yaml", yaml_zig);
b.installArtifact(exe); const install = b.addInstallArtifact(ex_exe, .{});
example_step.dependOn(&install.step);
} }

View File

@ -7,11 +7,14 @@ pub fn main() !void {
defer _ = gpa.deinit(); defer _ = gpa.deinit();
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const slurp = try std.fs.cwd().readFileAlloc( const slurp = std.fs.cwd().readFileAlloc(
allocator, allocator,
"test.yaml", "test.yaml",
1024 * 1024 * 1024, 1024 * 1024 * 1024,
); ) catch |err| {
std.debug.print("couldn't open test.yaml in the cwd\n", .{});
return err;
};
defer allocator.free(slurp); defer allocator.free(slurp);
var diag = yaml.ParseDiagnostic{ .message = "?????" }; var diag = yaml.ParseDiagnostic{ .message = "?????" };