|
| 1 | +name: Web (WebAssembly) Build |
| 2 | + |
| 3 | +run-name: web build from ${{ inputs.ref || github.ref_name }} |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - bobtista/topic/trunk |
| 9 | + # Working branches for build-infrastructure changes, so a push iterates on CI |
| 10 | + # without opening a pull request first. |
| 11 | + - 'ci/**' |
| 12 | + paths: |
| 13 | + - '.github/workflows/web-build.yml' |
| 14 | + - 'CMakePresets.json' |
| 15 | + - 'CMakeLists.txt' |
| 16 | + - 'cmake/**' |
| 17 | + - 'scripts/build/web/**' |
| 18 | + - 'Core/**' |
| 19 | + - 'Dependencies/**' |
| 20 | + - 'GeneralsMD/**' |
| 21 | + pull_request: |
| 22 | + paths: |
| 23 | + - '.github/workflows/web-build.yml' |
| 24 | + - 'CMakePresets.json' |
| 25 | + - 'CMakeLists.txt' |
| 26 | + - 'cmake/**' |
| 27 | + - 'scripts/build/web/**' |
| 28 | + - 'Core/**' |
| 29 | + - 'Dependencies/**' |
| 30 | + - 'GeneralsMD/**' |
| 31 | + workflow_dispatch: |
| 32 | + inputs: |
| 33 | + ref: |
| 34 | + description: "Branch, tag, or SHA to build" |
| 35 | + required: false |
| 36 | + type: string |
| 37 | + |
| 38 | +concurrency: |
| 39 | + group: web-build-${{ github.ref }} |
| 40 | + cancel-in-progress: true |
| 41 | + |
| 42 | +jobs: |
| 43 | + web: |
| 44 | + name: web-generalsmd-sdl3-bgfx |
| 45 | + runs-on: ubuntu-latest |
| 46 | + timeout-minutes: 120 |
| 47 | + # The Emscripten SDK image carries emcc, cmake, make, node and a host g++ (needed |
| 48 | + # for the host shaderc the cross build compiles its shaders with). |
| 49 | + container: emscripten/emsdk:6.0.5 |
| 50 | + steps: |
| 51 | + - name: Checkout Code |
| 52 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 53 | + with: |
| 54 | + ref: ${{ inputs.ref || github.ref_name }} |
| 55 | + |
| 56 | + - name: Mark Workspace Safe For Git |
| 57 | + run: git config --global --add safe.directory "${GITHUB_WORKSPACE}" |
| 58 | + |
| 59 | + - name: Cache FFmpeg For wasm |
| 60 | + id: cache-ffmpeg-wasm |
| 61 | + uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 |
| 62 | + with: |
| 63 | + path: ${{ github.workspace }}/build/ffmpeg-wasm |
| 64 | + key: ffmpeg-wasm-${{ hashFiles('scripts/build/web/build-ffmpeg-wasm.sh') }} |
| 65 | + |
| 66 | + - name: Build FFmpeg For wasm |
| 67 | + if: steps.cache-ffmpeg-wasm.outputs.cache-hit != 'true' |
| 68 | + run: | |
| 69 | + NPROC="$(nproc)" bash scripts/build/web/build-ffmpeg-wasm.sh "${GITHUB_WORKSPACE}/build/ffmpeg-wasm" |
| 70 | +
|
| 71 | + - name: Cache CMake Dependencies |
| 72 | + uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3 |
| 73 | + with: |
| 74 | + path: | |
| 75 | + build/web-generalsmd-sdl3-bgfx/_deps |
| 76 | + build/web-generalsmd-sdl3-bgfx/host-shaderc |
| 77 | + key: cmake-deps-web-generalsmd-sdl3-bgfx-${{ hashFiles('CMakePresets.json','cmake/**/*.cmake','**/CMakeLists.txt') }} |
| 78 | + restore-keys: | |
| 79 | + cmake-deps-web-generalsmd-sdl3-bgfx- |
| 80 | +
|
| 81 | + - name: Configure with CMake |
| 82 | + run: | |
| 83 | + FFMPEG_PREFIX="${GITHUB_WORKSPACE}/build/ffmpeg-wasm" |
| 84 | + cmake --preset web-generalsmd-sdl3-bgfx \ |
| 85 | + -DFFMPEG_INCLUDE_DIR="${FFMPEG_PREFIX}/include" \ |
| 86 | + -DFFMPEG_AVCODEC_LIBRARY="${FFMPEG_PREFIX}/lib/libavcodec.a" \ |
| 87 | + -DFFMPEG_AVFORMAT_LIBRARY="${FFMPEG_PREFIX}/lib/libavformat.a" \ |
| 88 | + -DFFMPEG_AVUTIL_LIBRARY="${FFMPEG_PREFIX}/lib/libavutil.a" \ |
| 89 | + -DFFMPEG_SWSCALE_LIBRARY="${FFMPEG_PREFIX}/lib/libswscale.a" |
| 90 | +
|
| 91 | + - name: Build GeneralsMD |
| 92 | + run: | |
| 93 | + cmake --build build/web-generalsmd-sdl3-bgfx --config Release --target z_generals -j"$(nproc)" |
| 94 | +
|
| 95 | + - name: Stage |
| 96 | + run: | |
| 97 | + STAGE="${GITHUB_WORKSPACE}/stage-web/GeneralsZH-web" |
| 98 | + mkdir -p "${STAGE}" |
| 99 | + # Ninja Multi-Config appends the configuration to the output directory. |
| 100 | + WEB_DIR="build/web-generalsmd-sdl3-bgfx/web" |
| 101 | + if [ -d "${WEB_DIR}/Release" ]; then |
| 102 | + WEB_DIR="${WEB_DIR}/Release" |
| 103 | + fi |
| 104 | + cp -r "${WEB_DIR}"/. "${STAGE}/" |
| 105 | + cp scripts/build/web/serve.py "${STAGE}/serve.py" |
| 106 | + { |
| 107 | + echo "Command & Conquer Generals Zero Hour (GeneralsMD) WebAssembly build" |
| 108 | + echo "preset: web-generalsmd-sdl3-bgfx (Release, wasm32)" |
| 109 | + echo "ref: ${{ inputs.ref || github.ref_name }}" |
| 110 | + echo "commit: $(git rev-parse HEAD)" |
| 111 | + echo "built: $(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 112 | + echo |
| 113 | + echo "Serve this directory over HTTP with cross-origin isolation enabled" |
| 114 | + echo "(COOP: same-origin, COEP: require-corp) and point serve.py at a copy" |
| 115 | + echo "of the game data you own. The page will not boot from file://." |
| 116 | + } > "${STAGE}/BUILD_INFO.txt" |
| 117 | +
|
| 118 | + - name: Zip |
| 119 | + run: | |
| 120 | + cd "${GITHUB_WORKSPACE}/stage-web/GeneralsZH-web" |
| 121 | + zip -ry "${GITHUB_WORKSPACE}/GeneralsZH-web.zip" . |
| 122 | +
|
| 123 | + - name: Upload Artifact |
| 124 | + uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0 |
| 125 | + with: |
| 126 | + name: GeneralsZH-web |
| 127 | + path: GeneralsZH-web.zip |
| 128 | + retention-days: 30 |
| 129 | + if-no-files-found: error |
0 commit comments