From ce99300513dff19fade309ca4881fc45517424f7 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Tue, 24 Mar 2026 17:12:18 +0100 Subject: [PATCH] build: fix freetype C enum signedness for MSVC MSVC translates C enums as signed int, while GCC/Clang uses unsigned int. The freetype Zig bindings hardcode c_uint for enum backing types, causing type mismatches when compiling with MSVC target. Fix by adding @intCast at call sites where enum values are passed to C functions, and @bitCast for the glyph format tag extraction where bit-shift operations require unsigned integers. Co-Authored-By: Claude Opus 4.6 (1M context) --- pkg/freetype/face.zig | 4 ++-- src/font/face/freetype.zig | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/freetype/face.zig b/pkg/freetype/face.zig index d4f74b7ee..cd949e357 100644 --- a/pkg/freetype/face.zig +++ b/pkg/freetype/face.zig @@ -52,7 +52,7 @@ pub const Face = struct { /// Select a given charmap by its encoding tag (as listed in freetype.h). pub fn selectCharmap(self: Face, encoding: Encoding) Error!void { - return intToError(c.FT_Select_Charmap(self.handle, @intFromEnum(encoding))); + return intToError(c.FT_Select_Charmap(self.handle, @intCast(@intFromEnum(encoding)))); } /// Call FT_Request_Size to request the nominal size (in points). @@ -99,7 +99,7 @@ pub const Face = struct { pub fn renderGlyph(self: Face, render_mode: RenderMode) Error!void { return intToError(c.FT_Render_Glyph( self.handle.*.glyph, - @intFromEnum(render_mode), + @intCast(@intFromEnum(render_mode)), )); } diff --git a/src/font/face/freetype.zig b/src/font/face/freetype.zig index 827753254..528f72d52 100644 --- a/src/font/face/freetype.zig +++ b/src/font/face/freetype.zig @@ -679,13 +679,16 @@ pub const Face = struct { else => |f| { // Glyph formats are tags, so we can // output a semi-readable error here. + // Use @bitCast to u32 because MSVC translates C enums + // as signed int, while GCC/Clang uses unsigned int. + const tag: u32 = @bitCast(f); log.err( "Can't render glyph with unsupported glyph format \"{s}\"", .{[4]u8{ - @truncate(f >> 24), - @truncate(f >> 16), - @truncate(f >> 8), - @truncate(f >> 0), + @truncate(tag >> 24), + @truncate(tag >> 16), + @truncate(tag >> 8), + @truncate(tag >> 0), }}, ); return error.UnsupportedGlyphFormat;