Created
September 2, 2023 17:14
-
-
Save tauoverpi/84a5320cf043186c6f3161c38612bc71 to your computer and use it in GitHub Desktop.
Using the levy game project as a library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
pub fn build(b: *std.Build) void { | |
const target = b.standardTargetOptions(.{}); | |
const optimize = b.standardOptimizeOption(.{}); | |
const exe = b.addExecutable(.{ | |
.name = "hook", | |
.root_source_file = .{ .path = "main.zig" }, | |
.target = target, | |
.optimize = optimize, | |
}); | |
exe.addModule("levy-git-hooks", b.dependency("levy", .{}).module("levy-git-hooks")); | |
b.installArtifact(exe); | |
const run_cmd = b.addRunArtifact(exe); | |
run_cmd.step.dependOn(b.getInstallStep()); | |
if (b.args) |args| { | |
run_cmd.addArgs(args); | |
} | |
const run_step = b.step("run", "Run the app"); | |
run_step.dependOn(&run_cmd.step); | |
const unit_tests = b.addTest(.{ | |
.root_source_file = .{ .path = "main.zig" }, | |
.target = target, | |
.optimize = optimize, | |
}); | |
const run_unit_tests = b.addRunArtifact(unit_tests); | |
const test_step = b.step("test", "Run unit tests"); | |
test_step.dependOn(&run_unit_tests.step); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.{ | |
.name = "git-hook-example", | |
.version = "0.1.0", | |
.dependencies = .{ | |
.levy = .{ | |
.url = "https://git.sr.ht/~tauoverpi/levy/archive/57f3a887f48f2462bf7a8eafca560c1198886d50.tar.gz", | |
.hash = "1220f55aa4b101d8987a0d44790ee266f9d8630b5484d1181ac568b0bdc1bf67d8aa", | |
}, | |
}, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const Hooks = @import("levy-git-hooks").GitHooks(void, error{No}); | |
const Allocator = std.mem.Allocator; | |
const config: Hooks = .{ | |
.pre_commit = struct { | |
fn hook(_: Allocator, _: void) !void { | |
return error.No; // today is not a work day | |
} | |
}.hook, | |
}; | |
pub fn main() !void { | |
try config.dispatch(std.heap.page_allocator, std.fs.cwd(), {}, std.os.argv); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment