From cbe600603bce1bedcdfae4c327aa8215fd4105d3 Mon Sep 17 00:00:00 2001 From: Luna Date: Sun, 5 Jan 2025 15:17:03 -0300 Subject: [PATCH] remove graphicsmagick --- build.zig | 10 -------- src/include_main.zig | 61 -------------------------------------------- 2 files changed, 71 deletions(-) diff --git a/build.zig b/build.zig index e2a2ec2..dce02ac 100644 --- a/build.zig +++ b/build.zig @@ -14,12 +14,6 @@ const EXECUTABLES = .{ .{ "amv", "src/mv_main.zig" }, }; -fn addGraphicsMagick(thing: anytype) void { - thing.linkLibC(); - thing.addIncludePath(.{ .cwd_relative = "/usr/include" }); - thing.addIncludePath(.{ .cwd_relative = "/usr/include/GraphicsMagick" }); -} - pub fn build(b: *std.Build) !void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which @@ -64,8 +58,6 @@ pub fn build(b: *std.Build) !void { const run_unit_tests = b.addRunArtifact(exe_tests); - addGraphicsMagick(exe_tests); - for (mod_deps) |dep| { exe_tests.root_module.addImport(dep.name, dep.mod); } @@ -98,7 +90,6 @@ pub fn build(b: *std.Build) !void { single_exe.linkLibrary(lib); } - addGraphicsMagick(single_exe); b.installArtifact(single_exe); const hardlink_install = try b.allocator.create(CustomHardLinkStep); @@ -133,7 +124,6 @@ pub fn build(b: *std.Build) !void { // ); // // b.installArtifact(tool_exe); - // addGraphicsMagick(tool_exe); // comptime addAllTo(mod_deps, static_deps, tool_exe); // } // } diff --git a/src/include_main.zig b/src/include_main.zig index a63f04f..1045494 100644 --- a/src/include_main.zig +++ b/src/include_main.zig @@ -207,66 +207,10 @@ const TagInferrerContext = union(TagInferrer) { mime: MimeTagInferrer.RunContext, }; -pub const magick_c = @cImport({ - @cInclude("GraphicsMagick/wand/magick_wand.h"); - @cInclude("GraphicsMagick/wand/magick_wand.h"); - @cInclude("GraphicsMagick/wand/pixel_wand.h"); - @cInclude("GraphicsMagick/wand/drawing_wand.h"); - @cInclude("GraphicsMagick/magick/log.h"); -}); pub const exif_c = @cImport({ @cInclude("libexif/exif-data.h"); }); -const GraphicsMagickApi = struct { - InitializeMagick: *@TypeOf(magick_c.InitializeMagick), - DestroyImage: *@TypeOf(magick_c.DestroyImage), - DestroyImageInfo: *@TypeOf(magick_c.DestroyImageInfo), - CloneImageInfo: *@TypeOf(magick_c.CloneImageInfo), - ReadImage: *@TypeOf(magick_c.ReadImage), - GetImageAttribute: *@TypeOf(magick_c.GetImageAttribute), - GetExceptionInfo: *@TypeOf(magick_c.GetExceptionInfo), - CatchException: *@TypeOf(magick_c.CatchException), -}; - -const CachedMagick = union(enum) { - not_found: void, - found: GraphicsMagickApi, -}; - -var cached_graphics_magick: ?CachedMagick = null; - -/// Dynamically get an object that represents the GraphicsMagick library -/// in the system. -fn getGraphicsMagickApi() ?GraphicsMagickApi { - if (cached_graphics_magick) |cached_gm_api| { - return switch (cached_gm_api) { - .found => |api| api, - .not_found => null, - }; - } - - var gm_clib = std.DynLib.open("/usr/lib/libGraphicsMagickWand.so") catch { - // TODO anon initialization crashes compiler. https://github.com/ziglang/zig/issues/19966 - cached_graphics_magick = CachedMagick{ .not_found = {} }; - return null; - }; - var buf: [256]u8 = undefined; - var fba = std.heap.FixedBufferAllocator{ .end_index = 0, .buffer = &buf }; - var alloc = fba.allocator(); - - var api: GraphicsMagickApi = undefined; - inline for (@typeInfo(GraphicsMagickApi).Struct.fields) |field_decl| { - const name_cstr = alloc.dupeZ(u8, field_decl.name) catch unreachable; - defer fba.reset(); - - @field(api, field_decl.name) = gm_clib.lookup(field_decl.type, name_cstr).?; - } - // TODO anon initialization crashes compiler. https://github.com/ziglang/zig/issues/19966 - cached_graphics_magick = CachedMagick{ .found = api }; - return api; -} - extern "c" fn strerror(errcode: c_int) [*:0]const u8; const RegexTagInferrer = struct { @@ -291,7 +235,6 @@ const RegexTagInferrer = struct { config: Config, regex_cstr: [:0]const u8, regex: libpcre.Regex, - gm_api: ?GraphicsMagickApi = null, }; pub fn consumeArguments(args_it: *std.process.ArgIterator) !TagInferrerConfig { @@ -348,13 +291,11 @@ const RegexTagInferrer = struct { pub fn init(config: TagInferrerConfig, allocator: std.mem.Allocator) !RunContext { const regex_config = config.config.regex; const regex_cstr = try allocator.dupeZ(u8, regex_config.text.?); - const gm_api = if (regex_config.use_exif) getGraphicsMagickApi().? else null; return RunContext{ .allocator = allocator, .config = regex_config, .regex_cstr = regex_cstr, .regex = try libpcre.Regex.compile(regex_cstr, .{}), - .gm_api = gm_api, }; } @@ -484,8 +425,6 @@ test "regex tag inferrer" { } test "regex tag inferrer with exif" { - if (getGraphicsMagickApi() == null) return error.SkipZigTest; - var ctx = try manage_main.makeTestContext(); defer ctx.deinit();