Support for cross-compiling on Linux#465
Support for cross-compiling on Linux#465universeindex wants to merge 25 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've been trying for ages and I genuinely have no clue how to add a clang build option to msbuild, really sorry. it works fine in cmake but visual studio just isn't playing along. if someone else can figure it out thats great, but I give up |
|
Install Clang-cl with visual studio installer, add new configuration for a project, call it |
|
I get that, but my issue is that it's just not creating a new configuration. I select new and click ok then nothing happens, doesn't add the config at all |
|
You can just use this: https://github.com/mstorsjo/msvc-wine Then add it to PATH: And then you can just use the Toolchain file and everything should work perfectly. This also adds a working |
|
Folks say msvc-wine doesn't work for them. |
... this is what this pull request is doing... 😭😭😭 |
|
Huh? It's working perfectly fine for me. This is exactly how I got this to work on my system. |
they need lld installed which should probably be mentioned |
Is there a script included that already does this? If so then ignore me I guess lol |
|
that's the issue i had at the very least before it started working, an ambiguous error due to no lld linker |
Yes Let me just create a fresh Debian Trixie Distrobox to figure out everything that is required. |
there's no script to install but it's mentioned in compile.md within the project, might be a good idea to use something like docker / nix so we can containerise the actual building so it works no matter what system (macos, linux, windows, etc) |
i tested with arch, all that's required is base-devel, cmake, gcc, ninja & lld from my knowledge (and obviously msvc-wine & wine) |
|
Alright I'll put together a Dockerfile real quick then. |
|
There are Dockerfiles already in the repo lol Either way in case anyone can use it, here's a script I wrote for testing purposes: # Fresh Debian Trixie install
dpkg --add-architecture i386
apt update
apt install wine wine32 wine64 msitools git python3 cmake ninja-build lld-19 llvm-19 clang-19
DISPLAY= wineboot
# MSVC install
(
git clone https://github.com/mstorsjo/msvc-wine.git
cd msvc-wine
git checkout 32b504c63b869681cda6824a20e30b74cb718432
mkdir /opt/msvc
./vsdownload.py --dest /opt/msvc --accept-license
./install.sh /opt/msvc
ln -s /usr/bin/clang-cl{-19,}
ln -s /usr/bin/lld-link{-19,}
)
# MSVC setup
export PATH="/opt/msvc/bin/x64:$PATH"
# Project build
(
git clone https://github.com/universeindex/MinecraftConsoles.git --depth 1 --recursive
cd MinecraftConsoles
mkdir build
cd build
cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=../cmake/LinuxCrosscompile.cmake
ninja
) |
|
I might try to get this to build using clang-cl with mingw 🤔 |
|
tried this, but i started to get many more strange errors, i think lce depends on msvc specific stdlib stuff |
|
Yeah, fuck this codebase lol... using backslashes in include paths is already insane enough |
|
God only knows |
|
Would it be reasonable to split this into multiple PRs? Converting backslashes to forward slashes and fixing the casing issues in |
|
good idea actually, didnt think of that |
|
Okay, screw the Visual Studio solution file, I can't add new configuration either. Let's add clang-cl as cmake only for now. Resolve the branch conflicts and imma merge this one. |
|
We love microslop <3 |
|
I can make a new branch and PR with the |
|
looks like void is ready to merge this existing one once i fix up merge conflicts though, so maybe not, sorry |
this script made me possible to also compile this :3 |
|
Since there's no updates, I fixed the conflicts and got this to work in one of the latest commit of upstream and can merge automatically as of speaking, PR the PR? https://github.com/AE70/MinecraftConsoles/tree/pr465 . |
it doesnt seem to have audio but that could be a upstream issue |
not upstream issue, need to fix that. |
|
was it one of my commits that broke audio? i never touched that, last i checked it was working, weird |

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