fix for zig 0.11

This commit is contained in:
Luna 2023-08-04 21:50:59 -03:00
parent 7cc93c2976
commit c73b98a356
7 changed files with 37 additions and 28 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.addIncludePath("/usr/include/GraphicsMagick"); step.addIncludePath(.{ .path = "/usr/include/GraphicsMagick" });
step.addIncludePath("/usr/include"); step.addIncludePath(.{ .path = "/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",
@ -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.addIncludePath(possible_lilv_dir); step.addIncludePath(.{ .path = possible_lilv_dir });
} }
if (!found_any_lilv) { if (!found_any_lilv) {
@ -42,22 +42,34 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
} }
pub fn build(b: *Builder) void { pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions(); const target = b.standardTargetOptions(.{});
const exe = b.addExecutable("scritcher", "src/main.zig"); const optimize = b.standardOptimizeOption(.{});
exe.setBuildMode(mode);
exe.install();
const exe = b.addExecutable(.{
.name = "scritcher",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
setupLinks(exe); setupLinks(exe);
b.installArtifact(exe);
const test_obj_step = b.addTest("src/main.zig"); const run_cmd = b.addRunArtifact(exe);
setupLinks(test_obj_step);
const run_cmd = exe.run(); if (b.args) |args| {
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_cmd.step);
const test_step = b.step("test", "Run tests"); const test_step = b.addTest(.{
test_step.dependOn(&test_obj_step.step); .root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
setupLinks(test_step);
const run_unit_tests = b.addRunArtifact(test_step);
const test_cmd = b.step("test", "run unit tests");
test_cmd.dependOn(&run_unit_tests.step);
} }

View file

@ -26,7 +26,7 @@ pub fn sopen(
mode: i32, mode: i32,
fmt: *c.SF_INFO, fmt: *c.SF_INFO,
) !*c.SNDFILE { ) !*c.SNDFILE {
var cstr_path = try std.cstr.addNullByte(allocator, path); var cstr_path = try allocator.dupeZ(u8, path);
defer allocator.free(cstr_path); defer allocator.free(cstr_path);
var file = c.sf_open(cstr_path.ptr, mode, fmt); var file = c.sf_open(cstr_path.ptr, mode, fmt);
@ -321,7 +321,7 @@ pub const Image = struct {
// now, for each param for the plugin, we find its port, and set // now, for each param for the plugin, we find its port, and set
// the value for the port there. // the value for the port there.
for (params.items) |param| { for (params.items) |param| {
var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym); var sym_cstr = try self.allocator.dupeZ(u8, param.sym);
defer self.allocator.free(sym_cstr); defer self.allocator.free(sym_cstr);
var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr);

View file

@ -496,7 +496,8 @@ pub const CommandList = struct {
} }
} }
self.list.allocator.destroy(cmd_ptr); //TODO this is ian invalid free
//self.list.allocator.destroy(cmd_ptr);
} }
self.list.deinit(); self.list.deinit();
} }
@ -537,7 +538,7 @@ pub const Lang = struct {
fn parseCommandArguments( fn parseCommandArguments(
self: *@This(), self: *@This(),
comptime command_struct: type, comptime command_struct: type,
tok_it: *std.mem.SplitIterator(u8), tok_it: *std.mem.SplitIterator(u8, .sequence),
commands: *CommandList, commands: *CommandList,
) !void { ) !void {
// Based on the command struct fields, we can parse the arguments. // Based on the command struct fields, we can parse the arguments.
@ -638,7 +639,7 @@ pub const Lang = struct {
if (std.mem.startsWith(u8, stmt, "#")) continue; if (std.mem.startsWith(u8, stmt, "#")) continue;
// TODO better tokenizer instead of just tokenize(" ")...maybe???? // TODO better tokenizer instead of just tokenize(" ")...maybe????
var tok_it = std.mem.split(u8, stmt, " "); var tok_it = std.mem.splitSequence(u8, stmt, " ");
var cmd_opt = tok_it.next(); var cmd_opt = tok_it.next();
if (cmd_opt == null) { if (cmd_opt == null) {

View file

@ -38,7 +38,7 @@ fn magickLoad(image: *Image) !MagickContext {
var mctx = try MagickContext.init(); var mctx = try MagickContext.init();
errdefer mctx.deinit(); errdefer mctx.deinit();
var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); var curpath = try image.allocator.dupeZ(u8, image.curpath);
defer image.allocator.free(curpath); defer image.allocator.free(curpath);
log.debug("loading '{s}'", .{curpath}); log.debug("loading '{s}'", .{curpath});
@ -53,7 +53,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
const allocator = image.allocator; const allocator = image.allocator;
var tmpnam = try images.temporaryName(allocator); var tmpnam = try images.temporaryName(allocator);
var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam); var c_tmpnam = try allocator.dupeZ(u8, tmpnam);
defer allocator.free(c_tmpnam); defer allocator.free(c_tmpnam);
log.debug("\tmagick: saving to '{s}'..", .{c_tmpnam}); log.debug("\tmagick: saving to '{s}'..", .{c_tmpnam});

View file

@ -29,11 +29,7 @@ fn copyCommandToHeap(allocator: std.mem.Allocator, command: langs.Command, compt
const casted = command.cast(CommandStruct).?; const casted = command.cast(CommandStruct).?;
var heap_cmd = try allocator.create(CommandStruct); var heap_cmd = try allocator.create(CommandStruct);
@memcpy( heap_cmd.* = casted.*;
@as([*]u8, @ptrCast(&heap_cmd)),
@as([*]const u8, @ptrCast(&casted)),
@sizeOf(CommandStruct),
);
return &heap_cmd.base; return &heap_cmd.base;
} }

View file

@ -131,7 +131,7 @@ pub const RunContext = struct {
}; };
pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Context { pub fn makeContext(allocator: std.mem.Allocator, plugin_uri: []const u8) !Context {
const cstr_plugin_uri = try std.cstr.addNullByte(allocator, plugin_uri); const cstr_plugin_uri = try allocator.dupeZ(u8, plugin_uri);
defer allocator.free(cstr_plugin_uri); defer allocator.free(cstr_plugin_uri);
var world: *c.LilvWorld = c.lilv_world_new().?; var world: *c.LilvWorld = c.lilv_world_new().?;

View file

@ -152,7 +152,7 @@ pub const Runner = struct {
while (try it.next()) |entry| { while (try it.next()) |entry| {
switch (entry.kind) { switch (entry.kind) {
.File => blk: { .file => blk: {
if (!std.mem.startsWith(u8, entry.name, starts_with)) break :blk {}; if (!std.mem.startsWith(u8, entry.name, starts_with)) break :blk {};
// we want to get the N in x_gN.ext // we want to get the N in x_gN.ext
@ -215,7 +215,7 @@ pub const Runner = struct {
const rotate_cmd = cmd.cast(lang.Command.Rotate).?; const rotate_cmd = cmd.cast(lang.Command.Rotate).?;
var image = try self.getImage(); var image = try self.getImage();
var c_bgfill = try std.cstr.addNullByte(self.allocator, rotate_cmd.bgfill); var c_bgfill = try self.allocator.dupeZ(u8, rotate_cmd.bgfill);
defer self.allocator.free(c_bgfill); defer self.allocator.free(c_bgfill);
try magick.runRotate(image, rotate_cmd.deg, c_bgfill); try magick.runRotate(image, rotate_cmd.deg, c_bgfill);