From 3f1d78ec10f75f2eb3585132af5f4a76c45e9ed9 Mon Sep 17 00:00:00 2001 From: Diamante Date: Tue, 4 Jun 2024 18:48:54 +0200 Subject: [PATCH] build: use GCC to compile & use alpine image for Docker (#88) --- .github/workflows/build.yml | 27 +++++++------ .gitmodules | 4 -- Dockerfile | 7 ++-- deps/curl | 1 - deps/premake/curl.lua | 75 ------------------------------------- src/utils/http.cpp | 59 ----------------------------- src/utils/http.hpp | 14 ------- 7 files changed, 19 insertions(+), 168 deletions(-) delete mode 160000 deps/curl delete mode 100644 deps/premake/curl.lua delete mode 100644 src/utils/http.cpp delete mode 100644 src/utils/http.hpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a87ad0b..5f3289f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,9 +29,12 @@ jobs: - debug - release arch: + - x86 - x64 - arm64 include: + - arch: x86 + platform: Win32 - arch: x64 platform: x64 - arch: arm64 @@ -80,6 +83,7 @@ jobs: - debug - release arch: + - x86 - x64 steps: - name: Check out files @@ -90,19 +94,23 @@ jobs: # NOTE - If LFS ever starts getting used during builds, switch this to true! lfs: false - - name: Install dependencies (x64) - if: matrix.arch == 'x64' + - name: Install dependencies (x86) + if: matrix.arch == 'x86' run: | + sudo dpkg --add-architecture i386 sudo apt-get update - sudo apt-get install libcurl4-gnutls-dev -y + sudo apt-get -y install gcc-multilib g++-multilib - name: Install Premake5 uses: diamante0018/setup-premake@master with: version: ${{ env.PREMAKE_VERSION }} + - name: Install Mold + uses: rui314/setup-mold@staging + - name: Generate project files - run: premake5 --cc=clang gmake2 + run: premake5 gmake2 - name: Set up problem matching uses: ammaraskar/gcc-problem-matcher@master @@ -111,9 +119,6 @@ jobs: run: | pushd build make config=${{matrix.configuration}}_${{matrix.arch}} -j$(nproc) - env: - CC: clang - CXX: clang++ - name: Upload ${{matrix.arch}} ${{matrix.configuration}} binaries uses: actions/upload-artifact@main @@ -124,7 +129,7 @@ jobs: build-macos: name: Build macOS - runs-on: macos-13 + runs-on: macos-14 strategy: fail-fast: false matrix: @@ -224,10 +229,10 @@ jobs: shell: bash - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v3.2.0 + uses: docker/setup-buildx-action@v3.3.0 - name: Login to DockerHub - uses: docker/login-action@v3.1.0 + uses: docker/login-action@v3.2.0 with: username: ${{ secrets.DOCKERHUB_USER }} password: ${{ secrets.DOCKERHUB_TOKEN }} @@ -243,7 +248,7 @@ jobs: - name: Build and Push Docker Image id: build-and-push - uses: docker/build-push-action@v5.1.0 + uses: docker/build-push-action@v5.3.0 with: context: . platforms: linux/amd64 diff --git a/.gitmodules b/.gitmodules index 2ca343b..d7a4a64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -16,7 +16,3 @@ path = deps/libtomcrypt url = https://github.com/libtom/libtomcrypt.git branch = develop -[submodule "deps/curl"] - path = deps/curl - url = https://github.com/curl/curl.git - branch = curl-8_7_1 diff --git a/Dockerfile b/Dockerfile index 571d90b..ea266ea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ -FROM ubuntu:latest +FROM alpine:latest -RUN apt-get update -RUN apt-get install -y libc++-dev libcurl4-gnutls-dev +RUN apk add --no-cache gcompat libstdc++ COPY --chmod=755 ./linux-x64-release/alterware-master /usr/local/bin/ -RUN groupadd alterware-master && useradd -r -g alterware-master alterware-master +RUN addgroup -S alterware-master && adduser -S alterware-master -G alterware-master USER alterware-master EXPOSE 20810/udp diff --git a/deps/curl b/deps/curl deleted file mode 160000 index de7b3e8..0000000 --- a/deps/curl +++ /dev/null @@ -1 +0,0 @@ -Subproject commit de7b3e89218467159a7af72d58cea8425946e97d diff --git a/deps/premake/curl.lua b/deps/premake/curl.lua deleted file mode 100644 index 0f92f2c..0000000 --- a/deps/premake/curl.lua +++ /dev/null @@ -1,75 +0,0 @@ -curl = { - source = path.join(dependencies.basePath, "curl"), -} - -function curl.import() - links { "curl" } - - filter "toolset:msc*" - links { "Crypt32.lib" } - filter {} - - curl.includes() -end - -function curl.includes() -filter "toolset:msc*" - includedirs { - path.join(curl.source, "include"), - } - - defines { - "CURL_STRICTER", - "CURL_STATICLIB", - "CURL_DISABLE_LDAP", - } -filter {} -end - -function curl.project() - if not os.istarget("windows") then - return - end - - project "curl" - language "C" - - curl.includes() - - includedirs { - path.join(curl.source, "lib"), - } - - files { - path.join(curl.source, "lib/**.c"), - path.join(curl.source, "lib/**.h"), - } - - defines { - "BUILDING_LIBCURL", - } - - filter "toolset:msc*" - - defines { - "USE_SCHANNEL", - "USE_WINDOWS_SSPI", - "USE_THREADS_WIN32", - } - - filter {} - - filter "toolset:not msc*" - - defines { - "USE_GNUTLS", - "USE_THREADS_POSIX", - } - - filter {} - - warnings "Off" - kind "StaticLib" -end - -table.insert(dependencies, curl) diff --git a/src/utils/http.cpp b/src/utils/http.cpp deleted file mode 100644 index c6343e5..0000000 --- a/src/utils/http.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include - -#include "http.hpp" -#include - -namespace utils::http -{ - namespace - { - size_t write_callback(void* contents, const size_t size, const size_t nmemb, void* userp) - { - static_cast(userp)->append(static_cast(contents), size * nmemb); - return size * nmemb; - } - } - - std::optional get_data(const std::string& url, const headers& headers) - { - curl_slist* header_list = nullptr; - auto* curl = curl_easy_init(); - if (!curl) - { - return {}; - } - - auto _ = gsl::finally([&]() - { - curl_slist_free_all(header_list); - curl_easy_cleanup(curl); - }); - - - for(const auto& header : headers) - { - auto data = header.first + ": "s + header.second; - header_list = curl_slist_append(header_list, data.data()); - } - - std::string buffer{}; - curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header_list); - curl_easy_setopt(curl, CURLOPT_URL, url.data()); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer); - if (curl_easy_perform(curl) == CURLE_OK) - { - return {std::move(buffer)}; - } - - return {}; - } - - std::future> get_data_async(const std::string& url, const headers& headers) - { - return std::async(std::launch::async, [url, headers]() - { - return get_data(url, headers); - }); - } -} diff --git a/src/utils/http.hpp b/src/utils/http.hpp deleted file mode 100644 index 773d6fa..0000000 --- a/src/utils/http.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace utils::http -{ - using headers = std::unordered_map; - - std::optional get_data(const std::string& url, const headers& headers = {}); - std::future> get_data_async(const std::string& url, const headers& headers = {}); -}