Support for cross-compiling on Linux#465
Support for cross-compiling on Linux#465universeindex wants to merge 30 commits intosmartcmd:mainfrom
Conversation
…ace all #inlcudes containing backslashes with forward slashes (not supported outside MSVC)
…e in miles sound system, probably the abi blowing up
|
P.S. I tested building on Windows, which still works fine, so hopefully there shouldn't be any issues |
|
Most commits made to upstream will probably conflict with those by overwriting the includes I changed back with backslashes, but I'll be fixing those until this is merged |
|
Yes, I will be very happy to have clang-cl support and cross compilation support. Actually, clang-cl will be a test site for |
|
Have you tested it compiling with MSVC? Both msbuild and cmake. I hope this doesn't break the MSVC compilation. |
|
I tested CMake w/ visual studio generator on Windows (with MSVC) which worked fine, but I haven't tried the normal .sln yet. I can do that now, but it might be a minute, i'm working on a really slow machine currently |
|
works fine, compiles and runs w/ visual studio build ^ |
|
Could you please tell, aside from |
|
I did rewrite Minecraft.Client/iob_shim.asm in C++ as IobShim.cpp because I couldn't get MASM to work under Linux, but that's it aside from the includes I believe. |
|
can confirm does compile on linux w/ cmake well done :) |
|
That asm file wasn't really an asm thing rather a MSVC linker hack and it appears we don't actually need that at all. |
cmake/LinuxCrosscompile.cmake
Outdated
| set(CMAKE_C_COMPILER_FRONTEND_VARIANT MSVC) | ||
| set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MSVC) | ||
|
|
||
| add_compile_options(/winsysroot /opt/msvc --target=x86_64-pc-windows-msvc -fms-compatibility -fms-extensions -fdelayed-template-parsing) |
There was a problem hiding this comment.
the cmake file assumes /opt/msvc whereas https://github.com/mstorsjo/msvc-wine recommends ~/my_msvc/opt/msvc
just a simple issue as you can syslink or run the msvc-wine installer as root & install to /opt/msvc
There was a problem hiding this comment.
oh, good catch, i think i might set it to CMAKE_BINARY_DIR/msvc so users can symlink one instead, or if theres a way to set options of a toolchain file that would be best
will change soon, not home atm
There was a problem hiding this comment.
msvc-wine sets itself in the path directory (although the user has to set this up manually through something like .zshrc)
could do something like
whereis msbuild
to determine the directory?
if it isn't set as CMAKE_MSVC_DIR
There was a problem hiding this comment.
opened pr on your fork that fixes this & a clang error universeindex#1
|
I think |
…ot with explicit -imsvc paths
|
|
will need someone to test compiling on windows however |
Forgot about it that, as I am used to x86 development. Uncool, Microsoft. Anyway, maybe conditionally use the |
I don't see a successful run of the ci on your repo you should do that just to be sure |
It seems to fail |
|
You might wanna look at this which does build (goes further at least) |
|
oh, thanks, do you mind if i just use this? |
Sure xD (wait for it to get a successfull build tho) |
|
oh nevermind i just set the wrong toolchain file, lol |
|
Yea also gets stuck on yours after that error I'll try to look into it tomorrow but no promises |
|
it seems to be compiling without errors, but has been frozen for almost an hour now... not sure if this means it broke or not |
|
There are some mentions of the I tried removing Here's the build script I'm using: https://gist.github.com/carterisonline/42a647b01beb93738fa8f8f278459d45 |
|
that's probably referring to the actual msvc running under wine, in this case msvc-wine is only providing the windows sdk and clang is the actual compiler, so i doubt it |
|
Yeah MSVC is weird and I'm thinking that |
|
Note: if |
|
Yeah waiting for this to compile with only one thread made me seriously consider switching to Windows. I can't wish that on anybody |
|
Anybody got a successful run? or know what to change? |
|
Tried with fedora, same result https://github.com/Twig6943/MinecraftConsoles/actions/runs/22802811436/job/66147070210 |
|
What are the odds theres something wrong with |
|
based, if that mean i can cross-compile on my linux system without a vm that could awesome, as i could make changes easily :). |
|
let it all sink in right now please |
I removed everything in it besides |
|
I feel like this PR is having some scope creep, maybe we should just move the workflow stuff to its own PR? |
Makes sense to me as nobody has an idea as to how to fix the workflow as of writing this, and this is sort of a blocker for this pr as the .yml is included. |
|
I'll just delete it for now then |
|
there are build errors right now, fixing them |
|
I don't know wtf happened, but there are huge amounts of build errors happening now, give me a bit to fix those |





Description
I've implemented support for cross-compiling a Windows build on a Linux host using clang-cl. I added a toolchain file at cmake/LinuxCrosscompile.cmake that achieves this. I also modified many source files to not use backslashes in include statements (which error with clang-cl) and use case-sensitive paths (many Linux filesystems are case-sensitive, unlike NTFS, which causes errors). I avoided changing actual functionality as much as possible, so I hope this isn't too intrusive. Additionally I apologize for the messy commit messages, I hope this isn't a big issue, I have detailed all of the changes I made here.
Changes
Include statements use forward slashes instead of backslashes
Include statements reference files with correct capitalization
Added a CMake toolchain file for using clang-cl on Linux
Minecraft.Client/Xbox/MinecraftWindows.rc is not compiled on Linux, this causes errors otherwise, as it can't find the windows SDK and I am unsure how to specify the location here.
I also added documentation for building on Linux.
Previous Behavior
Running CMake on Linux would throw a hardcoded error stating that Linux isn't supported. When removed, and clang-cl is set to be used, many errors occur due to include paths using backslashes and inconsistent capitalization. The only way to build and run on Linux before is to use a Windows VM, and there is no way to get proper code completion on a Linux IDE.
Root Cause
Backslashes in include paths are supported on Windows, but not other systems, and NTFS is case-insensitive, so include paths do not have to match capitalization, also not on other systems.
New Behavior
The game now compiles and outputs a Windows binary on Linux using clang-cl.
Fix Implementation
See changes section