Cross-compiling MTASA on Linux using msvc-wine
This guide will walk you through how you can cross-compile MTASA on Linux targeting Windows, using msvc-wine. For running the game on Linux, see Client on Linux Manual.
Setting up the environment
Section titled “Setting up the environment”Setting up msvc-wine
Section titled “Setting up msvc-wine”Clone https://github.com/mstorsjo/msvc-wine/
git clone https://github.com/mstorsjo/msvc-wine/cd msvc-wineRun ./vsdownload.py and ./install.sh to download and install the default packages plus MFC. You can specify the destination directory with the --dest option. --accept-license will skip the license agreement prompt; remove it if you wish to read through Microsoft’s license.
./vsdownload.py --dest /path/to/msvc-wine-install-dir/ --accept-license./vsdownload.py --dest /path/to/msvc-wine-install-dir/ --accept-license Microsoft.VisualStudio.Component.VC.ATLMFC./install.sh /path/to/msvc-wine-install-dir/Microsoft.VisualStudio.Component.VC.ATLMFC will lead to a missing afxres.h include error when building. Setting up the Wine preifx
Section titled “Setting up the Wine preifx”Create or use an already existing wine prefix. The rest of this guide assumes that you have your WINEPREFIX environment variable set correctly.
# Set the wine prefixexport WINEPREFIX="/path/to/wine-prefix"# If this is a new prefix, initialize itwineboot -iMake sure you have (the correct version of) .NET SDK installed. If you have the wine-mono package installed on your system (distributions may have it available in their repository), newly created wine prefixes will default to using that as a .NET implementation. As a result, however, the native MSBuild.exe might crash because it relies on some telemetry features that wine-mono doesn’t implement. If that’s the case, run wine uninstaller and remove Wine Mono Windows Support, then run winetricks dotnet48 to install the official .NET 4.8 package inside your wine prefix.
Installing the Microsoft DirectX SDK
Section titled “Installing the Microsoft DirectX SDK”You will need to download and install the Microsoft DirectX SDK (August 2009) inside your wine prefix. For more information, you may check out the original Compiling MTASA guide. To obtain the installer (DXSDK_Aug09.exe), you can use the following mirrors:
See DXSDK Aug09 Hashes for file hashes of the installer.
d3dx9.h include error when building. DXSDK_DIR environment variable set. Building
Section titled “Building”To obtain the latest MTA source code, please refer to the original Compiling MTASA guide. Make sure you have your WINEPREFIX set correctly.
Doing a full build
Section titled “Doing a full build”Specify the location of the msbuild wrapper script installed by msvc-wine, then execute ./wine-build.sh. After the build completes, run wine ./win-install-data.bat to install the necessary binary blobs (and optionally the resources). You can find the msbuild wrapper script at bin/x64/msbuild in the directory where you installed msvc-wine to.
MSBUILDPATH="/path/to/msvc-wine-install-dir/bin/x64/msbuild" ./wine-build.shwine ./win-install-data.batIf all went well, you should now have the built Client and Server binaries sitting inside ./Bin/. For running the Client, see Client on Linux Manual.
Release or Debug) and the target platform (Win32, x64, ARM or ARM64) as arguments to ./wine-build.sh. Doing an incremental build
Section titled “Doing an incremental build”Although you could, you don’t need to rerun ./wine-build.sh after every change you make in the source code. If you add, remove or move a file or a directory, you can just manually regenerate the necessary projects:
wine utils/premake5.exe vs2022Then to do an incremental build, you can just manually invoke msbuild:
/path/to/msvc-wine-install-dir/bin/x64/msbuild Build/MTASA.sln \ -property:Configuration=Release \ -property:Platform=Win32 \ -maxCpuCountIDE integration
Section titled “IDE integration”premake can’t generate compile_commands.json by itself, but there are modules for it:
- https://github.com/MattBystrin/premake-ecc
- https://github.com/tarruda/premake-export-compile-commands
However, these might not work out of the box.
TODO
Troubleshooting
Section titled “Troubleshooting”You may also want to check out the error troubleshooting section in the original Compiling MTASA guide.
Internal Compiler Errors
Section titled “Internal Compiler Errors”If you encounter ICEs (Internal Compiler Errors) when trying to build the project, you should try to increase the file descriptor limit after killing the wine server. You may also want to remove the ./Build/{bin,obj} directories.
# Kill the wine serverwineserver -k# Increase the file descriptor limitulimit -n $(ulimit -Hn)# Remove the partially built artifactsrm -rf ./Build/{bin,obj}