Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online client: build using MinGW and CMake #151

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

iwanb
Copy link

@iwanb iwanb commented Jun 19, 2024

This adds support to build the client using CMake and MinGW, so it can be cross-built on Linux. I re-used the nix setup that was done for the server (fun to see nix in this project!). I tested the built client, using MinGW. I don't have Windows/VisualStudio to build it on Windows.

I would like to look into porting the client to Linux and porting the memory map to PINE, but I thought it would be better if I can build and test the Windows one first, to compare and make sure I don't break things.

Most of the CMake file is from #131

I had to do two changes to the client, one is to add #include <psapi.h> which seems harmless.

The second one is to change OpenFileMapping to OpenFileMappingW. This seems to be what's documented, but I'm not familiar with the Windows APIs so I'm not sure why it was needed (I assume for wide-char support) and whether it's fine for the Windows build. https://learn.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-openfilemappingw

Copy link
Contributor

@PedroHLC PedroHLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CMake and Nix part LGTM.

Someone should confirm if it still works with MSVC/VisualStudio

@FRDS
Copy link
Contributor

FRDS commented Jun 19, 2024

I have confirmed it builds successfully on Visual Studio 2022 and detects Duckstation on Windows just fine like before. 😀

Build started...
1>------ Build started: Project: Client, Configuration: Release x64 ------
1>callbacks.c
1>compress.c
1>host.c
1>list.c
1>packet.c
1>peer.c
1>protocol.c
1>unix.c
1>win32.c
1>CL_main.c
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(132,21): warning C4244: '=': conversion from 'unsigned short' to 'unsigned char', possible loss of data
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(62,20): warning C4133: 'initializing': incompatible types - from 'enet_uint8 *' to 'SG_Header *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(71,28): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageRooms *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(118,35): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageClientStatus *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(165,27): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageName *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(180,21): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(192,28): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageTrack *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(213,32): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageCharacter *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(257,30): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_EverythingKart *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(289,20): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(329,30): warning C4133: 'initializing': incompatible types - from 'SG_Header *' to 'SG_MessageEndRace *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(337,20): warning C4133: 'initializing': incompatible types - from 'char *' to 'Gamepad *'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1048,20): warning C4018: '<': signed/unsigned mismatch
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1064,41): warning C4133: 'function': incompatible types - from 'TCHAR [260]' to 'LPSTR'
1>C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\Client\CL_main.c(1130,10): warning C4133: 'function': incompatible types - from 'FILE *' to 'const char *const '
1>Generating code
1>Previous IPDB not found, fall back to full compilation.
1>All 114 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
1>Finished generating code
1>Client.vcxproj -> C:\CTR-Modding\psx-modding-toolchain-main\games\CTR-ModSDK\mods\Windows\OnlineCTR\Network_PC\x64\Release\Client.exe
1>Done building project "Client.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 6:06 AM and took 06.639 seconds ==========

Copy link
Contributor

@PedroHLC PedroHLC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested again, this time with really running it. 🏁

You could add artefacts to the CI by adding to .github/workflows/main.yml:

      - name: Build Server Release Mingw2 GCC
        run: nix build -L --keep-going '.?submodules=1#online-server.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-server.release.mingw32.gcc
+      - name: Build Client Release Mingw2 GCC
+        run: nix build -L --keep-going '.?submodules=1#online-client.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-client.release.mingw32.gcc
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: online-server-windows
          path: |
            ${{ runner.temp }}/result/online-server.release.mingw32.gcc/bin
+            ${{ runner.temp }}/result/online-client.release.mingw32.gcc/bin

flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@iwanb
Copy link
Author

iwanb commented Jun 25, 2024

Tested again, this time with really running it. 🏁

You could add artefacts to the CI by adding to .github/workflows/main.yml:

      - name: Build Server Release Mingw2 GCC
        run: nix build -L --keep-going '.?submodules=1#online-server.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-server.release.mingw32.gcc
+      - name: Build Client Release Mingw2 GCC
+        run: nix build -L --keep-going '.?submodules=1#online-client.release.mingw32.gcc' -o ${{ runner.temp }}/result/online-client.release.mingw32.gcc
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        with:
          name: online-server-windows
          path: |
            ${{ runner.temp }}/result/online-server.release.mingw32.gcc/bin
+            ${{ runner.temp }}/result/online-client.release.mingw32.gcc/bin

Yes I thought about doing that. On my machine I used the mingw64 build though. Not sure what is preferable?

@PedroHLC
Copy link
Contributor

mingw64 build though.

Sorry, only yesterday I learned that the online client does not need to be built in 32 bits (PC port of the game needs)

Use the 64 one, that's what they're providing for users.

@iwanb
Copy link
Author

iwanb commented Jul 16, 2024

I've updated it to build the new cpp and PINE based client. It needed a couple harmless changes, but I'm not 100% sure about the needed change in decompile/General/AltMods/OnlineCTR/global.h.

I could use the client (using wine) against the native linux Duckstation, but on linux duckstation uses a unix socket for pine while the client uses TCP so I had to proxy that using socat, running this on top of the client:

socat -d TCP-LISTEN:28011,fork UNIX-CONNECT:/run/user/1000/duckstation.sock

@TheUbMunster

@TheUbMunster
Copy link
Contributor

I'm not sure about global.h, as that static assert stuff wasn't mine.

@PedroHLC
Copy link
Contributor

I'm not sure about global.h, as that static assert stuff wasn't mine.

looks right to me, it's inside the GCC/Clang pre-processor-branch, and if it detects window.h (so it has to be Mingw's GCC and not Linux's GCC) then it does the same thing it does on MSVC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants