diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a53d6107..14c4b213 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,32 +1,20 @@ -name: Reusable Build Workflow +Based on this build file, write the docker image files for the two builds here so they don't need to install anything, and then edit the build.yml itself to utilize them and remove unneeded commands + +name: Build on: - workflow_call: - inputs: - platform: - description: "Which platform to build for: 'linux' or 'windows'" - required: true - run-tests: - description: "If true, run the test suite" - type: boolean - default: false - package-dist: - description: "If true, create a distributable package (and upload artifact)" - type: boolean - default: false + push: + branches: [ "master" ] + pull_request: jobs: - build: - runs-on: ubuntu-latest # We'll do both Linux or Windows cross from Ubuntu + build-linux: + runs-on: ubuntu-latest steps: - name: Check Out Code uses: actions/checkout@v3 - # --------------------- - # 1) Install Dependencies - # --------------------- - - name: Install Dependencies (Linux) - if: ${{ inputs.platform == 'linux' }} + - name: Install Dependencies run: | sudo apt-get update sudo apt-get install -y \ @@ -36,135 +24,185 @@ jobs: libxi-dev libxinerama-dev libxss-dev \ libegl1-mesa-dev libgl1-mesa-dev \ cmake ninja-build git build-essential binutils mold meson pkg-config \ - ccache - - - name: Install Dependencies (Windows cross) - if: ${{ inputs.platform == 'windows' }} - run: | - sudo apt-get update - sudo apt-get install -y \ - mingw-w64 cmake ninja-build git build-essential \ - binutils pkg-config meson ccache + ccache - name: Configure ccache run: | echo "CMAKE_C_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV - echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV + echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV - name: Cache ccache uses: actions/cache@v3 with: path: ~/.ccache - key: ${{ runner.os }}-ccache-${{ inputs.platform }}-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/CMakeLists.txt', '**/*.meson', '**/*.build') }} + key: ccache-linux-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/CMakeLists.txt', '**/meson.build') }} restore-keys: | - ${{ runner.os }}-ccache-${{ inputs.platform }}- + ccache-linux- - # --------------------- - # 2) Build SDL3 - # --------------------- - - name: Cache SDL3 - id: cache-sdl + - name: Cache SDL3 (Linux) uses: actions/cache@v3 with: path: | - sdl3-${{ inputs.platform }} - sdl3-build-${{ inputs.platform }} - key: sdl3-${{ inputs.platform }}-${{ hashFiles('sdl3-*/*.CMakeLists.txt') }} + sdl3 + sdl3-build + key: sdl3-linux-${{ hashFiles('sdl3/CMakeLists.txt') }} - - name: Build SDL3 + - name: Build SDL3 (Linux) run: | - # Use different folder names for Linux vs Windows - if [ "${{ inputs.platform }}" = "linux" ]; then - SRC="sdl3-linux" - BUILD="sdl3-build-linux" - GIT_URL="https://github.com/libsdl-org/SDL.git" - # Possibly different branches or flags for Linux, etc. - # ... - if [ ! -d "$SRC/.git" ]; then - git clone --depth 1 --branch main "$GIT_URL" "$SRC" - fi - mkdir -p "$BUILD" - cd "$BUILD" - cmake ../"$SRC" -GNinja \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3" \ - -DSDL_SHARED=ON -DSDL_STATIC=OFF - ninja - ninja install - - elif [ "${{ inputs.platform }}" = "windows" ]; then - SRC="sdl3-win" - BUILD="sdl3-build-win" - GIT_URL="https://github.com/libsdl-org/SDL.git" - # ... - if [ ! -d "$SRC/.git" ]; then - git clone --depth 1 --branch main "$GIT_URL" "$SRC" - fi - mkdir -p "$BUILD" - cd "$BUILD" - cmake ../"$SRC" -GNinja \ - -DCMAKE_SYSTEM_NAME=Windows \ - -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ - -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ - -DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3_win" \ - -DSDL_SHARED=ON -DSDL_STATIC=OFF - ninja - ninja install - fi - - # --------------------- - # 3) Build Prosperon - # --------------------- - - name: Configure PKG_CONFIG_PATH - if: ${{ inputs.platform == 'windows' }} - run: | - echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/sdl3-build-win/installed_sdl3_win/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV - - - name: Build Prosperon - run: | - if [ "${{ inputs.platform }}" = "linux" ]; then - export PKG_CONFIG_PATH="${PWD}/sdl3-build-linux/installed_sdl3/lib/pkgconfig:$PKG_CONFIG_PATH" - meson setup build_dbg -Dbuildtype=release -Db_lto=true -Db_ndebug=true - meson compile -C build_dbg - - elif [ "${{ inputs.platform }}" = "windows" ]; then - meson setup --cross-file mingw32.cross build_win -Dbuildtype=release -Db_lto=true -Db_ndebug=true - meson compile -C build_win - fi - - # --------------------- - # 4) (Optional) Run Tests - # --------------------- - - name: Run Test Suite - if: ${{ inputs.run-tests == true }} - run: | - # Example: just show how you'd do it - echo "Running tests..." - # e.g. meson test -C build_dbg - # or some custom test commands - echo "Tests completed!" - - # --------------------- - # 5) (Optional) Package Dist - # --------------------- - - name: Package Distribution - if: ${{ inputs.package-dist == true }} - run: | - echo "Creating final _pack folder..." - mkdir _pack - if [ "${{ inputs.platform }}" = "linux" ]; then - cp build_dbg/prosperon _pack/ - cp sdl3-build-linux/installed_sdl3/lib/libSDL3.so _pack/ + if [ ! -d "sdl3/.git" ]; then + echo "Cloning SDL3 repository..." + git clone --depth 1 --branch main https://github.com/libsdl-org/SDL.git sdl3 else - cp build_win/prosperon.exe _pack/ - cp sdl3-build-win/installed_sdl3_win/bin/SDL3.dll _pack/ + echo "SDL3 source is already present (possibly from cache)." fi - - name: Upload Artifact - if: ${{ inputs.package-dist == true }} + mkdir -p sdl3-build + cd sdl3-build + cmake ../sdl3 -GNinja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3" \ + -DSDL_SHARED=ON \ + -DSDL_STATIC=OFF + ninja + ninja install + + - name: Build Prosperon (Linux) + run: | + export PKG_CONFIG_PATH="${PWD}/sdl3-build/installed_sdl3/lib/pkgconfig:$PKG_CONFIG_PATH" + meson setup build_dbg -Dbuildtype=debugoptimized + meson compile -C build_dbg + + - name: Create artifact folder (Linux) + run: | + mkdir _pack + cp build_dbg/prosperon _pack/ + # Adjust wildcard if there's a versioned libSDL3. e.g. libSDL3-0.600.0.so + cp sdl3-build/installed_sdl3/lib/libSDL3.so _pack/ + + - name: Upload Artifact (Linux) uses: actions/upload-artifact@v3 with: - name: prosperon-${{ inputs.platform }} + name: prosperon-artifacts-linux path: _pack + + build-windows: + runs-on: ubuntu-latest + steps: + - name: Check Out Code + uses: actions/checkout@v3 + + - name: Install Dependencies (Windows Cross) + run: | + sudo apt-get update + sudo apt-get install -y \ + mingw-w64 cmake ninja-build git build-essential \ + binutils pkg-config meson ccache + + - name: Configure ccache + run: | + echo "CMAKE_C_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV + echo "CMAKE_CXX_COMPILER_LAUNCHER=ccache" >> $GITHUB_ENV + + - name: Cache ccache + uses: actions/cache@v3 + with: + path: ~/.ccache + key: ccache-win-${{ hashFiles('**/*.c', '**/*.cpp', '**/*.h', '**/CMakeLists.txt', '**/meson.build') }} + restore-keys: | + ccache-win- + + - name: Cache SDL3 (Windows cross) + uses: actions/cache@v3 + with: + path: | + sdl3-win + sdl3-build-win + key: sdl3-win-${{ hashFiles('sdl3-win/CMakeLists.txt') }} + + - name: Build SDL3 (Windows cross) + run: | + if [ ! -d "sdl3-win/.git" ]; then + echo "Cloning SDL3 for Windows cross..." + git clone --depth 1 --branch main https://github.com/libsdl-org/SDL.git sdl3-win + else + echo "SDL3-win source already present (possibly from cache)." + fi + + mkdir -p sdl3-build-win + cd sdl3-build-win + cmake ../sdl3-win -GNinja \ + -DCMAKE_SYSTEM_NAME=Windows \ + -DCMAKE_C_COMPILER=x86_64-w64-mingw32-gcc \ + -DCMAKE_CXX_COMPILER=x86_64-w64-mingw32-g++ \ + -DCMAKE_RC_COMPILER=x86_64-w64-mingw32-windres \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX="${PWD}/installed_sdl3_win" \ + -DSDL_SHARED=ON \ + -DSDL_STATIC=OFF + ninja + ninja install + + - name: Configure PKG_CONFIG_PATH (Windows cross) + run: | + echo "PKG_CONFIG_PATH=${GITHUB_WORKSPACE}/sdl3-build-win/installed_sdl3_win/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV + + - name: Build Prosperon (Windows cross) + run: | + meson setup -Dbuildtype=debugoptimized --cross-file mingw32.cross build_win + meson compile -C build_win + + - name: Create package folder + run: | + mkdir _pack + cp build_win/prosperon.exe _pack/ + cp sdl3-build-win/installed_sdl3_win/bin/SDL3.dll _pack/ + + - name: Upload Artifact (Windows cross) + uses: actions/upload-artifact@v3 + with: + name: prosperon-artifacts-windows + path: _pack + + + package-dist: + needs: [build-linux, build-windows] + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v3 + + - name: Download Linux Artifacts + uses: actions/download-artifact@v3 + with: + name: prosperon-artifacts-linux + path: linux_artifacts + + - name: Download Windows Artifacts + uses: actions/download-artifact@v3 + with: + name: prosperon-artifacts-windows + path: windows_artifacts + + - name: Create the Dist Folder + run: | + mkdir dist + + cp README.md dist/ + cp license.txt dist/ + cp -r examples dist/ + + # Make subdirectories for each platform + mkdir dist/linux + mkdir dist/win + + # ------------------- + # Copy artifacts in + # ------------------- + cp linux_artifacts/* dist/linux/ + cp windows_artifacts/* dist/win/ + + - name: Upload Final Dist + uses: actions/upload-artifact@v3 + with: + name: prosperon + path: dist \ No newline at end of file