Compare commits

...

2 commits

Author SHA1 Message Date
43dad638f2 use stage1 2022-10-08 15:06:14 -03:00
ef6c68705d port to latest zig 2022-10-08 15:05:15 -03:00
3 changed files with 18 additions and 14 deletions

View file

@ -12,8 +12,8 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
step.linkSystemLibrary("GraphicsMagickWand"); step.linkSystemLibrary("GraphicsMagickWand");
step.linkSystemLibrary("GraphicsMagick"); step.linkSystemLibrary("GraphicsMagick");
step.addIncludeDir("/usr/include/GraphicsMagick"); step.addIncludePath("/usr/include/GraphicsMagick");
step.addIncludeDir("/usr/include"); step.addIncludePath("/usr/include");
const possible_lilv_include_dirs = [_][]const u8{ const possible_lilv_include_dirs = [_][]const u8{
"/usr/include/lilv-0/lilv", "/usr/include/lilv-0/lilv",
@ -24,7 +24,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
for (possible_lilv_include_dirs) |possible_lilv_dir| { for (possible_lilv_include_dirs) |possible_lilv_dir| {
var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| { var possible_dir = std.fs.cwd().openDir(possible_lilv_dir, .{}) catch |err| {
std.debug.print("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, err }); std.debug.print("possible lilv {s} fail: {s}\n", .{ possible_lilv_dir, @errorName(err) });
continue; continue;
}; };
@ -32,7 +32,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
found_any_lilv = true; found_any_lilv = true;
std.debug.print("found lilv at '{s}'\n", .{possible_lilv_dir}); std.debug.print("found lilv at '{s}'\n", .{possible_lilv_dir});
step.addIncludeDir(possible_lilv_dir); step.addIncludePath(possible_lilv_dir);
} }
if (!found_any_lilv) { if (!found_any_lilv) {
@ -45,6 +45,7 @@ pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions(); const mode = b.standardReleaseOptions();
const exe = b.addExecutable("scritcher", "src/main.zig"); const exe = b.addExecutable("scritcher", "src/main.zig");
exe.setBuildMode(mode); exe.setBuildMode(mode);
exe.use_stage1 = true;
exe.install(); exe.install();
setupLinks(exe); setupLinks(exe);

View file

@ -94,7 +94,7 @@ pub const Command = struct {
rotate, rotate,
}; };
pub fn tagToType(tag: Tag) type { pub fn tagToType(comptime tag: Tag) type {
return switch (tag) { return switch (tag) {
.noop => Noop, .noop => Noop,
.load => Load, .load => Load,
@ -147,7 +147,7 @@ pub const Command = struct {
} }
pub fn print(base: *const @This()) void { pub fn print(base: *const @This()) void {
log.debug("tag: {s}\n", .{base.tag}); log.debug("tag: {}\n", .{base.tag});
} }
pub const Noop = struct { pub const Noop = struct {
@ -529,9 +529,9 @@ pub const Lang = struct {
} }
fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void { fn doError(self: *Lang, comptime fmt: []const u8, args: anytype) void {
log.err("ERROR! at line {}: ", .{self.line}); log.warn("ERROR! at line {}: ", .{self.line});
log.err(fmt, args); log.warn(fmt, args);
log.err("\n", .{}); log.warn("\n", .{});
self.has_error = true; self.has_error = true;
} }
@ -622,7 +622,7 @@ pub const Lang = struct {
cmd.base.tag = command_struct.base_tag; cmd.base.tag = command_struct.base_tag;
const command = cmd.base.cast(command_struct).?; const command = cmd.base.cast(command_struct).?;
log.debug("cmd: {s}\n", .{command}); log.debug("cmd: {}\n", .{command});
} }
pub fn parse(self: *Lang, data: []const u8) !CommandList { pub fn parse(self: *Lang, data: []const u8) !CommandList {

View file

@ -57,6 +57,7 @@ pub const Runner = struct {
} }
fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 { fn resolveArg(self: *Runner, load_path: []const u8) ![]const u8 {
std.debug.assert(load_path.len > 0);
if (load_path[0] == ':') { if (load_path[0] == ':') {
// parse the index from 1 to end // parse the index from 1 to end
var index = try std.fmt.parseInt(usize, load_path[1..], 10); var index = try std.fmt.parseInt(usize, load_path[1..], 10);
@ -131,7 +132,7 @@ pub const Runner = struct {
const basename = std.fs.path.basename(image.path); const basename = std.fs.path.basename(image.path);
const dirname = std.fs.path.dirname(image.path).?; const dirname = std.fs.path.dirname(image.path).?;
var dir = try std.fs.cwd().openDir(dirname, .{ .iterate = true }); var dir = try std.fs.cwd().openIterableDir(dirname, .{});
defer dir.close(); defer dir.close();
const period_idx = std.mem.lastIndexOf(u8, basename, ".").?; const period_idx = std.mem.lastIndexOf(u8, basename, ".").?;
@ -199,11 +200,11 @@ pub const Runner = struct {
defer self.allocator.free(out_path); defer self.allocator.free(out_path);
try image.saveTo(out_path); try image.saveTo(out_path);
var proc = try std.ChildProcess.init( var proc = std.ChildProcess.init(
&[_][]const u8{ runqs.program, out_path }, &[_][]const u8{ runqs.program, out_path },
self.allocator, self.allocator,
); );
defer proc.deinit(); //defer proc.deinit();
log.debug("running '{s} {s}'\n", .{ runqs.program, out_path }); log.debug("running '{s} {s}'\n", .{ runqs.program, out_path });
_ = try proc.spawnAndWait(); _ = try proc.spawnAndWait();
@ -331,7 +332,9 @@ test "running noop" {
defer cmds.deinit(); defer cmds.deinit();
var command = lang.Command{ .tag = .noop }; var command = lang.Command{ .tag = .noop };
var noop = lang.Command.Noop{ .base = command };
var noop = try allocator.create(lang.Command.Noop);
noop.* = lang.Command.Noop{ .base = command };
try cmds.append(&noop.base); try cmds.append(&noop.base);
var runner = Runner.init(allocator, false); var runner = Runner.init(allocator, false);