From 2a098c039c087bc2f144bdc3e01cfd9d2489d13d Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 00:31:22 +0800 Subject: [PATCH 1/8] feat:compile module --- CMakeLists.txt | 8 ++++++-- main.cpp | 4 ++++ sdl_wrapper/CMakeLists.txt | 14 ++++++++++++++ sdl_wrapper/sdl_wrapper.buffer.ixx | 13 +++++++++++++ sdl_wrapper/sdl_wrapper.ixx | 6 ++++++ 5 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 sdl_wrapper/CMakeLists.txt create mode 100644 sdl_wrapper/sdl_wrapper.buffer.ixx create mode 100644 sdl_wrapper/sdl_wrapper.ixx diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0d20b..1923319 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.30) project(SDL_TEST LANGUAGES C CXX) set(CMAKE_CXX_STANDARD 23) +set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) set(FETCHCONTENT_QUIET OFF CACHE BOOL "" FORCE) @@ -91,8 +92,11 @@ target_include_directories(imgui PUBLIC ) target_link_libraries(imgui PUBLIC SDL3::SDL3) +add_subdirectory(sdl_wrapper) + add_executable(SDL_TEST main.cpp) -target_link_libraries(SDL_TEST PRIVATE shaderc imgui) +target_link_libraries(SDL_TEST PRIVATE shaderc imgui sdl_wrapper) + include(GNUInstallDirs) install(TARGETS SDL_TEST diff --git a/main.cpp b/main.cpp index bf00519..3808de2 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,8 @@ #include #include +import sdl_wrapper; + // the vertex input layout struct Vertex { float x, y, z; //vec3 position @@ -48,6 +50,8 @@ void main() FragColor = v_color; })WSQ"; +sopho::BufferWrapper BufferWrapper{}; + SDL_Window *window; SDL_GPUDevice *device; SDL_GPUBuffer *vertexBuffer; diff --git a/sdl_wrapper/CMakeLists.txt b/sdl_wrapper/CMakeLists.txt new file mode 100644 index 0000000..50badf6 --- /dev/null +++ b/sdl_wrapper/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 3.30) +project(sdl_wrapper LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +add_library(sdl_wrapper STATIC) + +target_sources(sdl_wrapper + PUBLIC + FILE_SET cxx_modules TYPE CXX_MODULES FILES + ${CMAKE_CURRENT_SOURCE_DIR}/sdl_wrapper.ixx + ${CMAKE_CURRENT_SOURCE_DIR}/sdl_wrapper.buffer.ixx +) + +target_link_libraries(sdl_wrapper PUBLIC SDL3::SDL3) diff --git a/sdl_wrapper/sdl_wrapper.buffer.ixx b/sdl_wrapper/sdl_wrapper.buffer.ixx new file mode 100644 index 0000000..cb44360 --- /dev/null +++ b/sdl_wrapper/sdl_wrapper.buffer.ixx @@ -0,0 +1,13 @@ +// +// Created by sophomore on 11/8/25. +// + +export module sdl_wrapper:buffer; +#include "SDL3/SDL_gpu.h" + +namespace sopho { + export class BufferWrapper { + SDL_GPUBuffer *vertexBuffer{}; + + }; +} diff --git a/sdl_wrapper/sdl_wrapper.ixx b/sdl_wrapper/sdl_wrapper.ixx new file mode 100644 index 0000000..b57802a --- /dev/null +++ b/sdl_wrapper/sdl_wrapper.ixx @@ -0,0 +1,6 @@ +// +// Created by sophomore on 11/7/25. +// + +export module sdl_wrapper; +export import :buffer; \ No newline at end of file From 8d7b7ac5e598c53e9180b9c2d4207333229d80a4 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 00:40:23 +0800 Subject: [PATCH 2/8] feat:set generator --- .github/workflows/cmake-multi-platform.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 528139e..eb29df1 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -79,6 +79,7 @@ jobs: -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} + -G "Ninja Multi-Config" - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). From c3f32f901803cfcfc458d494b5e9106d4a4e0070 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 08:56:40 +0800 Subject: [PATCH 3/8] feat:split workflow into windows and linux --- .github/workflows/cmake-linux.yml | 91 +++++++++++++++++++ ...e-multi-platform.yml => cmake-windows.yml} | 13 +-- 2 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/cmake-linux.yml rename .github/workflows/{cmake-multi-platform.yml => cmake-windows.yml} (92%) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml new file mode 100644 index 0000000..1ac9399 --- /dev/null +++ b/.github/workflows/cmake-linux.yml @@ -0,0 +1,91 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "**" ] + pull_request: + branches: [ "**" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest] + build_type: [Debug, Release] + c_compiler: [gcc, clang] + include: + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + echo "install-dir=${{ github.workspace }}/install/${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" + + + - name: Install SDL windowing deps (Linux) + run: | + sudo apt-get update + sudo apt-get install -y --no-install-recommends \ + build-essential pkg-config cmake ninja-build \ + libasound2-dev libpulse-dev libaudio-dev libjack-dev \ + libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev \ + libxkbcommon-dev libwayland-dev wayland-protocols \ + libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev \ + libdbus-1-dev libudev-dev + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + -G "Ninja Multi-Config" + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} + + - name: Install + run: > + cmake --install ${{ steps.strings.outputs.build-output-dir }} + --config ${{ matrix.build_type }} + --prefix "${{ steps.strings.outputs.install-dir }}" + + - name: Upload install folder + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-install-${{ github.sha }} + path: ${{ steps.strings.outputs.install-dir }}/ diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-windows.yml similarity index 92% rename from .github/workflows/cmake-multi-platform.yml rename to .github/workflows/cmake-windows.yml index eb29df1..004852b 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-windows.yml @@ -23,28 +23,19 @@ jobs: # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest, windows-latest] + os: [windows-latest] build_type: [Debug, Release] c_compiler: [gcc, clang, cl] include: - os: windows-latest c_compiler: cl cpp_compiler: cl - - os: ubuntu-latest - c_compiler: gcc - cpp_compiler: g++ - - os: ubuntu-latest - c_compiler: clang - cpp_compiler: clang++ - os: windows-latest c_compiler: gcc cpp_compiler: g++ - os: windows-latest c_compiler: clang cpp_compiler: clang++ - exclude: - - os: ubuntu-latest - c_compiler: cl steps: - uses: actions/checkout@v4 @@ -69,6 +60,7 @@ jobs: libxkbcommon-dev libwayland-dev wayland-protocols \ libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev \ libdbus-1-dev libudev-dev + - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. @@ -79,7 +71,6 @@ jobs: -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} - -G "Ninja Multi-Config" - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). From 918ad248df7cdec8c12541d43b8262c8564df10d Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 08:59:45 +0800 Subject: [PATCH 4/8] feat:rename workflow --- .github/workflows/cmake-linux.yml | 2 +- .github/workflows/cmake-windows.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index 1ac9399..1547418 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -1,6 +1,6 @@ # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml -name: CMake on multiple platforms +name: CMake on Linux on: push: diff --git a/.github/workflows/cmake-windows.yml b/.github/workflows/cmake-windows.yml index 004852b..ec5e66b 100644 --- a/.github/workflows/cmake-windows.yml +++ b/.github/workflows/cmake-windows.yml @@ -1,6 +1,6 @@ # This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. # See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml -name: CMake on multiple platforms +name: CMake on Windows on: push: From c3bae73f9f1823c0260eb0031ce19b87f51425b4 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 09:10:25 +0800 Subject: [PATCH 5/8] feat:switch to archlinux for gcc15 --- .github/workflows/cmake-linux.yml | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index 1547418..567ec01 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -10,7 +10,10 @@ on: jobs: build: - runs-on: ${{ matrix.os }} + runs-on: ubuntu-latest + container: + image: archlinux:latest + options: --user root strategy: # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. @@ -23,15 +26,12 @@ jobs: # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - os: [ubuntu-latest] build_type: [Debug, Release] c_compiler: [gcc, clang] include: - - os: ubuntu-latest - c_compiler: gcc + - c_compiler: gcc cpp_compiler: g++ - - os: ubuntu-latest - c_compiler: clang + - c_compiler: clang cpp_compiler: clang++ steps: @@ -43,19 +43,18 @@ jobs: shell: bash run: | echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - echo "install-dir=${{ github.workspace }}/install/${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" + echo "install-dir=${{ github.workspace }}/install/archlinux-latest-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" - name: Install SDL windowing deps (Linux) run: | - sudo apt-get update - sudo apt-get install -y --no-install-recommends \ - build-essential pkg-config cmake ninja-build \ - libasound2-dev libpulse-dev libaudio-dev libjack-dev \ - libx11-dev libxext-dev libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev libxtst-dev \ - libxkbcommon-dev libwayland-dev wayland-protocols \ - libdrm-dev libgbm-dev libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev \ - libdbus-1-dev libudev-dev + pacman -Syu --noconfirm + pacman -S --noconfirm --needed \ + base-devel cmake ninja pkgconf gcc clang \ + alsa-lib jack libpulse \ + xorgproto libx11 libxext libxrandr libxcursor libxfixes libxi libxss libxtst \ + libxkbcommon wayland wayland-protocols \ + libdrm mesa mesa-utils - name: Configure CMake # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. @@ -87,5 +86,5 @@ jobs: - name: Upload install folder uses: actions/upload-artifact@v4 with: - name: ${{ matrix.os }}-${{ matrix.c_compiler }}-${{ matrix.build_type }}-install-${{ github.sha }} + name: archlinux-latest-${{ matrix.c_compiler }}-${{ matrix.build_type }}-install-${{ github.sha }} path: ${{ steps.strings.outputs.install-dir }}/ From ffa9a35c4dbf92e578202c885fe4f4ce36761efc Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 10:05:09 +0800 Subject: [PATCH 6/8] fix: change github workspace --- .github/workflows/cmake-linux.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index 567ec01..1e93eb9 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -42,8 +42,8 @@ jobs: id: strings shell: bash run: | - echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - echo "install-dir=${{ github.workspace }}/install/archlinux-latest-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" + echo "build-output-dir=$GITHUB_WORKSPACE/build" >> "$GITHUB_OUTPUT" + echo "install-dir=$GITHUB_WORKSPACE/install/archlinux-latest-${{ matrix.c_compiler }}-${{ matrix.build_type }}" >> "$GITHUB_OUTPUT" - name: Install SDL windowing deps (Linux) @@ -64,7 +64,7 @@ jobs: -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} + -S $GITHUB_WORKSPACE -G "Ninja Multi-Config" - name: Build From 5d00b233d377b3ed8c7b64b91c783f7d33b53614 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 10:06:37 +0800 Subject: [PATCH 7/8] fix: install git in pacman docker --- .github/workflows/cmake-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index 1e93eb9..fc05c2c 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -50,7 +50,7 @@ jobs: run: | pacman -Syu --noconfirm pacman -S --noconfirm --needed \ - base-devel cmake ninja pkgconf gcc clang \ + base-devel cmake ninja pkgconf gcc clang git\ alsa-lib jack libpulse \ xorgproto libx11 libxext libxrandr libxcursor libxfixes libxi libxss libxtst \ libxkbcommon wayland wayland-protocols \ From ae4430d3fa68cd7083761de983dcfaf52852b3c5 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 8 Nov 2025 10:14:31 +0800 Subject: [PATCH 8/8] fix: install python3 in pacman docker --- .github/workflows/cmake-linux.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-linux.yml b/.github/workflows/cmake-linux.yml index fc05c2c..66f82c3 100644 --- a/.github/workflows/cmake-linux.yml +++ b/.github/workflows/cmake-linux.yml @@ -50,7 +50,7 @@ jobs: run: | pacman -Syu --noconfirm pacman -S --noconfirm --needed \ - base-devel cmake ninja pkgconf gcc clang git\ + base-devel cmake ninja pkgconf gcc clang git python3\ alsa-lib jack libpulse \ xorgproto libx11 libxext libxrandr libxcursor libxfixes libxi libxss libxtst \ libxkbcommon wayland wayland-protocols \