Skip to content

Commit

Permalink
0.12.0
Browse files Browse the repository at this point in the history
svercl committed May 25, 2024
1 parent 33718d0 commit eb1adcb
Showing 3 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ zshim is the [`shim`](https://github.com/71/scoop-better-shimexe/).

Requirements:

- [Zig 0.11.0-dev.1568+c9b957c93](https://ziglang.org/)
- [Zig 0.12.0](https://ziglang.org/)
- git

Once you have those, then it's as easy as:
18 changes: 7 additions & 11 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
const Builder = @import("std").build.Builder;
const std = @import("std");

pub fn build(b: *Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

const exe = b.addExecutable(.{
.name = "shim",
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.link_libc = true,
.single_threaded = true,
.strip = optimize != .Debug,
});
exe.linkLibC();
b.installArtifact(exe);

exe.single_threaded = true;

if (optimize != .Debug) {
exe.strip = true;
}

const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
@@ -29,7 +25,7 @@ pub fn build(b: *Builder) void {
run_step.dependOn(&run_cmd.step);

const unit_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
10 changes: 5 additions & 5 deletions src/main.zig
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ test "pathWithExtension" {
try std.testing.expectEqualStrings("mem.exe", example);
}

pub fn main() anyerror!void {
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
@@ -67,7 +67,7 @@ pub fn main() anyerror!void {
var buffered_reader = std.io.bufferedReader(shim_file.reader());
const reader = buffered_reader.reader();

try readShim(reader, &cfg);
try readShim(reader.any(), &cfg);
}

// Arguments sent to the child process
@@ -109,7 +109,7 @@ const whitespace_with_quotes = std.ascii.whitespace ++ .{'"'};
///
/// The file is (usually) multiple key-value pairs separated by a single '=', and
/// must contain at least a "path", although this is up to the caller to uphold.
fn readShim(reader: anytype, into: *std.BufMap) !void {
fn readShim(reader: std.io.AnyReader, into: *std.BufMap) !void {
// Go through the shim file and collect key-value pairs
var line_buf: [1024]u8 = undefined;
while (try reader.readUntilDelimiterOrEof(&line_buf, '\n')) |line| {
@@ -131,7 +131,7 @@ test "parsing valid shim" {
var cfg = std.BufMap.init(std.testing.allocator);
defer cfg.deinit();

_ = try readShim(reader, &cfg);
_ = try readShim(reader.any(), &cfg);

try std.testing.expectEqualStrings("C:/Program Files/Git/cmd/git.exe", cfg.get("path") orelse "");
try std.testing.expectEqualStrings("status", cfg.get("args") orelse "");
@@ -147,7 +147,7 @@ test "parsing valid shim (new style)" {
var cfg = std.BufMap.init(std.testing.allocator);
defer cfg.deinit();

_ = try readShim(reader, &cfg);
_ = try readShim(reader.any(), &cfg);

try std.testing.expectEqualStrings("C:\\Program Files\\Git\\cmd\\git.exe", cfg.get("path") orelse "");
try std.testing.expectEqualStrings("status", cfg.get("args") orelse "");

0 comments on commit eb1adcb

Please sign in to comment.