| 1 | name: Build raylib - macOS |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | push: |
| 6 | paths: |
| 7 | - 'src/**' |
| 8 | - 'examples/**' |
| 9 | - '.github/workflows/macos.yml' |
| 10 | pull_request: |
| 11 | paths: |
| 12 | - 'src/**' |
| 13 | - 'examples/**' |
| 14 | - '.github/workflows/macos.yml' |
| 15 | release: |
| 16 | types: [published] |
| 17 | |
| 18 | permissions: |
| 19 | contents: read |
| 20 | |
| 21 | jobs: |
| 22 | build: |
| 23 | permissions: |
| 24 | contents: write # for actions/upload-release-asset to upload release asset |
| 25 | runs-on: macos-latest |
| 26 | |
| 27 | env: |
| 28 | RELEASE_NAME: raylib-dev_macos |
| 29 | |
| 30 | steps: |
| 31 | - name: Checkout |
| 32 | uses: actions/checkout@master |
| 33 | |
| 34 | - name: Setup Release Version |
| 35 | run: | |
| 36 | echo "RELEASE_NAME=raylib-${{ github.event.release.tag_name }}_macos" >> $GITHUB_ENV |
| 37 | shell: bash |
| 38 | if: github.event_name == 'release' && github.event.action == 'published' |
| 39 | |
| 40 | - name: Setup Environment |
| 41 | run: | |
| 42 | mkdir build |
| 43 | cd build |
| 44 | mkdir ${{ env.RELEASE_NAME }} |
| 45 | cd ${{ env.RELEASE_NAME }} |
| 46 | mkdir include |
| 47 | mkdir lib |
| 48 | cd ../.. |
| 49 | |
| 50 | # Generating static + shared library, note that i386 architecture is deprecated |
| 51 | # Defining GL_SILENCE_DEPRECATION because OpenGL is deprecated on macOS |
| 52 | - name: Build Library |
| 53 | run: | |
| 54 | cd src |
| 55 | clang --version |
| 56 | |
| 57 | # Extract version numbers from Makefile |
| 58 | brew install grep |
| 59 | RAYLIB_API_VERSION=`ggrep -Po 'RAYLIB_API_VERSION\s*=\s\K(.*)' Makefile` |
| 60 | RAYLIB_VERSION=`ggrep -Po 'RAYLIB_VERSION\s*=\s\K(.*)' Makefile` |
| 61 | |
| 62 | # Build raylib x86_64 static |
| 63 | make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC CUSTOM_CFLAGS="-target x86_64-apple-macos10.12 -DGL_SILENCE_DEPRECATION" |
| 64 | mv libraylib.a /tmp/libraylib_x86_64.a |
| 65 | make clean |
| 66 | |
| 67 | # Build raylib arm64 static |
| 68 | make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=STATIC CUSTOM_CFLAGS="-target arm64-apple-macos11 -DGL_SILENCE_DEPRECATION" -B |
| 69 | mv libraylib.a /tmp/libraylib_arm64.a |
| 70 | make clean |
| 71 | |
| 72 | # Join x86_64 and arm64 static |
| 73 | lipo -create -output ../build/${{ env.RELEASE_NAME }}/lib/libraylib.a /tmp/libraylib_x86_64.a /tmp/libraylib_arm64.a |
| 74 | |
| 75 | # Build raylib x86_64 dynamic |
| 76 | make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED CUSTOM_CFLAGS="-target x86_64-apple-macos10.12 -DGL_SILENCE_DEPRECATION" CUSTOM_LDFLAGS="-target x86_64-apple-macos10.12" -B |
| 77 | mv libraylib.${RAYLIB_VERSION}.dylib /tmp/libraylib_x86_64.${RAYLIB_VERSION}.dylib |
| 78 | make clean |
| 79 | |
| 80 | # Build raylib arm64 dynamic |
| 81 | make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED CUSTOM_CFLAGS="-target arm64-apple-macos11 -DGL_SILENCE_DEPRECATION" CUSTOM_LDFLAGS="-target arm64-apple-macos11" -B |
| 82 | mv libraylib.${RAYLIB_VERSION}.dylib /tmp/libraylib_arm64.${RAYLIB_VERSION}.dylib |
| 83 | |
| 84 | # Join x86_64 and arm64 dynamic |
| 85 | lipo -create -output ../build/${{ env.RELEASE_NAME }}/lib/libraylib.${RAYLIB_VERSION}.dylib /tmp/libraylib_x86_64.${RAYLIB_VERSION}.dylib /tmp/libraylib_arm64.${RAYLIB_VERSION}.dylib |
| 86 | ln -sv libraylib.${RAYLIB_VERSION}.dylib ../build/${{ env.RELEASE_NAME }}/lib/libraylib.dylib |
| 87 | ln -sv libraylib.${RAYLIB_VERSION}.dylib ../build/${{ env.RELEASE_NAME }}/lib/libraylib.${RAYLIB_API_VERSION}.dylib |
| 88 | cd .. |
| 89 | |
| 90 | - name: Generate Artifacts |
| 91 | run: | |
| 92 | cp -v ./src/raylib.h ./build/${{ env.RELEASE_NAME }}/include |
| 93 | cp -v ./src/raymath.h ./build/${{ env.RELEASE_NAME }}/include |
| 94 | cp -v ./src/rlgl.h ./build/${{ env.RELEASE_NAME }}/include |
| 95 | cp -v ./CHANGELOG ./build/${{ env.RELEASE_NAME }}/CHANGELOG |
| 96 | cp -v ./README.md ./build/${{ env.RELEASE_NAME }}/README.md |
| 97 | cp -v ./LICENSE ./build/${{ env.RELEASE_NAME }}/LICENSE |
| 98 | cd build |
| 99 | tar -czvf ${{ env.RELEASE_NAME }}.tar.gz ${{ env.RELEASE_NAME }} |
| 100 | |
| 101 | - name: Upload Artifacts |
| 102 | uses: actions/upload-artifact@v4 |
| 103 | with: |
| 104 | name: ${{ env.RELEASE_NAME }} |
| 105 | path: | |
| 106 | ./build/${{ env.RELEASE_NAME }} |
| 107 | !./build/${{ env.RELEASE_NAME }}.tar.gz |
| 108 | |
| 109 | - name: Upload Artifact to Release |
| 110 | uses: softprops/action-gh-release@v1 |
| 111 | with: |
| 112 | files: ./build/${{ env.RELEASE_NAME }}.tar.gz |
| 113 | env: |
| 114 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 115 | if: github.event_name == 'release' && github.event.action == 'published' |