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("GraphicsMagick");
step.addIncludePath("/usr/include/GraphicsMagick");
step.addIncludePath("/usr/include");
step.addIncludePath(.{ .path = "/usr/include/GraphicsMagick" });
step.addIncludePath(.{ .path = "/usr/include" });
const possible_lilv_include_dirs = [_][]const u8{
"/usr/include/lilv-0/lilv",
@ -32,7 +32,7 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
found_any_lilv = true;
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) {
@ -42,22 +42,34 @@ fn setupLinks(step: *builds.LibExeObjStep) void {
}
pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("scritcher", "src/main.zig");
exe.setBuildMode(mode);
exe.install();
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "scritcher",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
setupLinks(exe);
b.installArtifact(exe);
const test_obj_step = b.addTest("src/main.zig");
setupLinks(test_obj_step);
const run_cmd = b.addRunArtifact(exe);
const run_cmd = exe.run();
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 test_step = b.step("test", "Run tests");
test_step.dependOn(&test_obj_step.step);
const test_step = b.addTest(.{
.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,
fmt: *c.SF_INFO,
) !*c.SNDFILE {
var cstr_path = try std.cstr.addNullByte(allocator, path);
var cstr_path = try allocator.dupeZ(u8, path);
defer allocator.free(cstr_path);
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
// the value for the port there.
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);
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();
}
@ -537,7 +538,7 @@ pub const Lang = struct {
fn parseCommandArguments(
self: *@This(),
comptime command_struct: type,
tok_it: *std.mem.SplitIterator(u8),
tok_it: *std.mem.SplitIterator(u8, .sequence),
commands: *CommandList,
) !void {
// 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;
// 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();
if (cmd_opt == null) {

View File

@ -38,7 +38,7 @@ fn magickLoad(image: *Image) !MagickContext {
var mctx = try MagickContext.init();
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);
log.debug("loading '{s}'", .{curpath});
@ -53,7 +53,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
const allocator = image.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);
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).?;
var heap_cmd = try allocator.create(CommandStruct);
@memcpy(
@as([*]u8, @ptrCast(&heap_cmd)),
@as([*]const u8, @ptrCast(&casted)),
@sizeOf(CommandStruct),
);
heap_cmd.* = casted.*;
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 {
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);
var world: *c.LilvWorld = c.lilv_world_new().?;

View File

@ -152,7 +152,7 @@ pub const Runner = struct {
while (try it.next()) |entry| {
switch (entry.kind) {
.File => blk: {
.file => blk: {
if (!std.mem.startsWith(u8, entry.name, starts_with)) break :blk {};
// 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).?;
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);
try magick.runRotate(image, rotate_cmd.deg, c_bgfill);