Skip to content

Commit 6a3f1d1

Browse files
committed
Add article on how to cross-compile MTASA on Linux using msvc-wine
1 parent 9002a5f commit 6a3f1d1

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
title: Cross-compiling MTASA on Linux using msvc-wine
3+
---
4+
import NoteBox from '@src/components/NoteBox.astro';
5+
6+
This guide will walk you through how you can cross-compile MTASA on Linux targeting Windows, using [msvc-wine](https://github.com/mstorsjo/msvc-wine/). For running the game on Linux, see [Client on Linux Manual](/Client_on_Linux_Manual).
7+
8+
## Setting up the environment
9+
10+
### Setting up msvc-wine
11+
12+
Clone https://github.com/mstorsjo/msvc-wine/
13+
14+
```sh
15+
git clone https://github.com/mstorsjo/msvc-wine/
16+
cd msvc-wine
17+
```
18+
19+
Run `./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.
20+
```sh
21+
./vsdownload.py --dest /path/to/msvc-wine-install-dir/ --accept-license
22+
./vsdownload.py --dest /path/to/msvc-wine-install-dir/ --accept-license Microsoft.VisualStudio.Component.VC.ATLMFC
23+
./install.sh /path/to/msvc-wine-install-dir/
24+
```
25+
26+
<NoteBox type='warning'>Skipping installing `Microsoft.VisualStudio.Component.VC.ATLMFC` will lead to a missing `afxres.h` include error when building.</NoteBox>
27+
28+
### Setting up the Wine preifx
29+
30+
<NoteBox type='info'>This guide was written with wine-10.12 in mind, using the new WoW64 mode. Your mileage may vary if you are using an older version.</NoteBox>
31+
32+
Create or use an already existing wine prefix. **The rest of this guide assumes that you have your WINEPREFIX environment variable set correctly**.
33+
```sh
34+
# Set the wine prefix
35+
export WINEPREFIX="/path/to/wine-prefix"
36+
# If this is a new prefix, initialize it
37+
wineboot -i
38+
```
39+
40+
Make 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.
41+
42+
### Installing the Microsoft DirectX SDK
43+
44+
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](/Compiling_MTASA/#Microsoft_DirectX_SDK). To obtain the installer (`DXSDK_Aug09.exe`), you can use the following mirrors:
45+
* [Mirror 1 (archive.org)](https://archive.org/download/dxsdk_aug09/DXSDK_Aug09.exe)
46+
* [Mirror 2 (mega.nz)](https://mega.nz/file/pQJCiAJY#jBcYT6ZP4DMBpnm12BLRto9EQ-RjjpP3BWkSPanpvLI)
47+
48+
See [DXSDK Aug09 Hashes](/Compiling_MTASA/DXSDK_Aug09_Hashes) for file hashes of the installer.
49+
50+
<NoteBox type='warning'>Skipping this step will lead to a missing `d3dx9.h` include error when building.</NoteBox>
51+
<NoteBox type='info'>Unlike on Windows, here you don't have to restart anything. The next invocation of wine will already have the `DXSDK_DIR` environment variable set.</NoteBox>
52+
53+
## Building
54+
55+
To obtain the latest MTA source code, please refer to the original [Compiling MTASA guide](/Compiling_MTASA/#Getting_the_latest_source_code). Make sure you have your `WINEPREFIX` set correctly.
56+
57+
### Doing a full build
58+
59+
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.
60+
```sh
61+
MSBUILDPATH="/path/to/msvc-wine-install-dir/bin/x64/msbuild" ./wine-build.sh
62+
wine ./win-install-data.bat
63+
```
64+
65+
If 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](/Client_on_Linux_Manual).
66+
67+
<NoteBox type='info'>You can also pass the build configuration (`Release` or `Debug`) and the target platform (`Win32`, `x64`, `ARM` or `ARM64`) as arguments to `./wine-build.sh`.</NoteBox>
68+
69+
### Doing an incremental build
70+
71+
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:
72+
```sh
73+
wine utils/premake5.exe vs2022
74+
```
75+
76+
Then to do an incremental build, you can just manually invoke `msbuild`:
77+
```sh
78+
/path/to/msvc-wine-install-dir/bin/x64/msbuild Build/MTASA.sln \
79+
-property:Configuration=Release \
80+
-property:Platform=Win32 \
81+
-maxCpuCount
82+
```
83+
84+
### IDE integration
85+
86+
premake can't generate `compile_commands.json` by itself, but there are modules for it:
87+
* https://github.com/MattBystrin/premake-ecc
88+
* https://github.com/tarruda/premake-export-compile-commands
89+
90+
However, these might not work out of the box.
91+
92+
TODO
93+
94+
## Troubleshooting
95+
96+
You may also want to check out the error troubleshooting section in the original [Compiling MTASA guide](/Compiling_MTASA/#Error_Troubleshooting).
97+
98+
### Internal Compiler Errors
99+
100+
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.
101+
```sh
102+
# Kill the wine server
103+
wineserver -k
104+
# Increase the file descriptor limit
105+
ulimit -n $(ulimit -Hn)
106+
# Remove the partially built artifacts
107+
rm -rf ./Build/{bin,obj}
108+
```

0 commit comments

Comments
 (0)