From 9cdb8d2b5f0f2ae35c78a5004547bea35383863b Mon Sep 17 00:00:00 2001 From: "Leandro (Cerberus1746) Benedet Garcia" Date: Mon, 10 Feb 2025 20:26:53 -0300 Subject: [PATCH] Create Actions --- .github/workflows/ci.yml | 146 ++++++++++++++++++++++++-- .github/workflows/pull-request-ci.yml | 24 +++++ .github/workflows/sdl3_repo_tag | 1 + SDL3/SDL3.Core.cs | 3 + SDL3/SDL3.Legacy.cs | 3 + generate_json.sh | 4 +- 6 files changed, 172 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/pull-request-ci.yml create mode 100644 .github/workflows/sdl3_repo_tag diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5bfbf3f..1d2b1f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,151 @@ -name: CI +name: Generate bindings -on: [push, pull_request] +on: [push,] jobs: + generate-bindings: + env: + C2FFI_HASH: 0de81efb64acc82c08c5eee4a7108ddcb1b00d86 + name: Generate Bindings + runs-on: ubuntu-latest + steps: + # We have many repos to clone, that's why we divide then all into + # separate paths, including our own. + # Actually it's for my sanity, but alas + - name: Clone repo + uses: actions/checkout@v3 + with: + path: main/ + + - name: Read file with SDL3 repository tag + uses: satya-500/read-file-github-action@v1.0.0 + id: read_file + with: + path: main/.github/workflows/sdl3_repo_tag + + # Cache compiled things so we don't need to compile it all the time + - id: cache-c2ffi + uses: actions/cache@v4 + with: + path: c2ffi/build/bin + key: ${{ env.C2FFI_HASH }}-c2ffi + # We also need to cache the entire SDL repo, because ninja needs to rerun + # cmake when installing, for some reason + # But hey, does it need to rebuild things? Nope + # Does it even check for compiler differences? Nope + # It does check if apt dependencies are there, for some reason. + - id: cache-sdl + uses: actions/cache@v4 + with: + path: sdl3/ + key: ${{ steps.read_file.outputs.contents }}-sdl3 + + - name: Clone SDL3 + uses: actions/checkout@v3 + if: steps.cache-sdl.outputs.cache-hit != 'true' + with: + repository: libsdl-org/SDL + ref: ${{ steps.read_file.outputs.contents }} + path: sdl3/ + + # If there's something not compiled, we need to setup the compiler + # c2ffi REQUIRES llvm and a specific version of it + - name: Setup buildsystem + uses: aminya/setup-cpp@v1 + if: steps.cache-c2ffi.outputs.cache-hit != 'true' || steps.cache-sdl.outputs.cache-hit != 'true' + with: + compiler: llvm-18.1 + # We still need to install sdl dependencies into the system, even if + # there's a cache hit + - name: Build deps + uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: | + libasound2-dev libpulse-dev ninja-build cmake \ + libaudio-dev libjack-dev libsndio-dev libx11-dev libxext-dev \ + libxrandr-dev libxcursor-dev libxfixes-dev libxi-dev libxss-dev \ + libxkbcommon-dev libdrm-dev libgbm-dev libgl1-mesa-dev \ + libgles2-mesa-dev libegl1-mesa-dev libdbus-1-dev \ + libibus-1.0-dev libudev-dev fcitx-libs-dev libpipewire-0.3-dev \ + libwayland-dev liburing-dev dotnet-sdk-8.0 + version: 1.2 + + - name: Build SDL3 + if: steps.cache-sdl.outputs.cache-hit != 'true' + run: | + cd $GITHUB_WORKSPACE/sdl3/ + mkdir build + cd build + cmake -G Ninja .. + ninja + # We NEED to install SDL into the path for c2ffi to find the headers + # I tried to just pass the includes of the repository to c2ffi, + # without success. It worked locally, but not in the actions + # TODO: find a way to install the headers without any compilation, it + # would be nice + - name: Run SDL Install + run: | + cd $GITHUB_WORKSPACE/sdl3/build/ + sudo ninja install + + # c2ffi related + - name: Clone c2ffi + uses: actions/checkout@v3 + if: steps.cache-c2ffi.outputs.cache-hit != 'true' + with: + repository: rpav/c2ffi + # I am using a specific commit hash just in case. + ref: ${{env.C2FFI_HASH}} + path: c2ffi/ + - name: Run c2ffi cmake + if: steps.cache-c2ffi.outputs.cache-hit != 'true' + run: | + cd $GITHUB_WORKSPACE/c2ffi/ + mkdir build + cd build + cmake -G Ninja .. + ninja + + # Finally something actually related to binding generation + - name: Generate ffi.json + run: | + c2ffi=$GITHUB_WORKSPACE/c2ffi/build/bin/c2ffi + cd $GITHUB_WORKSPACE/main/ + chmod +x ./generate_json.sh + chmod +x $c2ffi + ./generate_json.sh $c2ffi + + - name: Generate Bindings + run: | + generator=GenerateBindings/bin/Release/net8.0/GenerateBindings + + cd $GITHUB_WORKSPACE/main/ + dotnet build GenerateBindings.sln -c Release + + $generator $GITHUB_WORKSPACE/sdl3/ + $generator $GITHUB_WORKSPACE/sdl3/ --core + + - name: Commit bindings + run: | + cd $GITHUB_WORKSPACE/main/ + + # we need to check for changes first because git push returns an + # error code if there are no changes + if [ -n "$(git status -s)" ]; then + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git commit -a -m "[skip ci] Update bindings" + git push + fi + linux: name: Linux runs-on: ubuntu-22.04 + needs: + - generate-bindings steps: - uses: actions/checkout@v3 - - name: dotnet build GenerateBindings - run: | - dotnet build GenerateBindings -c Debug - dotnet build GenerateBindings -c Release - - name: msbuild SDL3 run: | msbuild -restore SDL3-CS.Legacy.sln /p:Configuration=Debug diff --git a/.github/workflows/pull-request-ci.yml b/.github/workflows/pull-request-ci.yml new file mode 100644 index 0000000..b1d0196 --- /dev/null +++ b/.github/workflows/pull-request-ci.yml @@ -0,0 +1,24 @@ +name: On pull request + +on: [pull_request,] + +jobs: + linux: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v3 + + - name: dotnet build GenerateBindings + run: | + dotnet build GenerateBindings -c Debug + dotnet build GenerateBindings -c Release + + - name: msbuild SDL3 + run: | + msbuild -restore SDL3-CS.Legacy.sln /p:Configuration=Debug + msbuild -restore SDL3-CS.Legacy.sln /p:Configuration=Release + + - name: dotnet build SDL3.Core + run: | + dotnet build SDL3/SDL3.Core.csproj -c Debug + dotnet build SDL3/SDL3.Core.csproj -c Release diff --git a/.github/workflows/sdl3_repo_tag b/.github/workflows/sdl3_repo_tag new file mode 100644 index 0000000..13c3373 --- /dev/null +++ b/.github/workflows/sdl3_repo_tag @@ -0,0 +1 @@ +release-3.2.4 \ No newline at end of file diff --git a/SDL3/SDL3.Core.cs b/SDL3/SDL3.Core.cs index 677ed35..772bb59 100644 --- a/SDL3/SDL3.Core.cs +++ b/SDL3/SDL3.Core.cs @@ -6985,6 +6985,7 @@ public struct SDL_hid_device_info public const string SDL_HINT_MAC_BACKGROUND_APP = "SDL_MAC_BACKGROUND_APP"; public const string SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"; public const string SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH = "SDL_MAC_OPENGL_ASYNC_DISPATCH"; + public const string SDL_HINT_MAC_OPTION_AS_ALT = "SDL_MAC_OPTION_AS_ALT"; public const string SDL_HINT_MAC_SCROLL_MOMENTUM = "SDL_MAC_SCROLL_MOMENTUM"; public const string SDL_HINT_MAIN_CALLBACK_RATE = "SDL_MAIN_CALLBACK_RATE"; public const string SDL_HINT_MOUSE_AUTO_CAPTURE = "SDL_MOUSE_AUTO_CAPTURE"; @@ -7090,6 +7091,8 @@ public struct SDL_hid_device_info public const string SDL_HINT_X11_XCB_LIBRARY = "SDL_X11_XCB_LIBRARY"; public const string SDL_HINT_XINPUT_ENABLED = "SDL_XINPUT_ENABLED"; public const string SDL_HINT_ASSERT = "SDL_ASSERT"; + public const string SDL_HINT_PEN_MOUSE_EVENTS = "SDL_PEN_MOUSE_EVENTS"; + public const string SDL_HINT_PEN_TOUCH_EVENTS = "SDL_PEN_TOUCH_EVENTS"; public enum SDL_HintPriority { diff --git a/SDL3/SDL3.Legacy.cs b/SDL3/SDL3.Legacy.cs index 338963f..e510ad6 100644 --- a/SDL3/SDL3.Legacy.cs +++ b/SDL3/SDL3.Legacy.cs @@ -6856,6 +6856,7 @@ public static int SDL_hid_get_indexed_string(IntPtr dev, int string_index, strin public const string SDL_HINT_MAC_BACKGROUND_APP = "SDL_MAC_BACKGROUND_APP"; public const string SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK = "SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK"; public const string SDL_HINT_MAC_OPENGL_ASYNC_DISPATCH = "SDL_MAC_OPENGL_ASYNC_DISPATCH"; + public const string SDL_HINT_MAC_OPTION_AS_ALT = "SDL_MAC_OPTION_AS_ALT"; public const string SDL_HINT_MAC_SCROLL_MOMENTUM = "SDL_MAC_SCROLL_MOMENTUM"; public const string SDL_HINT_MAIN_CALLBACK_RATE = "SDL_MAIN_CALLBACK_RATE"; public const string SDL_HINT_MOUSE_AUTO_CAPTURE = "SDL_MOUSE_AUTO_CAPTURE"; @@ -6961,6 +6962,8 @@ public static int SDL_hid_get_indexed_string(IntPtr dev, int string_index, strin public const string SDL_HINT_X11_XCB_LIBRARY = "SDL_X11_XCB_LIBRARY"; public const string SDL_HINT_XINPUT_ENABLED = "SDL_XINPUT_ENABLED"; public const string SDL_HINT_ASSERT = "SDL_ASSERT"; + public const string SDL_HINT_PEN_MOUSE_EVENTS = "SDL_PEN_MOUSE_EVENTS"; + public const string SDL_HINT_PEN_TOUCH_EVENTS = "SDL_PEN_TOUCH_EVENTS"; public enum SDL_HintPriority { diff --git a/generate_json.sh b/generate_json.sh index 107f87f..b3e7b1d 100755 --- a/generate_json.sh +++ b/generate_json.sh @@ -1,4 +1,4 @@ -#!env sh +#!/bin/bash if [ ! -z $1 ]; then c2ffi_executable=$1 elif ! command -v c2ffi 2>&1 >/dev/null; then @@ -14,5 +14,5 @@ cat > tmp.c <<- EOM #include EOM -$c2ffi_executable tmp.c -o GenerateBindings/assets/ffi.json +$c2ffi_executable tmp.c "${@:2}" -o GenerateBindings/assets/ffi.json rm tmp.c