From 092f338b0b787a2a4520bd57f319fcb9fe919a0a Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 27 Mar 2024 11:32:46 +0100 Subject: [PATCH 1/3] Update CI/CD --- .github/workflows/compilation.yml | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 3a3e715..12ed888 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -12,7 +12,7 @@ jobs: os: [macos-latest, ubuntu-latest] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Compile native versions run: | @@ -20,12 +20,13 @@ jobs: - name: Get short SHA id: slug - run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)" + run: | + echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT - name: Create tar archive (keep executable bit) run: tar -zcvf ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os}}.tar.gz bin - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os}} path: | @@ -36,7 +37,7 @@ jobs: container: dockcross/windows-static-x86:latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Compile windows version with cross-compilator run: | @@ -49,7 +50,7 @@ jobs: - name: Create tar archive run: tar -zcvf ps2client-${{ steps.slug.outputs.sha8 }}-windows-latest.tar.gz bin - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 with: name: ps2client-${{ steps.slug.outputs.sha8 }}-windows-latest path: | @@ -60,24 +61,25 @@ jobs: runs-on: ubuntu-latest if: startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/master' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Get short SHA id: slug - run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)" + run: | + echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT - name: Download Mac artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: ps2client-${{ steps.slug.outputs.sha8 }}-macos-latest - name: Download Ubuntu artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: ps2client-${{ steps.slug.outputs.sha8 }}-ubuntu-latest - name: Download Windows artifact - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: name: ps2client-${{ steps.slug.outputs.sha8 }}-windows-latest From bb5a00cd414cf77ee5f924b956e9202b5618354d Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 27 Mar 2024 13:05:28 +0100 Subject: [PATCH 2/3] Simplify platform logic --- src/fsclient.c | 8 ++------ src/network.c | 5 ++--- src/network.h | 2 -- src/ps2client.c | 10 ++-------- src/ps2link.c | 14 +++++++------- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/fsclient.c b/src/fsclient.c index d39c4a7..de58c2f 100644 --- a/src/fsclient.c +++ b/src/fsclient.c @@ -56,12 +56,8 @@ // Check to make sure a command was actually supplied. if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; } -#ifdef _WIN32 - - // Startup network, under windows. - if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; } - -#endif + // Startup network + if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; } // Connect to the ps2netfs server. if (ps2netfs_connect(hostname) < 0) { printf("Error: Could not connect to the ps2netfs server. (%s)\n", hostname); return -1; } diff --git a/src/network.c b/src/network.c index d0d877c..cdbf06d 100644 --- a/src/network.c +++ b/src/network.c @@ -13,18 +13,17 @@ // NETWORK FUNCTIONS // /////////////////////// -#ifdef _WIN32 int network_startup(void) { +#ifdef _WIN32 WSADATA wsaData; // Start up winsock. if (WSAStartup(MAKEWORD(2, 0), &wsaData) != 0) { return -1; } +#endif // End function. return 0; - } -#endif int network_connect(char *hostname, int port, int type) { int sock = -1; struct sockaddr_in sockaddr; diff --git a/src/network.h b/src/network.h index a592757..a1fe603 100644 --- a/src/network.h +++ b/src/network.h @@ -12,9 +12,7 @@ // NETWORK FUNCTIONS // /////////////////////// -#ifdef _WIN32 int network_startup(void); -#endif int network_connect(char *hostname, int port, int type); diff --git a/src/ps2client.c b/src/ps2client.c index 7631795..be54bda 100644 --- a/src/ps2client.c +++ b/src/ps2client.c @@ -5,9 +5,7 @@ #include #include "utility.h" #include "ps2link.h" -#ifdef _WIN32 #include "network.h" -#endif char hostname[256] = { "192.168.0.10" }; @@ -65,12 +63,8 @@ // Check to make sure a command was actually supplied. if (argc < 0) { printf("Error: No command was supplied.\n"); print_usage(); return -1; } -#ifdef _WIN32 - - // Startup network, under windows. - if (network_startup() < 0) { printf("Error: Could not start up winsock.\n"); return 1; } - -#endif + // Startup network. + if (network_startup() < 0) { printf("Error: Could not startup network.\n"); return 1; } // Connect to the ps2link server. if (ps2link_connect(hostname) < 0) { printf("Error: Could not connect to the ps2link server. (%s)\n", hostname); return -1; } diff --git a/src/ps2link.c b/src/ps2link.c index 563aa67..19095e9 100644 --- a/src/ps2link.c +++ b/src/ps2link.c @@ -13,6 +13,7 @@ #else #include #define sleep(x) Sleep(x * 1000) + #define pause() while (1) { Sleep(600000); } #endif #include "network.h" @@ -59,11 +60,7 @@ command_socket = network_connect(hostname, 0x4712, SOCK_DGRAM); // Delay for a moment to let ps2link finish setup. -#ifdef _WIN32 - Sleep(1); -#else sleep(1); -#endif // End function. return 0; @@ -78,8 +75,8 @@ // If no timeout was given, timeout immediately. if (timeout == 0) { return 0; } - // If timeout was never, loop forever. - if (timeout < 0) { for (;;) { sleep(600); } } + // If timeout was never, wait forever. + if (timeout < 0) { pause(); } // Increment the timeout counter until timeout is reached. while (ps2link_counter++ < timeout) { sleep(1); }; @@ -90,7 +87,10 @@ } int ps2link_disconnect(void) { - + // Kill created threads. + pthread_cancel(request_thread_id); + pthread_cancel(console_thread_id); + // Disconnect from the command port. if (network_disconnect(command_socket) < 0) { return -1; } From 0bc9a65fd114c1b512fc6e64ca7d080997f2f93f Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Wed, 27 Mar 2024 19:39:57 +0100 Subject: [PATCH 3/3] Check also using mingw32 --- .github/workflows/compilation.yml | 39 +++++++++++++++++++++++-------- Makefile | 8 +++---- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.github/workflows/compilation.yml b/.github/workflows/compilation.yml index 12ed888..8c84238 100644 --- a/.github/workflows/compilation.yml +++ b/.github/workflows/compilation.yml @@ -3,20 +3,35 @@ name: CI on: push: pull_request: + workflow_dispatch: {} jobs: build: - runs-on: ${{ matrix.os }} + runs-on: ${{ matrix.os[0] }} strategy: matrix: - os: [macos-latest, ubuntu-latest] - - steps: + os: [[macos-latest, bash], [ubuntu-latest, bash], [windows-latest, msys2]] + fail-fast: false + defaults: + run: + shell: ${{ matrix.os[1] }} {0} + + steps: - uses: actions/checkout@v4 + - name: Install MSYS2 packages + if: matrix.os[0] == 'windows-latest' + uses: msys2/setup-msys2@v2 + with: + msystem: MINGW32 + install: | + base-devel mingw-w64-i686-gcc + update: true + - name: Compile native versions run: | - make --debug + make -j $(getconf _NPROCESSORS_ONLN) clean + make -j $(getconf _NPROCESSORS_ONLN) all - name: Get short SHA id: slug @@ -24,11 +39,13 @@ jobs: echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT - name: Create tar archive (keep executable bit) - run: tar -zcvf ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os}}.tar.gz bin + run: tar -zcvf ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os[0]}}.tar.gz bin - - uses: actions/upload-artifact@v4 + - name: Upload artefacts + if: matrix.os[0] != 'windows-latest' + uses: actions/upload-artifact@v4 with: - name: ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os}} + name: ps2client-${{ steps.slug.outputs.sha8 }}-${{matrix.os[0]}} path: | *tar.gz @@ -41,11 +58,13 @@ jobs: - name: Compile windows version with cross-compilator run: | - make -f Makefile.mingw32 --trace + make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) clean + make -f Makefile.mingw32 -j $(getconf _NPROCESSORS_ONLN) all - name: Get short SHA id: slug - run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)" + run: | + echo "sha8=$(echo ${GITHUB_SHA} | cut -c1-8)" >> $GITHUB_OUTPUT - name: Create tar archive run: tar -zcvf ps2client-${{ steps.slug.outputs.sha8 }}-windows-latest.tar.gz bin diff --git a/Makefile b/Makefile index a4c0731..e726c3d 100644 --- a/Makefile +++ b/Makefile @@ -12,17 +12,17 @@ CFLAGS += -O2 endif - ifneq "MINGW" "$(findstring MINGW,$(MSYSTEM))" - LIBS = -lpthread - else + ifeq ($(OS),Windows_NT) LIBS = -lwsock32 + else + LIBS = -lpthread endif ifeq "x$(PREFIX)" "x" PREFIX = $(PS2DEV) endif - ifeq "MINGW" "$(findstring MINGW,$(MSYSTEM))" + ifeq ($(OS),Windows_NT) all: $(MAKE) -f Makefile.mingw32 all