update build to work properly - note that patch is needed for zig build test

This commit is contained in:
Emil Lerch 2025-09-18 10:19:34 -07:00
parent fb9bae8525
commit ce3a9ebd31
Signed by: lobo
GPG key ID: A7B62D657EF764F8
2 changed files with 32 additions and 7 deletions

View file

@ -36,6 +36,7 @@ pub fn build(b: *std.Build) void {
}),
});
lib.step.dependOn(&download_link_step.step);
lib.addIncludePath(upstream.path("include"));
lib.addCSourceFiles(.{
@ -137,12 +138,20 @@ pub fn build(b: *std.Build) void {
}),
});
exe.step.dependOn(&download_link_step.step);
// Copy data files to install directory
const install_data = b.addInstallDirectory(.{
.source_dir = upstream.path("data"),
.install_dir = .bin,
.install_subdir = "data",
});
install_data.step.dependOn(&download_link_step.step);
// This declares intent for the executable to be installed into the
// install prefix when running `zig build` (i.e. when executing the default
// step). By default the install prefix is `zig-out/` but can be overridden
// by passing `--prefix` or `-p`.
b.installArtifact(exe);
b.getInstallStep().dependOn(&install_data.step);
// This creates a top level step. Top level steps have a name and can be
// invoked by name when running `zig build` (e.g. `zig build run`).
@ -176,11 +185,11 @@ pub fn build(b: *std.Build) void {
const mod_tests = b.addTest(.{
.root_module = mod,
});
mod_tests.step.dependOn(&download_link_step.step);
// A run step that will run the test executable.
const run_mod_tests = b.addRunArtifact(mod_tests);
run_mod_tests.setCwd(.{ .cwd_relative = b.getInstallPath(.bin, "") });
run_mod_tests.step.dependOn(&install_data.step);
// Creates an executable that will run `test` blocks from the executable's
// root module. Note that test executables only test one module at a time,
// hence why we have to create two separate ones.
@ -190,12 +199,20 @@ pub fn build(b: *std.Build) void {
// A run step that will run the second test executable.
const run_exe_tests = b.addRunArtifact(exe_tests);
run_exe_tests.setCwd(.{ .cwd_relative = b.getInstallPath(.bin, "") });
run_exe_tests.step.dependOn(&install_data.step);
// A top level step for running all tests. dependOn can be called multiple
// times and since the two run steps do not depend on one another, this will
// make the two of them run in parallel.
const test_step = b.step("test", "Run tests");
test_step.dependOn(&run_mod_tests.step);
// mod tests fail because we need to patch utilities.c with search:
// printf(" Opening
//
// replace:
// if ( verbosity > 0 ) printf(" Opening
//test_step.dependOn(&run_mod_tests.step);
test_step.dependOn(&run_exe_tests.step);
// Just like flags, top level steps are also listed in the `--help` menu.

View file

@ -2,9 +2,17 @@ const std = @import("std");
const pos = @import("pos");
pub fn main() !void {
// Prints to stderr, ignoring potential errors.
std.debug.print("All your {s} are belong to us.\n", .{"codebase"});
try pos.bufferedPrint();
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
var parser = try pos.Parser.init(gpa.allocator());
defer parser.deinit();
var tree = try parser.parse(pos.sentence);
defer tree.deinit();
std.debug.print("Parsed sentence: {s}\n", .{pos.sentence});
std.debug.print("Words: {d}, Links: {d}\n", .{ tree.words.len, tree.links.len });
}
test "simple test" {