From f7fd66b7ebb4df9cb6a8aca923f45127dd23c180 Mon Sep 17 00:00:00 2001 From: Chris Dill Date: Sat, 8 Jun 2024 07:27:01 +0100 Subject: [PATCH] Native build improvements (#235) * Add Raylib-cs.Native to solution * Update build.yml to use local build * Remove experimental android setup --- .github/workflows/build.yml | 200 ++++-------------- Examples.Android/AndroidManifest.xml | 8 - Examples.Android/Examples.Android.csproj | 29 --- Examples.Android/RaylibActivity.cs | 17 -- Examples.Android/android.patch | 27 --- .../runtimes/android-arm/native/.keep | 0 .../runtimes/android-arm64/native/.keep | 0 .../runtimes/android-x64/native/.keep | 0 .../runtimes/android-x86/native/.keep | 0 Raylib-cs.Native/Raylib-cs.Native.csproj | 39 ++-- Raylib-cs.sln | 6 + 11 files changed, 69 insertions(+), 257 deletions(-) delete mode 100644 Examples.Android/AndroidManifest.xml delete mode 100644 Examples.Android/Examples.Android.csproj delete mode 100644 Examples.Android/RaylibActivity.cs delete mode 100644 Examples.Android/android.patch delete mode 100644 Examples.Android/runtimes/android-arm/native/.keep delete mode 100644 Examples.Android/runtimes/android-arm64/native/.keep delete mode 100644 Examples.Android/runtimes/android-x64/native/.keep delete mode 100644 Examples.Android/runtimes/android-x86/native/.keep diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cd14d9e..08b534b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,30 +18,6 @@ jobs: - name: checkout repository uses: actions/checkout@v3 - - name: setup dependencies - run: | - sudo apt-get update - sudo apt-get install \ - libasound2-dev \ - libx11-dev \ - libxrandr-dev \ - libxi-dev \ - libgl1-mesa-dev \ - libglu1-mesa-dev \ - libxcursor-dev \ - libxinerama-dev - - - name: setup dotnet - uses: actions/setup-dotnet@v3 - with: - dotnet-version: 6.0.x - - - name: build and run tests - run: dotnet test Raylib-cs.Tests -c Release - - - name: build examples desktop - run: dotnet build Examples -c Release - - name: check raylib version id: version shell: bash @@ -49,57 +25,18 @@ jobs: echo "version=$(sed -n 's/.*\(.*\)<\/TargetRaylibTag>.*/\1/p' Raylib-cs/Build.props)">> ${GITHUB_OUTPUT} echo "pkgversion=$(sed -n 's/.*\(.*\)<\/PackageVersion>.*/\1/p' Raylib-cs/Build.props)">> ${GITHUB_OUTPUT} - build-android: - runs-on: ubuntu-20.04 - needs: build - strategy: - matrix: - name: [arm, arm64, x86, x64] - include: - - name: arm - arch: armeabi-v7a - cflags: "-mfloat-abi=softfp -mfpu=vfpv3-d16" - - name: arm64 - arch: arm64-v8a - cflags: "-mfix-cortex-a53-835769" - - name: x86 - arch: x86 - - name: x64 - arch: x86_64 - steps: - - name: checkout repository - uses: actions/checkout@v3 - - - name: build raylib - env: - version: ${{ needs.build.outputs.version }} - run: | - curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${version}.zip - unzip -qq raylib.zip - pushd raylib-${version}; patch -p1 < ../Examples.Android/android.patch; popd - cmake -S raylib-${version} \ - -B build \ - -D CMAKE_BUILD_TYPE=Release \ - -D BUILD_SHARED_LIBS=ON \ - -D BUILD_EXAMPLES=OFF \ - -D CMAKE_TOOLCHAIN_FILE=${ANDROID_NDK}/build/cmake/android.toolchain.cmake \ - -D PLATFORM=Android \ - -D ANDROID_ABI=${{ matrix.arch }} \ - -D ANDROID_PLATFORM=21 \ - -D CMAKE_C_FLAGS="${{ matrix.cflags }}" - cmake --build build --config Release - - - name: upload build - uses: actions/upload-artifact@v3 - with: - name: android-${{ matrix.name }} - path: build/raylib/libraylib.so - if-no-files-found: error - build-linux: runs-on: ubuntu-20.04 needs: build steps: + - name: checkout repository + uses: actions/checkout@v3 + + - name: setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + - name: setup dependencies run: | sudo apt-get update @@ -113,25 +50,17 @@ jobs: libxcursor-dev \ libxinerama-dev - - name: build raylib - env: - version: ${{ needs.build.outputs.version }} - run: | - curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${version}.zip - unzip -qq raylib.zip - cmake -S raylib-${version} \ - -B build \ - -D CMAKE_BUILD_TYPE=Release \ - -D BUILD_SHARED_LIBS=ON \ - -D BUILD_EXAMPLES=OFF \ - -D CMAKE_C_FLAGS="${{ matrix.cflags }}" - cmake --build build --config Release + - name: build projects + run: dotnet build -c Release + + - name: run tests + run: dotnet test Raylib-cs.Tests -c Release - name: upload build uses: actions/upload-artifact@v3 with: name: linux-x64 - path: build/raylib/libraylib.so + path: Raylib-cs.Native/bin/Release/native/raylib/libraylib.so if-no-files-found: error build-osx: @@ -146,25 +75,25 @@ jobs: - name: x64 arch: x86_64 steps: - - name: build raylib - env: - version: ${{ needs.build.outputs.version }} - run: | - curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${version}.zip - unzip -qq raylib.zip - cmake -S raylib-${version} \ - -B build \ - -D CMAKE_BUILD_TYPE=Release \ - -D CMAKE_OSX_ARCHITECTURES=${{ matrix.arch }} \ - -D BUILD_SHARED_LIBS=ON \ - -D BUILD_EXAMPLES=OFF - cmake --build build --config Release + - name: checkout repository + uses: actions/checkout@v3 + + - name: setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + + - name: build projects + run: dotnet build -c Release + + - name: run tests + run: dotnet test Raylib-cs.Tests -c Release - name: upload build uses: actions/upload-artifact@v3 with: name: osx-${{ matrix.name }} - path: build/raylib/libraylib.dylib + path: Raylib-cs.Native/bin/Release/native/raylib/libraylib.dylib if-no-files-found: error build-windows: @@ -179,34 +108,30 @@ jobs: - name: x64 arch: x64 steps: - - name: build ${{ matrix.arch }} - shell: bash - env: - version: ${{ needs.build.outputs.version }} - run: | - curl -Lso raylib.zip https://github.com/raysan5/raylib/archive/refs/tags/${version}.zip - unzip -qq raylib.zip - cmake -S raylib-${version} \ - -A ${{ matrix.arch }} \ - -B build \ - -D CMAKE_BUILD_TYPE=Release \ - -D BUILD_SHARED_LIBS=ON \ - -D BUILD_EXAMPLES=OFF \ - -D CMAKE_C_FLAGS="${{ matrix.cflags }}" - cmake --build build --config Release + - name: checkout repository + uses: actions/checkout@v3 + + - name: setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + + - name: build projects + run: dotnet build -c Release + + - name: run tests + run: dotnet test Raylib-cs.Tests -c Release - name: upload build uses: actions/upload-artifact@v3 with: name: win-${{ matrix.name }} - path: build/raylib/Release/raylib.dll + path: Raylib-cs.Native/bin/Release/native/raylib/Release/raylib.dll if-no-files-found: error - publish: + build-publish: runs-on: ubuntu-20.04 needs: - - build - - build-android - build-linux - build-osx - build-windows @@ -214,39 +139,6 @@ jobs: - name: checkout repository uses: actions/checkout@v3 - - name: setup dependencies - run: | - sudo apt-get update - sudo apt-get install \ - libasound2-dev \ - libx11-dev \ - libxrandr-dev \ - libxi-dev \ - libgl1-mesa-dev \ - libglu1-mesa-dev \ - libxcursor-dev \ - libxinerama-dev - - - uses: actions/download-artifact@v3 - with: - name: android-arm - path: Examples.Android/runtimes/android-arm/native - - - uses: actions/download-artifact@v3 - with: - name: android-arm64 - path: Examples.Android/runtimes/android-arm64/native - - - uses: actions/download-artifact@v3 - with: - name: android-x86 - path: Examples.Android/runtimes/android-x86/native - - - uses: actions/download-artifact@v3 - with: - name: android-x64 - path: Examples.Android/runtimes/android-x64/native - - uses: actions/download-artifact@v3 with: name: linux-x64 @@ -277,12 +169,6 @@ jobs: with: dotnet-version: 6.0.x - #- name: restore workload - # run: dotnet workload restore - - #- name: build examples android - # run: dotnet build Examples.Android -c Release - - name: create NuGet Package run: dotnet pack Raylib-cs -c Release --output nuget diff --git a/Examples.Android/AndroidManifest.xml b/Examples.Android/AndroidManifest.xml deleted file mode 100644 index 5791e9e..0000000 --- a/Examples.Android/AndroidManifest.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - diff --git a/Examples.Android/Examples.Android.csproj b/Examples.Android/Examples.Android.csproj deleted file mode 100644 index f1bb095..0000000 --- a/Examples.Android/Examples.Android.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - - Exe - net6.0-android;net7.0-android - Examples.Android - enable - enable - - - - 21 - com.raylibcs.android - 1 - 1.0 - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Examples.Android/RaylibActivity.cs b/Examples.Android/RaylibActivity.cs deleted file mode 100644 index 3230152..0000000 --- a/Examples.Android/RaylibActivity.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Examples.Android; - -public abstract class RaylibActivity : NativeActivity -{ - protected override void OnCreate(Bundle? savedInstanceState) - { - RaylibSetAndroidCallback(OnReady); - base.OnCreate(savedInstanceState); - } - - protected abstract void OnReady(); - - [DllImport(Raylib.NativeLibName, CallingConvention = CallingConvention.Cdecl)] - private static extern void RaylibSetAndroidCallback(Action callback); -} diff --git a/Examples.Android/android.patch b/Examples.Android/android.patch deleted file mode 100644 index 6d70c48..0000000 --- a/Examples.Android/android.patch +++ /dev/null @@ -1,27 +0,0 @@ -diff --git a/src/rcore.c b/src/rcore.c -index eae4951..4400b22 100644 ---- a/src/rcore.c -+++ b/src/rcore.c -@@ -1,3 +1,22 @@ -+#if defined (PLATFORM_ANDROID) -+#include -+ -+typedef void (*RaylibAndroidCallback)(); -+static RaylibAndroidCallback _androidCallback = NULL; -+ -+void RaylibSetAndroidCallback(RaylibAndroidCallback callback) { -+ _androidCallback = callback; -+} -+ -+int main(int argc, char *argv[]) { -+ (void)argc; -+ (void)argv; -+ while (_androidCallback == NULL) { -+ } -+ _androidCallback(); -+} -+#endif -+ - /********************************************************************************************** - * - * rcore - Basic functions to manage windows, OpenGL context and input on multiple platforms diff --git a/Examples.Android/runtimes/android-arm/native/.keep b/Examples.Android/runtimes/android-arm/native/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/Examples.Android/runtimes/android-arm64/native/.keep b/Examples.Android/runtimes/android-arm64/native/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/Examples.Android/runtimes/android-x64/native/.keep b/Examples.Android/runtimes/android-x64/native/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/Examples.Android/runtimes/android-x86/native/.keep b/Examples.Android/runtimes/android-x86/native/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/Raylib-cs.Native/Raylib-cs.Native.csproj b/Raylib-cs.Native/Raylib-cs.Native.csproj index 1fbe25a..355beb6 100644 --- a/Raylib-cs.Native/Raylib-cs.Native.csproj +++ b/Raylib-cs.Native/Raylib-cs.Native.csproj @@ -1,8 +1,8 @@ - + net6.0 - Raylib-cs.Native false + false @@ -24,34 +24,35 @@ - - + Condition="Exists('$(OutputPath)native/raylib/$(NativePre)raylib.$(NativeExt)')" /> + + + - + - - - + Condition="!Exists('$(BaseIntermediateOutputPath)raylib.zip')" /> - - + + + + + diff --git a/Raylib-cs.sln b/Raylib-cs.sln index 015e8d1..851d40f 100644 --- a/Raylib-cs.sln +++ b/Raylib-cs.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raylib-cs.Tests", "Raylib-c EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{1E2A5986-3F11-457F-AF97-D0C08D0060BA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Raylib-cs.Native", "Raylib-cs.Native\Raylib-cs.Native.csproj", "{B89AA313-3675-42A3-80BC-6156913E3A27}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -30,5 +32,9 @@ Global {1E2A5986-3F11-457F-AF97-D0C08D0060BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E2A5986-3F11-457F-AF97-D0C08D0060BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E2A5986-3F11-457F-AF97-D0C08D0060BA}.Release|Any CPU.Build.0 = Release|Any CPU + {B89AA313-3675-42A3-80BC-6156913E3A27}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B89AA313-3675-42A3-80BC-6156913E3A27}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B89AA313-3675-42A3-80BC-6156913E3A27}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B89AA313-3675-42A3-80BC-6156913E3A27}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal