zigimg icon indicating copy to clipboard operation
zigimg copied to clipboard

Fails to compile on zig 0.14 / MacOS

Open loftafi opened this issue 10 months ago • 6 comments

I could be doing something wrong, but as far as I can tell, this library doesn't work on zig 0.14 using the most recent version.

const zigimg = @import("zigimg");

pub fn main() !void {
    var file = try std.fs.cwd().openFile("test.png", .{});
    var img = try zigimg.Image.fromFile(std.heap.smp_allocator, &file);
    defer img.deinit();
}

const std = @import("std");

Here is the error:

% zig build
install
└─ install zigimg_test
   └─ zig build-exe zigimg_test Debug native 1 errors
/Users/user/.cache/zig/p/zigimg-0.1.0-AAAAAABoEABi8SAnVIitstXxPM3Szg3PHDsOtcnhKm6s/src/formats/png/reader.zig:981:43: error: missing struct field: remap
pub const NoopAllocator = Allocator.VTable{ .alloc = undefined, .free = undefined, .resize = undefined };
                          ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Volumes/user/zig/zig-macos-aarch64-0.14.0/lib/std/mem/Allocator.zig:22:20: note: struct declared here
pub const VTable = struct {
                   ^~~~~~

Here is a minimal example project:

https://github.com/loftafi/zigimg_test

loftafi avatar Mar 17 '25 05:03 loftafi

We only support mach nominated versions, see the README: https://github.com/zigimg/zigimg?tab=readme-ov-file#install--build

mlarouche avatar Mar 18 '25 12:03 mlarouche

That compile error will be fixed once a new mach nominated Zig version is out with these changes

mlarouche avatar Mar 18 '25 12:03 mlarouche

I thought mach nominated builds were meant to include zig stable? with the mach builds filling in the gaps between stable

Khitiara avatar May 03 '25 17:05 Khitiara

All the other libraries I use have bug fixes only applied to a zig 0.14 compatible branch. So I was forced into upgrading zig 0.14. So I was forced out of using zigimg.

For people forced by other projects to track, stable, I found something called stb which can reimported as a c header, and it works great. (Well at least it works great with zig 0.14) Although it would be better if we had a native zig solution that did support zig stable.

loftafi avatar May 06 '25 08:05 loftafi

Is there a branch of this library that resolves the build issue? It looks like something to do with the changes to the memory allocator. Is there a "ready to go" branch for using this with the latest stable zig?

Is it true that it's only a few lines of code to get it working on zig 0.14? Perhaps the Noop allocator can be changed so that it is compatible with both 0.13 and 0.14? See this patch:

https://github.com/zigimg/zigimg/compare/master...AdamBrutsaert:zigimg:master

zaddok avatar May 20 '25 02:05 zaddok

I have created an updated fork using the latest zigimg, and applying the patches from the above slightly older fork.

https://github.com/loftafi/zigimg/tree/master

This solves it for me temporarily. I am not sure if I should close this ticket. I guess I should leave it open because other people are still going to stumble across the same problem.

loftafi avatar May 20 '25 03:05 loftafi

@mlarouche this should be closed now? https://github.com/zigimg/zigimg/pull/275

stone-d-chen avatar Jun 26 '25 15:06 stone-d-chen

Indeed!

mlarouche avatar Jun 26 '25 16:06 mlarouche