diff --git a/.github/actions/setup-vcpkg/action.yml b/.github/actions/setup-vcpkg/action.yml new file mode 100644 index 000000000..0917d8caf --- /dev/null +++ b/.github/actions/setup-vcpkg/action.yml @@ -0,0 +1,46 @@ +name: setup-vcpkg + +description: Bootstrap vcpkg and expose the toolchain file path + +outputs: + root: + description: Path to the vcpkg root + value: ${{ steps.vars.outputs.root }} + toolchain-file: + description: Path to the vcpkg CMake toolchain file + value: ${{ steps.vars.outputs.toolchain_file }} + +runs: + using: composite + steps: + - name: Set vcpkg paths + id: vars + shell: bash + run: | + set -euo pipefail + root="${GITHUB_WORKSPACE}/vcpkg" + echo "root=${root}" >> "${GITHUB_OUTPUT}" + echo "toolchain_file=${root}/scripts/buildsystems/vcpkg.cmake" >> "${GITHUB_OUTPUT}" + + - name: Clone vcpkg + shell: bash + run: | + set -euo pipefail + if [[ ! -d "${GITHUB_WORKSPACE}/vcpkg/.git" ]]; then + git clone https://github.com/microsoft/vcpkg "${GITHUB_WORKSPACE}/vcpkg" + fi + + - name: Bootstrap vcpkg (Windows) + if: runner.os == 'Windows' + shell: pwsh + run: | + $ErrorActionPreference = 'Stop' + & "${env:GITHUB_WORKSPACE}\vcpkg\bootstrap-vcpkg.bat" -disableMetrics + + - name: Bootstrap vcpkg (Unix) + if: runner.os != 'Windows' + shell: bash + run: | + set -euo pipefail + "${GITHUB_WORKSPACE}/vcpkg/bootstrap-vcpkg.sh" -disableMetrics + diff --git a/.github/workflows/.gitignore b/.github/workflows/.gitignore new file mode 100644 index 000000000..284bc6143 --- /dev/null +++ b/.github/workflows/.gitignore @@ -0,0 +1,4 @@ +!/ci-build-linux.yml +!/ci-build-macos.yml +!/ci-build-tools-linux.yml +!/ci-build-windows.yml diff --git a/.github/workflows/branch_rules.yml b/.github/workflows/branch-rules.yml similarity index 99% rename from .github/workflows/branch_rules.yml rename to .github/workflows/branch-rules.yml index ea653c685..04b296388 100644 --- a/.github/workflows/branch_rules.yml +++ b/.github/workflows/branch-rules.yml @@ -1,4 +1,4 @@ -name: branch_rules +name: branch-rules on: pull_request: diff --git a/.github/workflows/ci-build-linux.yml b/.github/workflows/ci-build-linux.yml new file mode 100644 index 000000000..85be3d444 --- /dev/null +++ b/.github/workflows/ci-build-linux.yml @@ -0,0 +1,430 @@ +name: ci-build-linux + +on: + pull_request: + branches: + - dev + - main + types: + - opened + - reopened + - synchronize + - edited + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ci-build-linux-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + build-linux-gcc-debug: + name: build linux gcc debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Linux GCC Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-gcc-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-gcc-debug + + build-linux-gcc-release: + name: build linux gcc release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Linux GCC Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-gcc-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-gcc-release + + build-linux-clang-debug: + name: build linux clang debug + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Linux Clang Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-clang-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-clang-debug + + build-linux-clang-release: + name: build linux clang release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Linux Clang Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-clang-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-clang-release + + test-linux-debug: + name: test linux all tests debug + needs: build-linux-gcc-debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (Linux Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-test-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-test-debug + ctest --test-dir build/linux-test-debug --verbose + + test-linux-release: + name: test linux all tests release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (Linux Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-test-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-test-release + ctest --test-dir build/linux-test-release --verbose + + build-editor-linux-debug: + name: build editor linux debug + needs: build-linux-gcc-debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build editor (Linux Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-debug --target editor + + build-editor-linux-release: + name: build editor linux release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build editor (Linux Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-release --target editor + + build-player-linux-debug: + name: build player linux debug + needs: build-linux-gcc-debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build player (Linux Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-debug --target player + + build-player-linux-release: + name: build player linux release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build player (Linux Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-release --target player + + build-log_server-linux-debug: + name: build log_server linux debug + needs: build-linux-gcc-debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build log_server (Linux Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-debug --target log_server + + build-log_server-linux-release: + name: build log_server linux release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build log_server (Linux Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-release --target log_server + + build-kenzo-linux-debug: + name: build kenzo linux debug + needs: build-linux-gcc-debug + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build kenzo (Linux Debug) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-debug --target kenzo + + build-kenzo-linux-release: + name: build kenzo linux release + needs: build-linux-gcc-debug + if: github.base_ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build kenzo (Linux Release) + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/linux-tools-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/linux-tools-release --target kenzo + + + + + + + + diff --git a/.github/workflows/ci-build-macos.yml b/.github/workflows/ci-build-macos.yml new file mode 100644 index 000000000..084a666f8 --- /dev/null +++ b/.github/workflows/ci-build-macos.yml @@ -0,0 +1,122 @@ +name: ci-build-macos + +on: + pull_request: + branches: + - dev + - main + types: + - opened + - reopened + - synchronize + - edited + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ci-build-macos-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + build-macos-clang-debug: + name: build macos clang debug + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (macOS Clang Debug) + run: | + cmake -B build/macos-clang-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/macos-clang-debug + + build-macos-clang-release: + name: build macos clang release + needs: build-macos-clang-debug + if: github.base_ref == 'main' + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (macOS Clang Release) + run: | + cmake -B build/macos-clang-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/macos-clang-release + + test-macos-debug: + name: test macos all tests debug + needs: build-macos-clang-debug + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (macOS Debug) + run: | + cmake -B build/macos-test-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/macos-test-debug + ctest --test-dir build/macos-test-debug --verbose + + test-macos-release: + name: test macos all tests release + needs: build-macos-clang-debug + if: github.base_ref == 'main' + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (macOS Release) + run: | + cmake -B build/macos-test-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cmake --build build/macos-test-release + ctest --test-dir build/macos-test-release --verbose + + diff --git a/.github/workflows/ci-build-windows.yml b/.github/workflows/ci-build-windows.yml new file mode 100644 index 000000000..8ac7f29d6 --- /dev/null +++ b/.github/workflows/ci-build-windows.yml @@ -0,0 +1,304 @@ +name: ci-build-windows + +on: + pull_request: + branches: + - dev + - main + types: + - opened + - reopened + - synchronize + - edited + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ci-build-windows-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + build-windows-msvc-debug: + name: build windows msvc debug + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Windows MSVC Debug) + run: | + cmake -B build/windows-msvc-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-msvc-debug + + build-windows-msvc-release: + name: build windows msvc release + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Build (Windows MSVC Release) + run: | + cmake -B build/windows-msvc-release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-msvc-release + + build-windows-gcc-debug: + name: build windows gcc debug + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Setup MinGW + uses: egor-tensin/setup-mingw@v2 + + - name: Build (Windows GCC Debug) + run: | + cmake -B build/windows-gcc-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-mingw-dynamic + cmake --build build/windows-gcc-debug + + build-windows-gcc-release: + name: build windows gcc release + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Setup MinGW + uses: egor-tensin/setup-mingw@v2 + + - name: Build (Windows GCC Release) + run: | + cmake -B build/windows-gcc-release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-mingw-dynamic + cmake --build build/windows-gcc-release + + build-windows-clang-debug: + name: build windows clang debug + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Setup Clang + uses: egor-tensin/setup-clang@v1 + + - name: Build (Windows Clang Debug) + run: | + cmake -B build/windows-clang-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-clang-debug + + build-windows-clang-release: + name: build windows clang release + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Setup Clang + uses: egor-tensin/setup-clang@v1 + + - name: Build (Windows Clang Release) + run: | + cmake -B build/windows-clang-release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-clang-release + + test-windows-debug: + name: test windows all tests debug + needs: build-windows-msvc-debug + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET 10 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (Windows Debug) + run: | + cmake -B build/windows-test-debug -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-test-debug + ctest --test-dir build/windows-test-debug --verbose + + test-windows-release: + name: test windows all tests release + needs: build-windows-msvc-debug + if: github.base_ref == 'main' + runs-on: windows-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Setup .NET 10 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: "10.0.x" + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Run tests (Windows Release) + run: | + cmake -B build/windows-test-release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=cl -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" -DVCPKG_TARGET_TRIPLET=x64-windows + cmake --build build/windows-test-release + ctest --test-dir build/windows-test-release --verbose + + + + + + + + + + + diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 000000000..42ad9df7d --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,59 @@ +name: ci-clang-format + +on: + pull_request: + branches: + - dev + - main + types: + - opened + - reopened + - synchronize + - edited + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ci-clang-format-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + format: + name: clang-format + runs-on: ubuntu-latest + steps: + - name: Checkout PR branch + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Run clang-format on engine/src and engine/ffi + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + + mapfile -t files < <(find engine/src engine/ffi \ + -type f \( -name "*.cpp" -o -name "*.hpp" -o -name "*.h" -o -name "*.inl" \) -print | sort) + + if [[ ${#files[@]} -eq 0 ]]; then + echo "No engine files matched formatting filters." + exit 0 + fi + + for file in "${files[@]}"; do + clang-format -i --style=file:.clang-format "$file" + done + + if git diff --quiet -- "${files[@]}"; then + echo "Formatting check passed." + exit 0 + fi + + echo "::error::Formatting changes detected. Run clang-format locally and push the results." + exit 1 diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml new file mode 100644 index 000000000..d8fee9e62 --- /dev/null +++ b/.github/workflows/clang-tidy.yml @@ -0,0 +1,50 @@ +name: ci-clang-tidy + +on: + pull_request: + branches: + - dev + - main + types: + - opened + - reopened + - synchronize + - edited + +permissions: + contents: read + pull-requests: read + +concurrency: + group: ci-clang-tidy-${{ github.event.pull_request.number }} + cancel-in-progress: true + +jobs: + tidy: + name: clang-tidy + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.head_ref }} + fetch-depth: 0 + + - name: Install Nix + uses: cachix/install-nix-action@v30 + + - name: Setup vcpkg + id: vcpkg + uses: ./.github/actions/setup-vcpkg + + - name: Generate compile_commands + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + cmake -B build/clang-tidy -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="${{ steps.vcpkg.outputs.toolchain-file }}" + cp build/clang-tidy/compile_commands.json . + + - name: Run clang-tidy on engine/src + run: | + eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" + bash ./tools/ci/clang_tidy.sh diff --git a/.github/workflows/draft-dev-to-main.yml b/.github/workflows/draft-dev-to-main.yml new file mode 100644 index 000000000..8f4490fd1 --- /dev/null +++ b/.github/workflows/draft-dev-to-main.yml @@ -0,0 +1,103 @@ +name: draft-dev-to-main + +on: + pull_request: + branches: + - dev + types: + - closed + +permissions: + contents: read + pull-requests: write + issues: write + +jobs: + draft: + name: create dev -> main draft + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && github.event.pull_request.base.repo.fork == false && github.event.pull_request.base.repo.full_name == github.repository + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Fetch main and dev + shell: bash + run: | + set -euo pipefail + git fetch origin main dev --prune --tags + + - name: Determine next tag + id: version + shell: bash + run: | + set -euo pipefail + + ahead_count="$(git rev-list --count origin/main..origin/dev)" + if [[ "${ahead_count}" -le 0 ]]; then + echo "dev is not ahead of main; skipping." + echo "create_pr=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + + latest_tag="$(git tag --list "2.*.*" --sort=-version:refname | head -n 1 || true)" + if [[ -z "${latest_tag}" ]]; then + new_tag="2.0.0" + else + IFS='.' read -r major minor patch <<< "${latest_tag}" + minor=$((minor + 1)) + patch=0 + new_tag="${major}.${minor}.${patch}" + fi + + echo "new_tag=${new_tag}" >> "${GITHUB_OUTPUT}" + echo "create_pr=true" >> "${GITHUB_OUTPUT}" + + - name: Create draft PR if missing + if: steps.version.outputs.create_pr == 'true' + uses: actions/github-script@v7 + with: + script: | + const owner = context.repo.owner; + const repo = context.repo.repo; + const tag = "${{ steps.version.outputs.new_tag }}"; + + const existing = await github.rest.pulls.list({ + owner, + repo, + state: "open", + base: "main", + head: `${owner}:dev` + }); + + if (existing.data.length > 0) { + core.info("Open dev -> main PR already exists; skipping."); + return; + } + + const pr = await github.rest.pulls.create({ + owner, + repo, + title: `Toast Engine v${tag}`, + head: "dev", + base: "main", + body: "", + draft: true + }); + + await github.rest.pulls.requestReviewers({ + owner, + repo, + pull_number: pr.data.number, + reviewers: ["ynks"] + }); + + await github.rest.issues.addAssignees({ + owner, + repo, + issue_number: pr.data.number, + assignees: ["ynks"] + }); diff --git a/.github/workflows/release-on-merge.yml b/.github/workflows/release-on-merge.yml new file mode 100644 index 000000000..2cb3fe064 --- /dev/null +++ b/.github/workflows/release-on-merge.yml @@ -0,0 +1,87 @@ +name: release-on-merge + +on: + pull_request: + branches: + - main + types: + - closed + +permissions: + contents: write + +jobs: + release: + name: tag and release + runs-on: ubuntu-latest + if: github.event.pull_request.merged == true && github.event.pull_request.base.repo.fork == false && github.event.pull_request.base.repo.full_name == github.repository + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + persist-credentials: true + + - name: Determine next tag + id: version + shell: bash + env: + HEAD_REF: ${{ github.event.pull_request.head.ref }} + MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }} + run: | + set -euo pipefail + + latest_tag="$(git tag --list "2.*.*" --sort=-version:refname | head -n 1 || true)" + if [[ -z "${latest_tag}" ]]; then + if [[ "${HEAD_REF}" == "dev" ]]; then + new_tag="2.0.0" + else + echo "No existing 2.*.* tags and merge is not dev -> main. Skipping." + echo "create_release=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + else + IFS='.' read -r major minor patch <<< "${latest_tag}" + if [[ "${HEAD_REF}" == "dev" ]]; then + minor=$((minor + 1)) + patch=0 + elif [[ "${HEAD_REF}" == hotfix/* ]]; then + patch=$((patch + 1)) + else + echo "Head ref '${HEAD_REF}' does not match dev or hotfix/*; skipping." + echo "create_release=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + new_tag="${major}.${minor}.${patch}" + fi + + if git rev-parse -q --verify "refs/tags/${new_tag}" > /dev/null; then + echo "Tag ${new_tag} already exists; skipping." + echo "create_release=false" >> "${GITHUB_OUTPUT}" + exit 0 + fi + + echo "new_tag=${new_tag}" >> "${GITHUB_OUTPUT}" + echo "merge_sha=${MERGE_SHA}" >> "${GITHUB_OUTPUT}" + echo "create_release=true" >> "${GITHUB_OUTPUT}" + + - name: Create tag + if: steps.version.outputs.create_release == 'true' + run: | + git tag "${{ steps.version.outputs.new_tag }}" "${{ steps.version.outputs.merge_sha }}" + git push origin "refs/tags/${{ steps.version.outputs.new_tag }}" + + - name: Create GitHub release + if: steps.version.outputs.create_release == 'true' + uses: actions/github-script@v7 + with: + script: | + const tag = "${{ steps.version.outputs.new_tag }}"; + await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: tag, + name: `Toast Engine v${tag}`, + body: "" + }); diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index a1bd59af7..000000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,163 +0,0 @@ -name: tests - -on: - pull_request: - branches: - - dev - types: - - opened - - reopened - - synchronize - - edited - -permissions: - contents: read - pull-requests: read - -concurrency: - group: tests-${{ github.event.pull_request.number }} - cancel-in-progress: true - -jobs: - format: - name: clang-format - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: read - steps: - - name: Checkout PR branch - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 0 - persist-credentials: true - - - name: Install Nix - uses: cachix/install-nix-action@v30 - - - name: Run clang-format - run: | - eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" - bash ./tools/ci/clang_format.sh - - build: - name: build ${{ matrix.os }} - needs: format - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: - - ubuntu-latest - - windows-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 0 - - - name: Setup Nix - if: runner.os == 'Linux' - uses: cachix/install-nix-action@v30 - - - name: Setup xmake - if: runner.os == 'Windows' - uses: xmake-io/github-action-setup-xmake@v1 - - - name: Setup .NET - if: runner.os == 'Windows' - uses: actions/setup-dotnet@v4 - with: - dotnet-version: "10.0.x" - - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - - name: Build (Linux) - if: runner.os == 'Linux' - run: | - eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" - xmake f -m debug - xmake --all - - - name: Build (Windows) - if: runner.os == 'Windows' - run: xmake f -m debug && xmake --all - - test: - name: test ${{ matrix.os }} - needs: build - runs-on: ${{ matrix.os }} - strategy: - fail-fast: true - matrix: - os: - - ubuntu-latest - - windows-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 0 - - - name: Install Nix - if: runner.os == 'Linux' - uses: cachix/install-nix-action@v30 - - - name: Setup xmake - if: runner.os == 'Windows' - uses: xmake-io/github-action-setup-xmake@v1 - - - name: Setup .NET 10 - if: runner.os == 'Windows' - uses: actions/setup-dotnet@v4 - with: - dotnet-version: "10.0.x" - - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - - - name: Run tests (Linux) - if: runner.os == 'Linux' - run: | - eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" - xmake f -m debug - xmake test - - - name: Run tests (Windows) - if: runner.os == 'Windows' - run: | - xmake f -m debug - xmake test - - tidy: - name: clang-tidy - needs: test - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - ref: ${{ github.head_ref }} - fetch-depth: 0 - - - name: Install Nix - uses: cachix/install-nix-action@v30 - - - name: Generate compile_commands - run: | - eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" - xmake project -k compile_commands - - - name: Run clang-tidy - run: | - eval "$(nix --extra-experimental-features 'nix-command flakes' print-dev-env .)" - bash ./tools/ci/clang_tidy.sh - diff --git a/.gitignore b/.gitignore index e948bc731..23f10fc3e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ # Cache files .cache/ -.xmake/ logs/ .DS_Store @@ -14,10 +13,12 @@ logs/ **[Bb]in** **[Oo]bj** **[Tt]arget** +[Oo]ut engine/include/ +vcpkg_installed/ compile_commands.json -CMakeLists.txt +CMakeUserPresets.json **.sln vsxmake**/ vs**/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..2df3a349b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 4.0) +project(engine) + +include(CTest) + +set(CMAKE_CXX_STANDARD 23) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(OUTPUT_ROOT "${CMAKE_SOURCE_DIR}/out") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${OUTPUT_ROOT}") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${OUTPUT_ROOT}") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${OUTPUT_ROOT}") +set(CMAKE_PDB_OUTPUT_DIRECTORY "${OUTPUT_ROOT}") + +foreach(config IN ITEMS Debug Release RelWithDebInfo MinSizeRel) + string(TOUPPER "${config}" config_upper) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${config_upper} "${OUTPUT_ROOT}/${config}") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${config_upper} "${OUTPUT_ROOT}/${config}") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${config_upper} "${OUTPUT_ROOT}/${config}") + set(CMAKE_PDB_OUTPUT_DIRECTORY_${config_upper} "${OUTPUT_ROOT}/${config}") +endforeach() + +add_subdirectory(engine) +add_subdirectory(tools) +add_subdirectory(editor) +add_subdirectory(tests) diff --git a/README.md b/README.md index 902d4458d..173becc6e 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,21 @@ Credits: ## Building Dependencies: -- xmake -- cargo -- dotnet +- cmake 3.25+ +- ninja +- vcpkg (manifest mode) +- cargo (optional, for Rust tools) +- dotnet 10 (optional, for player) +Configure + build with vcpkg toolchain (CI bootstraps vcpkg automatically): ``` -xmake run toast.editor +cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=/scripts/buildsystems/vcpkg.cmake +cmake --build build ``` -Generating documentation can be done by simply +Run tests: ``` -xmake documentation +ctest --test-dir build ``` -To use this engine in a project, include it as a submodule and go to Get Started on the documentation \ No newline at end of file +To use this engine in a project, include it as a submodule and go to Get Started on the documentation diff --git a/cmake/clang_format.cmake b/cmake/clang_format.cmake new file mode 100644 index 000000000..8fbe49c1c --- /dev/null +++ b/cmake/clang_format.cmake @@ -0,0 +1,33 @@ +if(NOT DEFINED ROOT_DIR) + message(FATAL_ERROR "clang_format: ROOT_DIR not set") +endif() + +set(SRC_DIR "${ROOT_DIR}/src") +set(FFI_DIR "${ROOT_DIR}/ffi") + +if(NOT IS_DIRECTORY "${SRC_DIR}") + message(STATUS "clang_format: src dir not found: ${SRC_DIR}") + return() +endif() + +find_program(CLANG_FORMAT NAMES clang-format) +if(NOT CLANG_FORMAT) + message(WARNING "clang_format: clang-format not found; skipping formatting") + return() +endif() + +file(GLOB_RECURSE FORMAT_FILES + "${SRC_DIR}/*.h" "${SRC_DIR}/*.hpp" "${SRC_DIR}/*.cpp" + "${FFI_DIR}/*.h" "${FFI_DIR}/*.hpp" "${FFI_DIR}/*.cpp" +) + +foreach(fmt_file IN LISTS FORMAT_FILES) + execute_process( + COMMAND "${CLANG_FORMAT}" -i "${fmt_file}" + RESULT_VARIABLE fmt_result + ) + if(NOT fmt_result EQUAL 0) + message(WARNING "clang_format: clang-format failed for ${fmt_file}") + endif() +endforeach() + diff --git a/cmake/sync_api_headers.cmake b/cmake/sync_api_headers.cmake new file mode 100644 index 000000000..3b802090e --- /dev/null +++ b/cmake/sync_api_headers.cmake @@ -0,0 +1,51 @@ +if(NOT DEFINED ROOT_DIR) + message(FATAL_ERROR "sync_api_headers: ROOT_DIR not set") +endif() + +set(SRC_DIR "${ROOT_DIR}/src") +set(INCLUDE_DIR "${ROOT_DIR}/include") + +set(NOTICE [=[// ============================================================ +// AUTO-GENERATED FILE - DO NOT MODIFY DIRECTLY +// Changes will not persist +// ============================================================]=]) + +if(NOT IS_DIRECTORY "${SRC_DIR}") + message(STATUS "sync_api_headers: src dir not found: ${SRC_DIR}") + return() +endif() + +if(EXISTS "${INCLUDE_DIR}") + file(REMOVE_RECURSE "${INCLUDE_DIR}") +endif() +file(MAKE_DIRECTORY "${INCLUDE_DIR}") + +file(GLOB_RECURSE HEADER_FILES "${SRC_DIR}/*.h" "${SRC_DIR}/*.hpp") +foreach(header IN LISTS HEADER_FILES) + file(READ "${header}" CONTENT) + if(CONTENT MATCHES "TOAST_API") + file(RELATIVE_PATH REL_PATH "${SRC_DIR}" "${header}") + set(dst_path "${INCLUDE_DIR}/${REL_PATH}") + get_filename_component(dst_dir "${dst_path}" DIRECTORY) + file(MAKE_DIRECTORY "${dst_dir}") + file(WRITE "${dst_path}" "${NOTICE}\n${CONTENT}") + + string(REGEX MATCHALL "#include[ \t]+\"([^\"]+\\.inl)\"" INL_MATCHES "${CONTENT}") + if(INL_MATCHES) + get_filename_component(header_dir "${header}" DIRECTORY) + foreach(inl_match IN LISTS INL_MATCHES) + string(REGEX REPLACE "^#include[ \t]+\"([^\"]+\\.inl)\".*" "\\1" inl_rel "${inl_match}") + set(inl_src "${header_dir}/${inl_rel}") + if(EXISTS "${inl_src}") + file(RELATIVE_PATH inl_rel_path "${SRC_DIR}" "${inl_src}") + set(inl_dst "${INCLUDE_DIR}/${inl_rel_path}") + get_filename_component(inl_dst_dir "${inl_dst}" DIRECTORY) + file(MAKE_DIRECTORY "${inl_dst_dir}") + file(READ "${inl_src}" inl_content) + file(WRITE "${inl_dst}" "${NOTICE}\n${inl_content}") + endif() + endforeach() + endif() + endif() +endforeach() + diff --git a/editor/App.axaml b/editor/App.axaml new file mode 100644 index 000000000..dd17fe598 --- /dev/null +++ b/editor/App.axaml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/editor/App.axaml.cs b/editor/App.axaml.cs new file mode 100644 index 000000000..3333cc406 --- /dev/null +++ b/editor/App.axaml.cs @@ -0,0 +1,31 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +using System.Linq; +using Avalonia.Markup.Xaml; +using editor.ViewModels; +using editor.Views; + +namespace editor; + +public partial class App : Application +{ + public override void Initialize() + { + AvaloniaXamlLoader.Load(this); + } + + public override void OnFrameworkInitializationCompleted() + { + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + desktop.MainWindow = new MainWindow + { + DataContext = new MainWindowViewModel(), + }; + } + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file diff --git a/editor/Assets/avalonia-logo.ico b/editor/Assets/avalonia-logo.ico new file mode 100644 index 000000000..f7da8bb58 Binary files /dev/null and b/editor/Assets/avalonia-logo.ico differ diff --git a/editor/CMakeLists.txt b/editor/CMakeLists.txt new file mode 100644 index 000000000..9988c6c3c --- /dev/null +++ b/editor/CMakeLists.txt @@ -0,0 +1,22 @@ +project(editor NONE) + +set(CSHARP_PROJECT "${CMAKE_CURRENT_SOURCE_DIR}/editor.csproj") +set(CSHARP_ASSEMBLY_NAME "editor") + +set(DOTNET_CONFIG "$,Debug,Release>") + +find_program(DOTNET_EXECUTABLE dotnet REQUIRED) +message(STATUS "Found dotnet: ${DOTNET_EXECUTABLE}") +message(STATUS "Build configuration: ${DOTNET_CONFIG}") +message(STATUS "Output directory: ${OUTPUT_ROOT}/$") + +add_custom_target(editor ALL + COMMAND ${DOTNET_EXECUTABLE} build + "${CSHARP_PROJECT}" + --configuration ${DOTNET_CONFIG} + --output "${OUTPUT_ROOT}/$" + --nologo + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "[dotnet] Building ${CSHARP_ASSEMBLY_NAME} (${DOTNET_CONFIG})..." + VERBATIM +) diff --git a/editor/Program.cs b/editor/Program.cs new file mode 100644 index 000000000..be9371f91 --- /dev/null +++ b/editor/Program.cs @@ -0,0 +1,24 @@ +using Avalonia; +using System; + +namespace editor; + +sealed class Program +{ + // Initialization code. Don't use any Avalonia, third-party APIs or any + // SynchronizationContext-reliant code before AppMain is called: things aren't initialized + // yet and stuff might break. + [STAThread] + public static void Main(string[] args) => BuildAvaloniaApp() + .StartWithClassicDesktopLifetime(args); + + // Avalonia configuration, don't remove; also used by visual designer. + public static AppBuilder BuildAvaloniaApp() + => AppBuilder.Configure() + .UsePlatformDetect() +#if DEBUG + .WithDeveloperTools() +#endif + .WithInterFont() + .LogToTrace(); +} diff --git a/editor/ViewLocator.cs b/editor/ViewLocator.cs new file mode 100644 index 000000000..6701c6b86 --- /dev/null +++ b/editor/ViewLocator.cs @@ -0,0 +1,37 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using Avalonia.Controls; +using Avalonia.Controls.Templates; +using editor.ViewModels; + +namespace editor; + +/// +/// Given a view model, returns the corresponding view if possible. +/// +[RequiresUnreferencedCode( + "Default implementation of ViewLocator involves reflection which may be trimmed away.", + Url = "https://docs.avaloniaui.net/docs/concepts/view-locator")] +public class ViewLocator : IDataTemplate +{ + public Control? Build(object? param) + { + if (param is null) + return null; + + var name = param.GetType().FullName!.Replace("ViewModel", "View", StringComparison.Ordinal); + var type = Type.GetType(name); + + if (type != null) + { + return (Control)Activator.CreateInstance(type)!; + } + + return new TextBlock { Text = "Not Found: " + name }; + } + + public bool Match(object? data) + { + return data is ViewModelBase; + } +} diff --git a/editor/ViewModels/MainWindowViewModel.cs b/editor/ViewModels/MainWindowViewModel.cs new file mode 100644 index 000000000..8276a9f83 --- /dev/null +++ b/editor/ViewModels/MainWindowViewModel.cs @@ -0,0 +1,6 @@ +namespace editor.ViewModels; + +public partial class MainWindowViewModel : ViewModelBase +{ + public string Greeting { get; } = "Welcome to Avalonia!"; +} diff --git a/editor/ViewModels/ViewModelBase.cs b/editor/ViewModels/ViewModelBase.cs new file mode 100644 index 000000000..17db38486 --- /dev/null +++ b/editor/ViewModels/ViewModelBase.cs @@ -0,0 +1,7 @@ +using CommunityToolkit.Mvvm.ComponentModel; + +namespace editor.ViewModels; + +public abstract class ViewModelBase : ObservableObject +{ +} diff --git a/editor/Views/MainWindow.axaml b/editor/Views/MainWindow.axaml new file mode 100644 index 000000000..0f83f154b --- /dev/null +++ b/editor/Views/MainWindow.axaml @@ -0,0 +1,20 @@ + + + + + + + + + + diff --git a/editor/Views/MainWindow.axaml.cs b/editor/Views/MainWindow.axaml.cs new file mode 100644 index 000000000..42196da81 --- /dev/null +++ b/editor/Views/MainWindow.axaml.cs @@ -0,0 +1,11 @@ +using Avalonia.Controls; + +namespace editor.Views; + +public partial class MainWindow : Window +{ + public MainWindow() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/editor/app.manifest b/editor/app.manifest new file mode 100644 index 000000000..235e2334e --- /dev/null +++ b/editor/app.manifest @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/editor/editor.csproj b/editor/editor.csproj new file mode 100644 index 000000000..de8f329a7 --- /dev/null +++ b/editor/editor.csproj @@ -0,0 +1,26 @@ + + + WinExe + net10.0 + enable + app.manifest + true + + + + + + + + + + + + + + None + All + + + + diff --git a/editor/xmake.lua b/editor/xmake.lua deleted file mode 100644 index a167fcad7..000000000 --- a/editor/xmake.lua +++ /dev/null @@ -1,31 +0,0 @@ --- Generates a bin path following the default build/p/a/m structure --- local get_path = function() --- local host = get_config("plat") --- local arch = get_config("arch") --- local mode = get_config("mode") --- return path.join("build", host, arch, mode) --- end - --- target("toast.editor", function() --- set_kind("phony") - --- on_build(function(target) --- cprint("${cyan bright}[toast.editor] building...") - --- local args = { --- "publish", --- "editor/editor.csproj", --- "-c", (mode == "debug") and "Debug" or "Release", --- "-o", get_path() --- } --- os.execv("dotnet", args) --- end) - --- on_run(function() --- if is_host("windows") then --- os.exec(path.join(get_path(), "editor.exe")) --- else --- os.exec(path.join(get_path(), "editor")) --- end --- end) --- end) diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt new file mode 100644 index 000000000..3e49c4b5c --- /dev/null +++ b/engine/CMakeLists.txt @@ -0,0 +1,40 @@ +project(toast_engine C CXX) + +find_package(asio CONFIG REQUIRED) +find_package(SDL3 CONFIG REQUIRED) + +file(GLOB_RECURSE SOURCE "src/*.cpp") +add_library(toast_engine SHARED ${SOURCE}) + +target_include_directories(toast_engine + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${CMAKE_CURRENT_SOURCE_DIR}/external + ${CMAKE_CURRENT_SOURCE_DIR} + PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/ffi +) + +target_link_libraries(toast_engine + PRIVATE + asio::asio + SDL3::SDL3 +) + +target_compile_definitions(toast_engine PRIVATE TOAST_EXPORT) +target_precompile_headers(toast_engine PRIVATE pch.h) + +add_custom_target(clang_format + COMMAND ${CMAKE_COMMAND} -DROOT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/clang_format.cmake + COMMENT "Formatting sources" + VERBATIM +) + +add_custom_target(sync_api_headers + COMMAND ${CMAKE_COMMAND} -DROOT_DIR=${CMAKE_CURRENT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/sync_api_headers.cmake + COMMENT "Syncing public headers" + VERBATIM +) +add_dependencies(sync_api_headers clang_format) +add_dependencies(toast_engine sync_api_headers) diff --git a/engine/pch.h b/engine/pch.h new file mode 100644 index 000000000..e021e921d --- /dev/null +++ b/engine/pch.h @@ -0,0 +1,32 @@ +/** + * @file pch.h + * @author Dante Harper + */ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/engine/src/toast/application.hpp b/engine/src/toast/application.hpp index 593b9fc44..8b7480a9b 100644 --- a/engine/src/toast/application.hpp +++ b/engine/src/toast/application.hpp @@ -9,7 +9,10 @@ namespace toast { -class TOAST_API IApplication { +class IApplication { +public: + virtual ~IApplication() = default; + virtual void begin() = 0; virtual void tick() = 0; virtual void destroy() = 0; diff --git a/engine/src/toast/events/event.cpp b/engine/src/toast/events/event.cpp index bbf9dd4e8..ea986bb23 100644 --- a/engine/src/toast/events/event.cpp +++ b/engine/src/toast/events/event.cpp @@ -12,6 +12,11 @@ namespace event { +std::unordered_map EventSystem::event_data; +std::mutex EventSystem::pool_mutex; +std::unordered_map> EventSystem::unsubscribe_map; +std::vector> EventSystem::deletion_queue; + namespace { struct Pool { alignas(64) std::array buffer; @@ -37,12 +42,12 @@ auto allocate(std::size_t size, std::size_t align) noexcept -> void* { void pollEvents() noexcept { // delete callbacks - _detail::deletion_queue.clear(); + EventSystem::deletion_queue.clear(); // swap memory pool uint32_t idx; { - std::scoped_lock _(_detail::mutex); + std::scoped_lock _(EventSystem::pool_mutex); idx = index; index = (index + 1) % pools.size(); } diff --git a/engine/src/toast/events/event.hpp b/engine/src/toast/events/event.hpp index 23fc50fb0..ef1eaf3f0 100644 --- a/engine/src/toast/events/event.hpp +++ b/engine/src/toast/events/event.hpp @@ -10,6 +10,8 @@ */ #pragma once +#include "toast/log.hpp" + #include #include #include @@ -17,15 +19,16 @@ #include #include #include -#include +// TODO: #include #include #include #include -#include #include namespace event { +struct EventSystem; // Forward declaration + /// @brief dispatches all queued events to their callbacks /// @note Not thread-safe. Should be only ever called from a single thread / main thread void TOAST_API pollEvents() noexcept; @@ -38,27 +41,16 @@ struct TOAST_API IEvent { virtual ~IEvent() = default; #ifdef DEBUG - std::stacktrace stacktrace; + // std::stacktrace stacktrace; #endif private: - friend void event::pollEvents() noexcept; + friend void TOAST_API event::pollEvents() noexcept; virtual void notify() noexcept = 0; }; -/// @brief mutex for the event system -inline std::mutex mutex; - -/// @brief vtable for unsubscribing callbacks -inline std::unordered_map> unsubscribe_map; - -/// @brief callbacks will be cleaned up only before pollEvents -/// @note unique pointers have the option of storing a pointer to the function that deletes the object -/// so thats how i implement the deletion_queue -inline std::vector> deletion_queue; - /// @brief allocates memory in the event queue pool -auto allocate(std::size_t size, std::size_t align) noexcept -> void*; +auto TOAST_API allocate(std::size_t size, std::size_t align) noexcept -> void*; } /// @brief queue's up an event @@ -66,7 +58,7 @@ auto allocate(std::size_t size, std::size_t align) noexcept -> void*; /// @param args arguments for the constructor template requires std::is_base_of_v<_detail::IEvent, T> -void TOAST_API send(Args&&... args) noexcept; +void send(Args&&... args) noexcept; /// @class Event /// @brief Base class for all events. Derive your event type as `struct Derived : Event`. @@ -91,20 +83,18 @@ void TOAST_API send(Args&&... args) noexcept; /// the callback itself /// template -struct TOAST_API Event : _detail::IEvent { +struct Event : _detail::IEvent { friend class Listener; + friend struct EventSystem; /// @brief callbacks that return 'true' are consumed and do not propogate using callback_t = std::move_only_function; - using iterator_t = std::multimap::iterator; + using iterator_t = std::multimap>::iterator; private: - static inline struct G { - G() noexcept; - std::multimap> callbacks; - std::mutex mutex; - std::vector processing; - bool cached; - } g; + static inline struct Registrar { + Registrar(); + bool registered; + } registrar; /// @brief registers a callback to the event callbacks /// @param priority higher number callbacks first @@ -119,6 +109,49 @@ struct TOAST_API Event : _detail::IEvent { void notify() noexcept override; }; +struct TOAST_API EventSystem { + struct EventInfo { + std::mutex mutex; + std::multimap> callbacks; + std::vector processing; + bool cached = false; + }; + + /// @brief callback map for each type of event + static std::unordered_map event_data; + + /// @brief mutex for the event system pool + static std::mutex pool_mutex; + + /// @brief vtable for unsubscribing callbacks + static std::unordered_map> unsubscribe_map; + + /// @brief callbacks will be cleaned up only before pollEvents + /// @note unique pointers have the option of storing a pointer to the function that deletes the object + /// so thats how i implement the deletion_queue + static std::vector> deletion_queue; + + template + static void registerEvent() { + static_assert(std::is_base_of_v, T>, "CONTRACT VIOLATION: You Must Inhert as 'struct Derived : Event'"); + if (event_data.contains(typeid(T))) { + TOAST_INFO("Events", "Event type {} already registered (Windows Is Shit)", typeid(T).name()); + return; + } + TOAST_INFO("Events", "Registering Event Type: {}", typeid(T).name()); + event_data.emplace( + std::piecewise_construct, + std::forward_as_tuple(typeid(T)), + std::forward_as_tuple() // This calls the EventInfo() constructor + ); + + EventSystem::unsubscribe_map.emplace(typeid(T), [](const std::any& iter) { + auto it = std::any_cast::iterator_t>(iter); + Event::unsubscribe(it); + }); + } +}; + } #include "event.inl" diff --git a/engine/src/toast/events/event.inl b/engine/src/toast/events/event.inl index 3eb96684e..e5202fc1c 100644 --- a/engine/src/toast/events/event.inl +++ b/engine/src/toast/events/event.inl @@ -8,33 +8,32 @@ namespace event { template -Event::G::G() noexcept { - static_assert(std::is_base_of_v, T>, "CONTRACT VIOLATION: You Must Inhert as 'struct Derived : Event'"); - // add function to the Event vtable - _detail::unsubscribe_map.emplace(typeid(T), [](std::any iter) { - auto it = std::any_cast(iter); - unsubscribe(it); - }); +Event::Registrar::Registrar() : registered(true) { + EventSystem::registerEvent(); } template auto Event::subscribe(char priority, callback_t&& callback) noexcept -> iterator_t { + (void)registrar.registered; auto cb = new callback_t(std::move(callback)); + auto& g = EventSystem::event_data[typeid(T)]; { std::scoped_lock _(g.mutex); g.cached = false; - return g.callbacks.emplace(priority, cb); + return g.callbacks.emplace(priority, static_cast(cb)); } } template void Event::unsubscribe(iterator_t it) noexcept { + (void)registrar.registered; + auto& g = EventSystem::event_data[typeid(T)]; { std::scoped_lock _(g.mutex); auto deleter = [](void* p) { delete static_cast*>(p); }; - _detail::deletion_queue.emplace_back((*it).second, deleter); + EventSystem::deletion_queue.emplace_back((*it).second, deleter); g.cached = false; g.callbacks.erase(it); } @@ -42,6 +41,9 @@ void Event::unsubscribe(iterator_t it) noexcept { template void Event::notify() noexcept { + (void)registrar.registered; + + auto& g = EventSystem::event_data[typeid(T)]; { // build cached list of all the callbacks in order // locks mutex for the shortest period possible @@ -58,7 +60,7 @@ void Event::notify() noexcept { // disptaches all of the callbacks for (auto& callback : g.processing) { - bool handled = (*callback)(static_cast(*this)); + bool handled = (*static_cast(callback))(static_cast(*this)); if (handled) { return; } @@ -72,12 +74,12 @@ void send(Args&&... args) noexcept { TOAST_INFO("Events", "Sending Event: {}", typeid(T).name()); // Allocate and enqueue event { - std::scoped_lock _(_detail::mutex); + std::scoped_lock _(EventSystem::pool_mutex); void* memory = _detail::allocate(sizeof(T), alignof(T)); assert(memory); _detail::IEvent* event = new (memory) T(std::forward(args)...); #ifdef DEBUG - event->stacktrace = std::stacktrace::current(1); + // TODO: event->stacktrace = std::stacktrace::current(1); #endif } } diff --git a/engine/src/toast/events/listener.cpp b/engine/src/toast/events/listener.cpp index 9a998c215..10dbc22a7 100644 --- a/engine/src/toast/events/listener.cpp +++ b/engine/src/toast/events/listener.cpp @@ -8,9 +8,13 @@ Listener::Listener() { m.enabled = true; } +Listener::Listener(bool state) { + m.enabled = state; +} + Listener::~Listener() { for (auto& [type, name, callback] : m.callbacks) { - _detail::unsubscribe_map[type](callback); + EventSystem::unsubscribe_map[type](callback); } } @@ -22,4 +26,5 @@ void Listener::enabled(bool state) { auto Listener::enabled() const -> bool { return m.enabled; } + } diff --git a/engine/src/toast/events/listener.hpp b/engine/src/toast/events/listener.hpp index 19ccc35c7..348440ee8 100644 --- a/engine/src/toast/events/listener.hpp +++ b/engine/src/toast/events/listener.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -49,12 +50,15 @@ class TOAST_API Listener { public: Listener(); + + Listener(bool state); + ~Listener(); /// @brief unsubscribes every event in type TEvent with that name /// @param name event callback name/s to remove template - void unsubscribe(std::string name) noexcept; + void unsubscribe(std::string_view name) noexcept; /// @brief subscribes a callback to an TEvent /// @param name of the callback diff --git a/engine/src/toast/events/listener.inl b/engine/src/toast/events/listener.inl index 3d3a7ace3..cdd3f21cc 100644 --- a/engine/src/toast/events/listener.inl +++ b/engine/src/toast/events/listener.inl @@ -7,7 +7,7 @@ namespace event { template -void Listener::unsubscribe(std::string name) noexcept { +void Listener::unsubscribe(std::string_view name) noexcept { TOAST_TRACE("Events", "Unsubscribing Callback {} to {}", name, typeid(TEvent).name()); std::erase_if(m.callbacks, [&](auto& callback) { auto& [type, sub_name, any] = callback; diff --git a/engine/src/toast/thread_pool.cpp b/engine/src/toast/thread_pool.cpp index 28ac0e95c..f5a893911 100644 --- a/engine/src/toast/thread_pool.cpp +++ b/engine/src/toast/thread_pool.cpp @@ -1,5 +1,7 @@ #include "thread_pool.hpp" +#include "log.hpp" + namespace toast { ThreadPool::ThreadPool(size_t size) { @@ -13,7 +15,7 @@ ThreadPool::ThreadPool(size_t size) { for (size_t i = 0; i < target_thread_num; ++i) { m.workers.emplace_back(&ThreadPool::threadLoop, this); } - // TODO: TOAST_TRACE("Created thread pool with {0} workers", target_thread_num); + TOAST_INFO("ThreadPool", "Created thread pool with {0} workers", target_thread_num); } void ThreadPool::queueJob(std::function&& job) { @@ -34,8 +36,14 @@ void ThreadPool::destroy() { } m.job_available.notify_all(); + for (auto& worker : m.workers) { + if (worker.joinable()) { + worker.join(); + } + } + m.workers.clear(); - // TODO: TOAST_TRACE("Destroyed thread pool"); + TOAST_INFO("ThreadPool", "Destroyed thread pool"); } auto ThreadPool::busy() -> bool { diff --git a/engine/src/toast/thread_pool.hpp b/engine/src/toast/thread_pool.hpp index 6bddd1b94..1c6662326 100644 --- a/engine/src/toast/thread_pool.hpp +++ b/engine/src/toast/thread_pool.hpp @@ -55,7 +55,7 @@ class ThreadPool { std::mutex queue_mutex; ///< Mutex protecting the job queue std::condition_variable job_available; ///< Notified when a job is enqueued or stop is requested std::condition_variable all_done; ///< Notified when activeJobs hits 0 and queue is empty - std::vector workers; ///< Worker threads (auto-join on destruction) + std::vector workers; ///< Worker threads (auto-join on destruction) std::queue> jobs; ///< Pending job queue } m; diff --git a/engine/xmake.lua b/engine/xmake.lua deleted file mode 100644 index c39a841ff..000000000 --- a/engine/xmake.lua +++ /dev/null @@ -1,94 +0,0 @@ ----@diagnostic disable: undefined-field, undefined-global, param-type-mismatch -add_requires("asio 1.36.0") -- networking - -target("toast.engine", function() - set_kind("shared") - add_includedirs(".", "src", "external", { public = false }) - add_includedirs("include", { public = true }) - add_defines("TOAST_EXPORT") - add_rpathdirs("$ORIGIN") - - add_files("**.cpp") - add_headerfiles("src/(**.hpp)", { public = false, extra = { check = true } }) - add_headerfiles("ffi/(**.h)", "include/toast/(**.hpp)", { prefixdir = "toast", extra = { check = true } }) - - -- External libraries go here -x - add_packages("asio") - add_ldflags("-lstdc++exp", { tools = { "clang", "gcc" }, public = true }) -- adds library for stacktrace - - -- Apply clang-format rule - add_rules("clang-format") - add_rules("sync-headers") - - if is_plat("linux") then - add_syslinks("pthread") - add_shflags("-Wl,--no-as-needed") - end -end) - - - - - --- Include Folder Generation -rule("sync-headers") ----@diagnostic disable-next-line: unused-local -before_build(function(target) - import("core.base.option") - - local base_dir = os.scriptdir() - local src_dir = path.join(base_dir, "src") - local dst_dir = path.join(base_dir, "include") - - -- Define the header you want to append - local notice = [[ -// ============================================================ -// AUTO-GENERATED FILE - DO NOT MODIFY DIRECTLY -// Changes will not persist -// ============================================================ -]] - - if not os.isdir(src_dir) then return end - if os.exists(dst_dir) then os.rm(dst_dir) end - os.mkdir(dst_dir) - - local count = 0 - local all_files = table.join(os.files(path.join(src_dir, "**.h")), os.files(path.join(src_dir, "**.hpp"))) - - for _, filepath in ipairs(all_files) do - local content = io.readfile(filepath) - - if content and content:find("TOAST_API", 1, true) then - -- Determine destination path while preserving subfolder structure - local rel_path = path.relative(filepath, src_dir) - local dst_path = path.join(dst_dir, rel_path) - - -- Ensure the subfolder exists in the destination - os.mkdir(path.directory(dst_path)) - - -- Write notice + content to the new file - io.writefile(dst_path, notice .. "\n" .. content) - count = count + 1 - - -- Scan for and copy .inl dependencies - for inl_include in content:gmatch('#include%s+"([^"]+%.inl)"') do - local current_dir = path.directory(filepath) - local inl_src_path = path.join(current_dir, inl_include) - - if os.isfile(inl_src_path) then - local inl_rel_path = path.relative(inl_src_path, src_dir) - local inl_dst_path = path.join(dst_dir, inl_rel_path) - - local inl_content = io.readfile(inl_src_path) - os.mkdir(path.directory(inl_dst_path)) - io.writefile(inl_dst_path, notice .. "\n" .. inl_content) - end - end - end - end - - if count > 0 then - cprint("${green}[sync-headers]: ${reset}Synced API") - end -end) -rule_end() diff --git a/flake.nix b/flake.nix index 8bb16b70d..060e82346 100644 --- a/flake.nix +++ b/flake.nix @@ -21,12 +21,14 @@ { devShells.${system}.default = pkgs.mkShell { nativeBuildInputs = with pkgs; [ - xmake + cmake + ninja gdb valgrind rustup protobuf pkg-config + vcpkg dotnet-sdk clang-tools rust-analyzer diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..88c47c425 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,36 @@ +include(CTest) + +if (BUILD_TESTING) + file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") + list(REMOVE_ITEM TEST_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/test_runner.cpp") + + add_executable(toast_tests ${TEST_SOURCES} "${CMAKE_CURRENT_SOURCE_DIR}/test_runner.cpp") + target_include_directories(toast_tests BEFORE PRIVATE ${CMAKE_SOURCE_DIR}/engine/src) + target_include_directories(toast_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + target_link_libraries(toast_tests PRIVATE toast_engine) + target_compile_definitions(toast_tests PRIVATE UNIT_TESTING) + + if (NOT WIN32) + target_link_libraries(toast_tests PRIVATE stdc++exp) + elseif (WIN32 AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + target_link_libraries(toast_tests PRIVATE stdc++exp) + endif() + + foreach(test_src IN LISTS TEST_SOURCES) + file(RELATIVE_PATH relpath "${CMAKE_CURRENT_SOURCE_DIR}" "${test_src}") + string(REPLACE "\\" "/" relpath "${relpath}") + get_filename_component(rel_dir "${relpath}" DIRECTORY) + get_filename_component(test_name "${relpath}" NAME_WE) + + if (NOT rel_dir STREQUAL "") + set(test_case "${rel_dir}/${test_name}") + else() + set(test_case "${test_name}") + endif() + + add_test(NAME ${test_case} COMMAND toast_tests --test ${test_case}) + if (NOT rel_dir STREQUAL "") + set_tests_properties(${test_case} PROPERTIES LABELS "${rel_dir}") + endif() + endforeach() +endif() diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/tests/events/01-basic.cpp b/tests/events/01-basic.cpp index 451e6fb1a..075804c72 100644 --- a/tests/events/01-basic.cpp +++ b/tests/events/01-basic.cpp @@ -1,11 +1,13 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct BasicEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/01-basic", test_events_01_basic) { event::Listener listener; bool called = false; listener.subscribe([&called](BasicEvent& e) { called = true; }); @@ -14,5 +16,4 @@ auto main() -> int { event::pollEvents(); assert(called); - return 0; } diff --git a/tests/events/02-priority.cpp b/tests/events/02-priority.cpp index 32ecac29a..1f7cb7f3a 100644 --- a/tests/events/02-priority.cpp +++ b/tests/events/02-priority.cpp @@ -1,10 +1,12 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include #include -auto main() -> int { +TOAST_TEST_NAMED("events", "events/02-priority", test_events_02_priority) { struct PriorityEvent : event::Event { }; event::Listener listener; @@ -23,6 +25,4 @@ auto main() -> int { assert(order[0] == 3); assert(order[1] == 1); assert(order[2] == 2); - - return 0; } diff --git a/tests/events/03-consume.cpp b/tests/events/03-consume.cpp index 035ae67db..cdb16cca8 100644 --- a/tests/events/03-consume.cpp +++ b/tests/events/03-consume.cpp @@ -1,11 +1,13 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct ConsumeEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/03-consume", test_events_03_consume) { event::Listener listener; bool high_called = false; bool low_called = false; @@ -25,6 +27,4 @@ auto main() -> int { assert(high_called); assert(!low_called); - - return 0; } diff --git a/tests/events/04-named.cpp b/tests/events/04-named.cpp index aae5e707b..c7447af05 100644 --- a/tests/events/04-named.cpp +++ b/tests/events/04-named.cpp @@ -1,12 +1,13 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include -#include struct NamedEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/04-named", test_events_04_named) { event::Listener listener; int called = 0; @@ -21,6 +22,4 @@ auto main() -> int { event::send(); event::pollEvents(); assert(called == 1); // Should still be 1 because it's unsubscribed - - return 0; } diff --git a/tests/events/05-arguments.cpp b/tests/events/05-arguments.cpp index de47348e8..5729969e8 100644 --- a/tests/events/05-arguments.cpp +++ b/tests/events/05-arguments.cpp @@ -1,6 +1,8 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include #include #include @@ -12,7 +14,7 @@ struct ArgEvent : event::Event { ArgEvent(int v, std::string m) : value(v), message(std::move(m)) { } }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/05-arguments", test_events_05_arguments) { event::Listener listener; int received_value = 0; std::string received_message; @@ -28,6 +30,4 @@ auto main() -> int { assert(received_value == 42); assert(received_message == "hello event"); - - return 0; } diff --git a/tests/events/06-nested.cpp b/tests/events/06-nested.cpp index b1e0eefd2..190814164 100644 --- a/tests/events/06-nested.cpp +++ b/tests/events/06-nested.cpp @@ -1,13 +1,15 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct EventA : event::Event { }; struct EventB : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/06-nested", test_events_06_nested) { event::Listener listener; bool b_called = false; @@ -21,6 +23,4 @@ auto main() -> int { event::pollEvents(); // Dispatches event_b assert(b_called); - - return 0; } diff --git a/tests/events/07-lifecycle.cpp b/tests/events/07-lifecycle.cpp index b146f4400..a7a155d55 100644 --- a/tests/events/07-lifecycle.cpp +++ b/tests/events/07-lifecycle.cpp @@ -1,11 +1,13 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct LifecycleEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/07-lifecycle", test_events_07_lifecycle) { int called = 0; { @@ -20,6 +22,4 @@ auto main() -> int { event::send(); event::pollEvents(); assert(called == 1); // should still be 1 if it unsubscribed correctly - - return 0; } diff --git a/tests/events/08-multiple.cpp b/tests/events/08-multiple.cpp index fa0426138..90238e4e7 100644 --- a/tests/events/08-multiple.cpp +++ b/tests/events/08-multiple.cpp @@ -1,13 +1,14 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct EventOne : event::Event { }; - struct EventTwo : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/08-multiple", test_events_08_multiple) { event::Listener listener_a; event::Listener listener_b; int a_calls = 0; @@ -22,6 +23,4 @@ auto main() -> int { assert(a_calls == 1); assert(b_calls == 1); - - return 0; } diff --git a/tests/events/09-unsubscribe_all.cpp b/tests/events/09-unsubscribe_all.cpp index 490451ed7..839ed434a 100644 --- a/tests/events/09-unsubscribe_all.cpp +++ b/tests/events/09-unsubscribe_all.cpp @@ -1,11 +1,13 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include struct UnsubEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/09-unsubscribe_all", test_events_09_unsubscribe_all) { event::Listener listener; int called = 0; @@ -18,6 +20,4 @@ auto main() -> int { event::pollEvents(); assert(called == 0); - - return 0; } diff --git a/tests/events/10-concurrent_send.cpp b/tests/events/10-concurrent_send.cpp index 08f023d0b..abcd30757 100644 --- a/tests/events/10-concurrent_send.cpp +++ b/tests/events/10-concurrent_send.cpp @@ -1,6 +1,8 @@ #include "toast/events/event.hpp" #include "toast/events/listener.hpp" +#include "test_registry.hpp" + #include #include #include @@ -8,7 +10,7 @@ struct CountEvent : event::Event { }; -auto main() -> int { +TOAST_TEST_NAMED("events", "events/10-concurrent_send", test_events_10_concurrent_send) { event::Listener listener; std::atomic counter {0}; @@ -38,6 +40,4 @@ auto main() -> int { event::pollEvents(); assert(counter == num_threads * events_per_thread); - - return 0; } diff --git a/tests/test_registry.hpp b/tests/test_registry.hpp new file mode 100644 index 000000000..0a758d330 --- /dev/null +++ b/tests/test_registry.hpp @@ -0,0 +1,33 @@ +#pragma once + +#include +#include + +namespace toast::tests { + +using TestFn = void (*)(); + +struct TestCase { + std::string name; + std::string group; + TestFn fn; +}; + +inline std::vector& registry() { + static std::vector cases; + return cases; +} + +struct Registrar { + Registrar(const char* name, const char* group, TestFn fn) { + registry().push_back(TestCase{std::string(name), std::string(group), fn}); + } +}; + +} // namespace toast::tests + +#define TOAST_TEST_NAMED(group, name_str, fn_name) \ + static void fn_name(); \ + static const toast::tests::Registrar fn_name##_registrar(name_str, group, &fn_name); \ + static void fn_name() + diff --git a/tests/test_runner.cpp b/tests/test_runner.cpp new file mode 100644 index 000000000..b655cde99 --- /dev/null +++ b/tests/test_runner.cpp @@ -0,0 +1,67 @@ +#include "test_registry.hpp" + +#include +#include +#include + +namespace { + +void print_usage(const char* exe_name) { + std::cout << "Usage: " << exe_name << " [--list] [--test ]" << "\n"; +} + +} // namespace + +int main(int argc, char** argv) { + std::string_view requested_test; + bool list_only = false; + + for (int i = 1; i < argc; ++i) { + std::string_view arg = argv[i]; + if (arg == "--list") { + list_only = true; + } else if (arg == "--test") { + if (i + 1 >= argc) { + print_usage(argv[0]); + return 2; + } + requested_test = argv[++i]; + } else if (arg == "--help" || arg == "-h") { + print_usage(argv[0]); + return 0; + } + } + + const auto& cases = toast::tests::registry(); + if (list_only) { + for (const auto& test_case : cases) { + std::cout << test_case.name << "\n"; + } + return 0; + } + + auto run_case = [](const toast::tests::TestCase& test_case) { + std::cout << "[ RUN ] " << test_case.name << "\n"; + test_case.fn(); + std::cout << "[ OK ] " << test_case.name << "\n"; + }; + + if (!requested_test.empty()) { + auto it = std::find_if(cases.begin(), cases.end(), [&](const auto& test_case) { + return test_case.name == requested_test; + }); + if (it == cases.end()) { + std::cerr << "Unknown test: " << requested_test << "\n"; + return 2; + } + run_case(*it); + return 0; + } + + for (const auto& test_case : cases) { + run_case(test_case); + } + + return 0; +} + diff --git a/tests/xmake.lua b/tests/xmake.lua deleted file mode 100644 index 7cb400de7..000000000 --- a/tests/xmake.lua +++ /dev/null @@ -1,27 +0,0 @@ --- Run Tests: xmake test --- Run Test Group: xmake test -g events - -local scriptdir = os.scriptdir() -for _, filepath in ipairs(os.files(path.join(scriptdir, "**.cpp"))) do - local relpath = path.relative(filepath, scriptdir) - local dir = path.directory(relpath) - local target_name = relpath:gsub("%.cpp$", "") - - target(target_name, function() - set_kind("binary") - set_default(false) - - add_files(filepath) - add_deps("toast.engine") - - - add_defines("UNIT_TESTING") - - - -- Grouping logic - set_group("tests/" .. dir) - add_tests("default", { group = dir }) - - add_rpathdirs("./", "../") - end) -end diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..a5facfe82 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,4 @@ +add_subdirectory(player) +add_subdirectory(dummy_game) +add_subdirectory(kenzo) +add_subdirectory(log_server) diff --git a/tools/ci/clang_format.sh b/tools/ci/clang_format.sh index dcf575d26..9dc87f54a 100644 --- a/tools/ci/clang_format.sh +++ b/tools/ci/clang_format.sh @@ -22,20 +22,6 @@ nix --extra-experimental-features "nix-command flakes" develop .#default -c bash exit 0 fi - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add -- "${files[@]}" - - if ! git commit -m "ci: apply clang-format to engine"; then - echo "Formatting changes detected, but nothing was committed." - exit 1 - fi - - if git push; then - echo "Formatting fixes were pushed to the PR branch. Continuing with the updated commit in this run." - exit 0 - fi - - echo "::error::Formatting changes were detected, but this workflow could not push fixes. Format locally and push." + echo "::error::Formatting changes detected. Run clang-format locally and push the results." exit 1 ' diff --git a/tools/dummy_game/CMakeLists.txt b/tools/dummy_game/CMakeLists.txt new file mode 100644 index 000000000..423de9bed --- /dev/null +++ b/tools/dummy_game/CMakeLists.txt @@ -0,0 +1,6 @@ +project(dummy_game CXX) + +add_library(dummy_game SHARED game.cpp) +add_dependencies(dummy_game toast_engine) +target_link_libraries(dummy_game PUBLIC toast_engine) +target_compile_definitions(dummy_game PRIVATE GAME_EXPORT) diff --git a/tools/kenzo/CMakeLists.txt b/tools/kenzo/CMakeLists.txt new file mode 100644 index 000000000..a08142f4f --- /dev/null +++ b/tools/kenzo/CMakeLists.txt @@ -0,0 +1,21 @@ +project(kenzo NONE) + +set(CARGO_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(CARGO_TARGET_DIR "${OUTPUT_ROOT}/$/cargo") +set(CARGO_PROFILE_NAME "$,$,$>,release,debug>") +set(CARGO_PROFILE_FLAG "$,$,$>,release,dev>") + +find_program(CARGO_EXECUTABLE cargo REQUIRED) +message(STATUS "Found cargo: ${CARGO_EXECUTABLE}") +message(STATUS "Build configuration: ${CARGO_PROFILE_NAME}") +message(STATUS "Cargo target directory: ${CARGO_TARGET_DIR}") + +add_custom_target(kenzo ALL + COMMAND ${CARGO_EXECUTABLE} build --profile "${CARGO_PROFILE_FLAG}" --target-dir "${CARGO_TARGET_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CARGO_TARGET_DIR}/${CARGO_PROFILE_NAME}/kenzo${CMAKE_EXECUTABLE_SUFFIX}" + "${OUTPUT_ROOT}/$/kenzo${CMAKE_EXECUTABLE_SUFFIX}" + WORKING_DIRECTORY ${CARGO_PROJECT_DIR} + COMMENT "[cargo] Building kenzo (${CARGO_PROFILE_NAME})..." + VERBATIM +) diff --git a/tools/log_server/CMakeLists.txt b/tools/log_server/CMakeLists.txt new file mode 100644 index 000000000..9f2d2c2db --- /dev/null +++ b/tools/log_server/CMakeLists.txt @@ -0,0 +1,21 @@ +project(log_server NONE) + +set(CARGO_PROJECT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +set(CARGO_TARGET_DIR "${OUTPUT_ROOT}/$/cargo") +set(CARGO_PROFILE_NAME "$,$,$>,release,debug>") +set(CARGO_PROFILE_FLAG "$,$,$>,release,dev>") + +find_program(CARGO_EXECUTABLE cargo REQUIRED) +message(STATUS "Found cargo: ${CARGO_EXECUTABLE}") +message(STATUS "Build configuration: ${CARGO_PROFILE_NAME}") +message(STATUS "Cargo target directory: ${CARGO_TARGET_DIR}") + +add_custom_target(log_server ALL + COMMAND ${CARGO_EXECUTABLE} build --profile "${CARGO_PROFILE_FLAG}" --target-dir "${CARGO_TARGET_DIR}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${CARGO_TARGET_DIR}/${CARGO_PROFILE_NAME}/log_server${CMAKE_EXECUTABLE_SUFFIX}" + "${OUTPUT_ROOT}/$/log_server${CMAKE_EXECUTABLE_SUFFIX}" + WORKING_DIRECTORY ${CARGO_PROJECT_DIR} + COMMENT "[cargo] Building log_server (${CARGO_PROFILE_NAME})..." + VERBATIM +) diff --git a/tools/log_server/Cargo.toml b/tools/log_server/Cargo.toml index 17db8da55..d224327df 100644 --- a/tools/log_server/Cargo.toml +++ b/tools/log_server/Cargo.toml @@ -3,18 +3,14 @@ name = "log_server" version = "0.1.0" edition = "2021" -# This file is for LSP/IDE support only -# The project is built fully with xmake -# Do not use this file for actual compilation - [[bin]] name = "log_server" path = "src/main.rs" [dependencies] -chrono = "0.4" -clap = { version = "4", features = ["derive"] } -csv = "1.3.1" -prost = "0.14" -serde = { version = "1", features = ["derive"] } -tokio = { version = "1", features = ["full"] } +prost = "0.14" +tokio = { version = "1", features = ["full"] } +clap = { version = "4", features = ["derive"] } +csv = "1.3.1" +serde = { version = "1", features = ["derive"] } +chrono = "0.4" \ No newline at end of file diff --git a/tools/player/CMakeLists.txt b/tools/player/CMakeLists.txt new file mode 100644 index 000000000..1b6545556 --- /dev/null +++ b/tools/player/CMakeLists.txt @@ -0,0 +1,22 @@ +project(toast_player NONE) + +set(CSHARP_PROJECT "${CMAKE_CURRENT_SOURCE_DIR}/player.csproj") +set(CSHARP_ASSEMBLY_NAME "player") + +set(DOTNET_CONFIG "$,Debug,Release>") + +find_program(DOTNET_EXECUTABLE dotnet REQUIRED) +message(STATUS "Found dotnet: ${DOTNET_EXECUTABLE}") +message(STATUS "Build configuration: ${DOTNET_CONFIG}") +message(STATUS "Output directory: ${OUTPUT_ROOT}/$") + +add_custom_target(player ALL + COMMAND ${DOTNET_EXECUTABLE} build + "${CSHARP_PROJECT}" + --configuration ${DOTNET_CONFIG} + --output "${OUTPUT_ROOT}/$" + --nologo + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "[dotnet] Building ${CSHARP_ASSEMBLY_NAME} (${DOTNET_CONFIG})..." + VERBATIM +) diff --git a/tools/player/dll_resolver.cs b/tools/player/dll_resolver.cs index d5056d633..aca40a7bb 100644 --- a/tools/player/dll_resolver.cs +++ b/tools/player/dll_resolver.cs @@ -28,16 +28,18 @@ private static IntPtr Resolve(string libraryName, System.Reflection.Assembly ass // System.Console.WriteLine($"[NativeResolver] Resolve called for: {libraryName}"); - // Search roots: assembly location, AppContext.BaseDirectory, current directory + var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + + // Search roots: AppContext.BaseDirectory, assembly location, current directory var roots = new List(); - try { - var asmDir = Path.GetDirectoryName(assembly.Location); - if (!string.IsNullOrEmpty(asmDir)) roots.Add(asmDir); - } catch (Exception ex) { Console.WriteLine($"[NativeResolver] asm location error: {ex.Message}"); } try { var baseDir = AppContext.BaseDirectory; if (!string.IsNullOrEmpty(baseDir)) roots.Add(baseDir); } catch (Exception ex) { Console.WriteLine($"[NativeResolver] baseDir error: {ex.Message}"); } + try { + var asmDir = Path.GetDirectoryName(assembly.Location); + if (!string.IsNullOrEmpty(asmDir)) roots.Add(asmDir); + } catch (Exception ex) { Console.WriteLine($"[NativeResolver] asm location error: {ex.Message}"); } roots.Add(Directory.GetCurrentDirectory()); // System.Console.WriteLine("[NativeResolver] search roots:"); @@ -48,7 +50,7 @@ private static IntPtr Resolve(string libraryName, System.Reflection.Assembly ass : [".so"]; // If resolving the application library, attempt to preload the engine library with RTLD_GLOBAL so DT_NEEDED is resolved - if (libraryName == "__APPLICATION_LIB__") { + if (libraryName == "__APPLICATION_LIB__" && isLinux) { foreach (var ext in extensions) { foreach (var root in roots) { try { @@ -81,15 +83,17 @@ private static IntPtr Resolve(string libraryName, System.Reflection.Assembly ass var oldCwd = Directory.GetCurrentDirectory(); try { if (!string.IsNullOrEmpty(libDir)) Directory.SetCurrentDirectory(libDir); - // Try dlopen directly to ensure DT_NEEDED deps are resolved via RTLD_GLOBAL - const int RTLD_NOW = 2; - const int RTLD_GLOBAL = 0x100; - var handle = dlopen(files[0], RTLD_NOW | RTLD_GLOBAL); - if (handle != IntPtr.Zero) { - // System.Console.WriteLine("[NativeResolver] dlopen(app) succeeded"); - return handle; + if (isLinux) { + // Try dlopen directly to ensure DT_NEEDED deps are resolved via RTLD_GLOBAL + const int RTLD_NOW = 2; + const int RTLD_GLOBAL = 0x100; + var handle = dlopen(files[0], RTLD_NOW | RTLD_GLOBAL); + if (handle != IntPtr.Zero) { + // System.Console.WriteLine("[NativeResolver] dlopen(app) succeeded"); + return handle; + } + // System.Console.WriteLine("[NativeResolver] dlopen(app) returned NULL, falling back to NativeLibrary.Load"); } - // System.Console.WriteLine("[NativeResolver] dlopen(app) returned NULL, falling back to NativeLibrary.Load"); return NativeLibrary.Load(files[0]); } finally { try { Directory.SetCurrentDirectory(oldCwd); } catch { } diff --git a/tools/player/player.csproj b/tools/player/player.csproj index 51e649b9d..007969b6d 100644 --- a/tools/player/player.csproj +++ b/tools/player/player.csproj @@ -1,24 +1,19 @@ - + Exe net10.0 enable enable - player - - - false - - - bin\ - obj\ + nullptr Studios - - - - - + + ../build/debug + + + + ../build/release + diff --git a/tools/player/toast_engine.cs b/tools/player/toast_engine.cs index d6b1da23a..db0116547 100644 --- a/tools/player/toast_engine.cs +++ b/tools/player/toast_engine.cs @@ -11,6 +11,8 @@ public ToastEngine() { m_handle = toast_create(); if (m_handle == IntPtr.Zero) throw new InvalidOperationException("Failed to create engine"); + + //toast_create_SDL_window("Hello from C#!!"); } public void Tick() { @@ -49,4 +51,7 @@ public void Dispose() { [DllImport("__ENGINE_LIB__", CallingConvention = CallingConvention.Cdecl)] private static extern void toast_destroy(IntPtr engine); + + //[DllImport("__ENGINE_LIB__", CallingConvention = CallingConvention.Cdecl)] + //private static extern void toast_create_SDL_window(string windowName); } diff --git a/tools/xmake.lua b/tools/xmake.lua deleted file mode 100644 index 59fdde062..000000000 --- a/tools/xmake.lua +++ /dev/null @@ -1,81 +0,0 @@ -add_requires("cargo::anyhow 1.0") -add_requires("cargo::chrono 0.4") -add_requires("cargo::clap", {configs = {features = "derive"}}) -add_requires("cargo::csv 1.3.1") -add_requires("cargo::crossterm 0.28.1") -add_requires("cargo::prost 0.14") -add_requires("cargo::prost-types 0.13.5") -add_requires("cargo::serde", {configs = {features = "derive"}}) -add_requires("cargo::textwrap 0.16") -add_requires("cargo::tokio", {configs = {features = "full"}}) -add_requires("cargo::tui-input 0.11") - -local tools_dir = os.scriptdir() - -target("player", function() - set_kind("binary") - add_deps("toast.engine", "toast.dummy_game") - add_files("player/**.cs") - remove_files("player/obj/**") - set_values("csharp.target_framework", "net10.0") - set_values("csharp.nullable", "enable") - set_values("csharp.implicit_usings", "enable") - set_values("csharp.generate_assembly_info", "false") -end) - -target("toast.dummy_game", function() - set_kind("shared") - add_files("dummy_game/**.cpp") - add_headerfiles("dummy_game/**.h") - add_deps("toast.engine") - add_defines("GAME_EXPORT") - add_rpathdirs("./") -end) - -target("kenzo", function() - set_kind("binary") - set_default(false) - on_build(function(target) - local oldir = os.cd("$(projectdir)/tools/kenzo") - - if is_mode("release") then - os.execv("cargo", {"build", "--release"}) - else - os.execv("cargo", {"build"}) - end - - -- Copy binary to xmake's output directory so xmake run works - local target_subdir = is_mode("release") and "release" or "debug" - local src_binary = "target/" .. target_subdir .. "/kenzo" - local dst_dir = target:targetdir() - os.mkdir(dst_dir) - os.cp(src_binary, path.join(dst_dir, "kenzo")) - - os.cd(oldir) - end) - on_clean(function(target) - local oldir = os.cd("$(projectdir)/tools/kenzo") - os.execv("cargo", {"clean"}) - os.cd(oldir) - end) -end) - -target("log_server", function() - set_kind("binary") - -- set_languages("rust") - add_files("log_server/src/main.rs") - add_packages( - "cargo::prost", - "cargo::tokio", - "cargo::clap", - "cargo::csv", - "cargo::serde", - "cargo::chrono" - ) -end) - -target("toast.tools", function() - set_kind("phony") - add_deps("kenzo", "log_server") -end) - diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 000000000..c023aa04f --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,12 @@ +{ + "name" : "engine", + "version-string" : "1.0.0", + "builtin-baseline" : "082b32b6c5de20fd01f61dfaa9856fcba849e73e", + "dependencies" : [ { + "name" : "asio", + "version>=" : "1.32.0" + }, { + "name" : "sdl3", + "version>=" : "3.4.8" + } ] +} \ No newline at end of file diff --git a/xmake.lua b/xmake.lua deleted file mode 100644 index 261a3e31b..000000000 --- a/xmake.lua +++ /dev/null @@ -1,89 +0,0 @@ -add_rules("mode.debug", "mode.release") -set_defaultmode("debug") - -set_languages("c++23") - -rule("clang-format") -before_build(function(target) - cprint("${green}[100%]: ${magenta}<" .. target:name() .. "> ${reset}format") - - local source_files = target:sourcefiles() - for _, file in ipairs(source_files) do - if file:endswith(".cpp") then - os.exec("clang-format -i --style=file:" .. os.curdir() .. "/.clang-format " .. file) - end - end - - local header_files = target:headerfiles() - for _, file in ipairs(header_files) do - if file:endswith(".hpp") or file:endswith(".h") or file:endswith(".inl") then - os.exec("clang-format -i --style=file:" .. os.curdir() .. "/.clang-format " .. file) - end - end -end) -rule_end() - -add_rules("plugin.compile_commands.autoupdate") -add_cxxflags("-stdlib=libc++", { tools = { "clang", "gcc" } }) -- Use LLVM STL by default - --- Makes release have flto, fast math and SIMD intrinsic optimizations -if is_mode("release") then - set_symbols("hidden") - set_strip("all") - set_optimize("aggressive") - set_policy("build.optimization.lto", true) - add_cxflags("-march=native", "-ffast-math", { force = true, tools = { "clang", "gcc" } }) - add_cxflags("/fp:fast", "/arch:AVX2", { force = true, tools = "cl" }) -end - --- Enables debug optimizations, needed on newer clang and gcc versions to avoid a warning -if is_mode("debug") then - set_optimize("none") - add_cxxflags("-Og") - add_defines("DEBUG") -end - -includes("engine/xmake.lua") -includes("editor/xmake.lua") -includes("tools/xmake.lua") -includes("tests/xmake.lua") - -task("tidy") -set_menu { - usage = "xmake tidy", - description = "Run clang-tidy on engine files with progress" -} -on_run(function() - local all_files = os.files("engine/**") - local targets = {} - for _, file in ipairs(all_files) do - local ext = path.extension(file) - local is_valid_ext = (ext == ".hpp" or ext == ".cpp" or ext == ".h" or ext == ".inl") - - -- Skip generated and external folders - if is_valid_ext and - not file:find("engine/generated", 1, true) and - not file:find("engine/external", 1, true) and - not file:find("engine/ffi", 1, true) then - table.insert(targets, file) - end - end - - local total = #targets - if total == 0 then - cprint("${yellow}No files found to analyze.") - return - end - - for i, file in ipairs(targets) do - local percentage = math.floor((i / total) * 100) - local progress = string.format("%3d%%", percentage) - cprint("${green}[" .. progress .. "]: ${reset}clang-tidy.analyzing " .. file) - try { - function() - os.execv("clang-tidy", { "-p", ".", file }) - end - } - end -end) -task_end()