From 5b79a1c9106bd1d327d624362620cba1fe4cc674 Mon Sep 17 00:00:00 2001 From: coco875 <59367621+coco875@users.noreply.github.com> Date: Mon, 8 Dec 2025 16:49:21 +0100 Subject: [PATCH] Improve cmake, make release need less dependancy and clean up some file (#584) * Update CMakeLists.txt * try something to use less dependancy * improve script * Delete addr_to_sym.py * restore dockerfile * move the docker for release and a script to execute it to script * Delete build.sh * move more script to script folder * add the new docker in the CI * Update vcpkg.json * fix windows and macos in theory --- .github/workflows/linux-compile.yml | 81 ++++++++++++++++ .github/workflows/main.yml | 95 ++++++++++++++++--- .gitignore | 1 + CMakeLists.txt | 4 + Dockerfile | 2 +- addr_to_sym.py | 20 ---- script/Dockerfile | 52 ++++++++++ script/build-release.sh | 56 +++++++++++ .../check_type_yamls.py | 0 .../valgrind_callgrind.sh | 0 src/port/Engine.cpp | 6 +- test_blend.bat | 1 - vcpkg.json | 15 ++- 13 files changed, 294 insertions(+), 39 deletions(-) delete mode 100644 addr_to_sym.py create mode 100644 script/Dockerfile create mode 100755 script/build-release.sh rename check_type_yamls.py => script/check_type_yamls.py (100%) rename valgrind_callgrind.sh => script/valgrind_callgrind.sh (100%) delete mode 100644 test_blend.bat diff --git a/.github/workflows/linux-compile.yml b/.github/workflows/linux-compile.yml index 7f0fe1a5f..cbf6fbb2c 100644 --- a/.github/workflows/linux-compile.yml +++ b/.github/workflows/linux-compile.yml @@ -54,3 +54,84 @@ jobs: name: spaghetti-linux-x64-${{ matrix.config }} path: spaghetti-${{ matrix.config }} retention-days: 1 + build-docker: + runs-on: ubuntu-latest + strategy: + matrix: + config: [Release] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + submodules: recursive + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ hashFiles('script/Dockerfile', 'vcpkg.json') }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./script/Dockerfile + push: false + load: true + tags: spaghettikart-builder:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Build project in Docker + run: | + docker run --rm \ + -v "${{ github.workspace }}:/project" \ + spaghettikart-builder:latest \ + bash -c " + cp vcpkg.json /tmp/vcpkg.json && \ + cd /tmp && \ + \${VCPKG_ROOT}/vcpkg install --triplet x64-linux && \ + cd /project && \ + cmake -B build -G Ninja \ + -DCMAKE_BUILD_TYPE=${{ matrix.config }} \ + -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_TARGET_TRIPLET=x64-linux && \ + cmake --build build --parallel + " + + - name: Generate AppImage + run: | + docker run --rm \ + -v "${{ github.workspace }}:/project" \ + spaghettikart-builder:latest \ + bash -c " + cd /project/build && \ + cpack -G External || true + " + + - name: Create Package + run: | + mkdir -p spaghetti-${{ matrix.config }} + cp build/Spaghettify spaghetti-${{ matrix.config }}/ || true + wget -O gamecontrollerdb.txt https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/gamecontrollerdb.txt + mv gamecontrollerdb.txt spaghetti-${{ matrix.config }}/ + cp build/*.appimage spaghetti-${{ matrix.config }}/ 2>/dev/null || true + + - name: Publish packaged artifacts + uses: actions/upload-artifact@v4 + with: + name: spaghetti-linux-docker-x64-${{ matrix.config }} + path: spaghetti-${{ matrix.config }} + retention-days: 7 + + # Workaround for cache growing too large + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache || true \ No newline at end of file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5d35c7006..6cff787f7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -126,7 +126,7 @@ jobs: build-macos-intel: needs: generate-port-o2r - runs-on: macOS-13 + runs-on: macOS-latest-intel strategy: matrix: config: [Release, Debug] @@ -344,18 +344,6 @@ jobs: run: | cmake -H. -Bbuild-cmake -GNinja -DCMAKE_BUILD_TYPE=${{ matrix.config }} cmake --build build-cmake --config ${{ matrix.config }} -j3 - (cd build-cmake && cpack -G External) - wget -O gamecontrollerdb.txt https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/gamecontrollerdb.txt - mv README.md readme.txt - mv build-cmake/*.appimage spaghetti.appimage - - name: Upload build - if: matrix.config == 'Release' - uses: actions/upload-artifact@v4 - with: - name: spaghetti-linux-x64 - path: | - spaghetti.appimage - gamecontrollerdb.txt build-linux-docker: needs: generate-port-o2r @@ -383,6 +371,87 @@ jobs: - name: Build spaghetti run: docker run --rm -v ${PWD}:/project spaghetti cmake --build build-cmake --config ${{ matrix.config }} -j$(nproc) + build-docker: + runs-on: ubuntu-latest + strategy: + matrix: + config: [Release] + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + submodules: recursive + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ hashFiles('script/Dockerfile', 'vcpkg.json') }} + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./script/Dockerfile + push: false + load: true + tags: spaghettikart-builder:latest + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max + + - name: Build project in Docker + run: | + docker run --rm \ + -v "${{ github.workspace }}:/project" \ + spaghettikart-builder:latest \ + bash -c " + cp vcpkg.json /tmp/vcpkg.json && \ + cd /tmp && \ + \${VCPKG_ROOT}/vcpkg install --triplet x64-linux && \ + cd /project && \ + cmake -B build -G Ninja \ + -DCMAKE_BUILD_TYPE=${{ matrix.config }} \ + -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_TARGET_TRIPLET=x64-linux && \ + cmake --build build --parallel + " + + - name: Generate AppImage + run: | + docker run --rm \ + -v "${{ github.workspace }}:/project" \ + spaghettikart-builder:latest \ + bash -c " + cd /project/build && \ + cpack -G External || true + " + + - name: Create Package + run: | + mkdir -p spaghetti-${{ matrix.config }} + cp build/Spaghettify spaghetti-${{ matrix.config }}/ || true + wget -O gamecontrollerdb.txt https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/master/gamecontrollerdb.txt + mv gamecontrollerdb.txt spaghetti-${{ matrix.config }}/ + cp build/*.appimage spaghetti-${{ matrix.config }}/ 2>/dev/null || true + + - name: Publish packaged artifacts + uses: actions/upload-artifact@v4 + with: + name: spaghetti-linux-x64 + path: spaghetti-${{ matrix.config }} + + # Workaround for cache growing too large + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cache || true + build-switch: needs: generate-port-o2r runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 4858b91ef..b65d51fef 100644 --- a/.gitignore +++ b/.gitignore @@ -128,3 +128,4 @@ cmake-build-*/ build*/ .DS_Store .cache/ +_packages/ diff --git a/CMakeLists.txt b/CMakeLists.txt index f3f2e660a..d11d225bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -173,6 +173,10 @@ else() set(CMAKE_CXX_FLAGS_DEBUG "-g -DNDEBUG ${COMMON_CXX_FLAGS}") set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG ${COMMON_C_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG ${COMMON_CXX_FLAGS}") + set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG ${COMMON_C_FLAGS}") + set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os -DNDEBUG ${COMMON_CXX_FLAGS}") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${COMMON_C_FLAGS}") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g -DNDEBUG ${COMMON_CXX_FLAGS}") endif() # Set game compilation version diff --git a/Dockerfile b/Dockerfile index 3c26400a4..aa026e2af 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,4 +61,4 @@ RUN wget https://github.com/nih-at/libzip/releases/download/v1.10.1/libzip-1.10. cd ../.. && \ rm -rf libzip-1.10.1.tar.gz libzip-1.10.1 -WORKDIR /project +WORKDIR /project \ No newline at end of file diff --git a/addr_to_sym.py b/addr_to_sym.py deleted file mode 100644 index 13737b628..000000000 --- a/addr_to_sym.py +++ /dev/null @@ -1,20 +0,0 @@ -import re - -# Define the regex query to match the hex values -regex_query = r'0x07[0-9a-fA-F]{6}' - -# Define a function to process each match -def process_match(match): - offset = int(match.group(0)[4:], 16) - return f"d_course_big_donut_packed_dl_{hex(offset)[2:].upper()}" - -# Open the input file -with open("courses/big_donut/packed.inc.c", "r") as f: - # Read the file contents - file_content = f.read() - - # Use re.sub() to find and replace all matches in the file content - modified_content = re.sub(regex_query, process_match, file_content) - - # Print the modified content to console - print(modified_content) diff --git a/script/Dockerfile b/script/Dockerfile new file mode 100644 index 000000000..ebfe509cf --- /dev/null +++ b/script/Dockerfile @@ -0,0 +1,52 @@ +FROM ubuntu:22.04 + +ENV DEBIAN_FRONTEND=noninteractive +ENV VCPKG_ROOT=/opt/vcpkg +ENV PATH="${VCPKG_ROOT}:${PATH}" + +# Install base dependencies +RUN apt-get update -y && apt-get -y upgrade && \ + apt-get -y install \ + build-essential \ + gcc \ + g++ \ + git \ + ninja-build \ + curl \ + zip \ + unzip \ + tar \ + pkg-config \ + wget \ + file \ + autoconf \ + automake \ + libtool \ + python3 \ + libx11-dev \ + libxrandr-dev \ + libxi-dev \ + libxinerama-dev \ + libxcursor-dev \ + libgl1-mesa-dev \ + libopengl-dev \ + libwayland-dev \ + libxkbcommon-dev \ + libasound2-dev \ + libpulse-dev \ + libudev-dev \ + libdbus-1-dev + +# Install CMake 4.0.3 +ENV DOCKER_CMAKE_VERSION="4.0.3" +RUN wget https://github.com/Kitware/CMake/releases/download/v${DOCKER_CMAKE_VERSION}/cmake-${DOCKER_CMAKE_VERSION}-linux-x86_64.sh && \ + chmod +x cmake-${DOCKER_CMAKE_VERSION}-linux-x86_64.sh && \ + ./cmake-${DOCKER_CMAKE_VERSION}-linux-x86_64.sh --prefix=/usr/local --skip-license && \ + rm cmake-${DOCKER_CMAKE_VERSION}-linux-x86_64.sh + +# Install vcpkg +RUN git clone https://github.com/microsoft/vcpkg.git ${VCPKG_ROOT} && \ + cd ${VCPKG_ROOT} && \ + ./bootstrap-vcpkg.sh -disableMetrics + +WORKDIR /project diff --git a/script/build-release.sh b/script/build-release.sh new file mode 100755 index 000000000..084b8c3c2 --- /dev/null +++ b/script/build-release.sh @@ -0,0 +1,56 @@ +#!/bin/bash +set -e + +# Script to build SpaghettiKart using Docker +# Usage: ./docker/build.sh [Release|Debug] + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +PROJECT_DIR="$(dirname "$SCRIPT_DIR")" + +BUILD_TYPE="${1:-Release}" +BUILD_DIR="build-docker" +IMAGE_NAME="spaghettikart-builder" +USER_ID=$(id -u) +GROUP_ID=$(id -g) + +cd "$PROJECT_DIR" + +# Build Docker image +echo "Building Docker image..." +docker build -t "${IMAGE_NAME}" -f script/Dockerfile . + +# Clean build directory if it contains incompatible cache +if [[ -f "${BUILD_DIR}/CMakeCache.txt" ]] && grep -q "/home/coco" "${BUILD_DIR}/CMakeCache.txt" 2>/dev/null; then + echo "Cleaning incompatible build cache..." + rm -rf "${BUILD_DIR}" +fi + +# Run build in Docker +echo "Building in Docker container..." +docker run --rm \ + -v "$(pwd):/project" \ + -e BUILD_TYPE="${BUILD_TYPE}" \ + -e USER_ID="${USER_ID}" \ + -e GROUP_ID="${GROUP_ID}" \ + "${IMAGE_NAME}" \ + bash -c " + # Copy vcpkg.json and install dependencies + cp vcpkg.json /tmp/vcpkg.json && \ + cd /tmp && \ + \${VCPKG_ROOT}/vcpkg install --triplet x64-linux && \ + cd /project && \ + cmake -B ${BUILD_DIR} -G Ninja \ + -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \ + -DCMAKE_TOOLCHAIN_FILE=/opt/vcpkg/scripts/buildsystems/vcpkg.cmake \ + -DVCPKG_TARGET_TRIPLET=x64-linux && \ + cmake --build ${BUILD_DIR} --parallel && \ + cp -f spaghetti.o2r ${BUILD_DIR}/ 2>/dev/null || true && \ + cp -f mk64.o2r ${BUILD_DIR}/ 2>/dev/null || true && \ + cd ${BUILD_DIR} && cpack -G External && \ + chown -R ${USER_ID}:${GROUP_ID} /project/${BUILD_DIR} /project/logs 2>/dev/null || true + " + +echo "" +echo "Build complete!" +echo "Executable: ${BUILD_DIR}/Spaghettify" +ls -1 "${BUILD_DIR}"/*.appimage 2>/dev/null && echo "AppImage generated successfully!" || echo "Note: AppImage generation may have failed" diff --git a/check_type_yamls.py b/script/check_type_yamls.py similarity index 100% rename from check_type_yamls.py rename to script/check_type_yamls.py diff --git a/valgrind_callgrind.sh b/script/valgrind_callgrind.sh similarity index 100% rename from valgrind_callgrind.sh rename to script/valgrind_callgrind.sh diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index 9729d9a5b..8bbd65cab 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -166,8 +166,8 @@ GameEngine::GameEngine() { { BTN_DDOWN, "DDown" }, }); auto controlDeck = std::make_shared(std::vector(), defaultMappings, buttonNames); - - this->context->InitResourceManager({}, {}, 3); // without this line InitWindow fails in Gui::Init() + const std::string assets_path = Ship::Context::LocateFileAcrossAppDirs("spaghetti.o2r"); + this->context->InitResourceManager({assets_path}, {}, 3); // without this line InitWindow fails in Gui::Init() this->context->InitConsole(); // without this line the GuiWindow constructor fails in ConsoleWindow::InitElement() auto gui = std::make_shared(std::vector>({})); @@ -176,7 +176,7 @@ GameEngine::GameEngine() { // auto wnd = std::make_shared(std::vector>({})); // auto wnd = std::dynamic_pointer_cast(Ship::Context::GetInstance()->GetWindow()); - this->context->Init({}, {}, 3, { 26800, 512, 1100 }, wnd, controlDeck); + this->context->Init({assets_path}, {}, 3, { 26800, 512, 1100 }, wnd, controlDeck); #ifndef __SWITCH__ Ship::Context::GetInstance()->GetLogger()->set_level( diff --git a/test_blend.bat b/test_blend.bat deleted file mode 100644 index a190f6fcd..000000000 --- a/test_blend.bat +++ /dev/null @@ -1 +0,0 @@ -"c:\Program Files\Blender Foundation\Blender 4.0\blender.exe" -b --python tools/blender_extension/blender_export.py -- courses/dks_jungle_parkway/course_data.inc.c d_course_dks_jungle_parkway_dl_E058 \ No newline at end of file diff --git a/vcpkg.json b/vcpkg.json index fec076923..53da50815 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -8,7 +8,20 @@ "bzip2", "libzip", "libpng", - "sdl2", + { + "name": "sdl2", + "features": ["x11", "alsa", "wayland"], + "platform": "linux", + "default-features": false + }, + { + "name": "sdl2", + "platform": "windows" + }, + { + "name": "sdl2", + "platform": "osx" + }, "sdl2-net", "glew", "glfw3",