ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.36k stars 2.51k forks source link

zig rc: UTF-16 (LE) encoding is not supported #17557

Open kassane opened 12 months ago

kassane commented 12 months ago

Zig Version

0.12.0-dev.935+a1e0b9979

Steps to Reproduce and Observed Behavior

cc: @squeek502

repo test: https://github.com/kassane/wolfssl (forked w/ zig build [v0.12.0-dev])

Tried add

lib.addWin32ResourceFile(.{
        .file = .{ .path = "wolfssl.rc" },
    });

Commands: zig build -DTests -DShared -Dtarget=native-windows (my host is Linux)

error: error(compilation): clang preprocessor failed with stderr:
fatal error: UTF-16 (LE) byte order mark detected in '/home/kassane/Documents/wolfssl/wolfssl.rc', but encoding is not supported

lib.addWin32ResourceFile(.{
        .file = .{ .path = "wolfssl.rc" },
        .flags = &.{"/c1200"},
    });
/home/kassane/Documents/wolfssl/wolfssl.rc:1:1: error: invalid command line option(s)
error: unsupported code page: utf16 (id=1200)

Expected Behavior

Works, equal to standalone test: https://github.com/ziglang/zig/blob/7b9165b37576ed4c4962c0ad2afb62921524aa08/test/standalone/windows_resources/build.zig#L28-L35

squeek502 commented 12 months ago

This is a known limitation due to the clang preprocessor not supporting UTF-16 files (and AFAIK no preprocessor outside of MSVC supports UTF-16 files).

The relevant resinator issue is https://github.com/squeek502/resinator/issues/5

Since you're forking wolfssl, my suggestion would be to convert wolfssl.rc to UTF-8 (and resource.h too if necessary). This could actually be done via build.zig if you don't want to touch the files themselves (generate a converted file and pass the generated file to addWin32ResourceFile). There's no reason beyond Visual Studio generating the .rc file as UTF-16 that it needs to be UTF-16 (there's not even any non-ASCII characters in it).

I've also opened https://github.com/squeek502/resinator/issues/6 but it wouldn't be a viable workaround for this .rc file.