Kode / Kinc

Modern low level game library and hardware abstraction.
http://kinc.tech
zlib License
511 stars 121 forks source link

Ability to use Clang to compile for Windows #842

Closed bluesillybeard closed 7 months ago

bluesillybeard commented 7 months ago

Is your feature request related to a problem? Please describe. I am creating a Zig binding for Kinc. As part of that binding, Kinc is compiled with Zig, which uses Clang under the hood.

The problem is, Clang does not compile the code for Windows. It gives a bunch of errors, presumably because the code is written assuming the MSBuild compiler.

Describe the solution you'd like Honestly, I don't know what a solution would look like. I don't know if this is as easy as adding some configs in Clang, or as fundamental as completely rewriting all of the Windows code.

Describe alternatives you've considered clang-cl looks like a good option, but Zig's version of Clang is statically linked into Zig itself, so that is not really an option.

It's possible to use Kmake to compile the library instead, then link the application against the library. This is undesirable for a few reasons:

  1. From what I've heard, linking binaries built with MSBuild using Clang is not a good idea
  2. that would make cross-compilation a great deal more difficult, if not outright impossible. Cross-compilation is a big deal for users of Zig.
  3. In order to refactor the binding to not rely on Kmake, this solution would have to be scrapped anyway
RobDangerous commented 7 months ago

1 is nonsense for a C-lib by the way and when you use clang on Windows you are already linking lots of msvc libs anyway.

bluesillybeard commented 7 months ago

Ok then, I'll go ahead and use --compile to make a lib, instead of using --json to load the data into Zig. It makes cross-compilation difficult but that's ok.

bluesillybeard commented 7 months ago

I found out why linking an MSVC lib with Clang doesn't work. No, it's not nonsense; and in fact is expected to happen.

Clang, as far as I know, will always link mingwex.lib, which defines a bunch of synbols, including __guard_check_icall_fptr and __guard_dispatch_icall_fptr. However, the lib from MSVC already defines those symbols so the linker errors because of duplicate symbols.

Unless you have a decent way to fix this, I'm going to have to compile it entirely with Clang.

bluesillybeard commented 7 months ago

Would you accept a pull request that refactors the code so it compiles with Clang as well as MSVC?

RobDangerous commented 7 months ago

That's not a clang problem, that's a mingw problem and you don't need to use mingw libs with clang - but maybe Zig forces that, no idea. If you need to use mingw I don't think there is much hope.

bluesillybeard commented 7 months ago

By setting the ABI to msvc, I was able to get it to work! (yay)