Skip to content

Commit 5bc88a7

Browse files
committed
Add Emscripten builds
1 parent 9a28224 commit 5bc88a7

File tree

3 files changed

+118
-3
lines changed

3 files changed

+118
-3
lines changed

.github/workflows/cmake.yml

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
butler-url: https://broth.itch.ovh/butler/windows-amd64/LATEST/archive/default
2929
- os: macos-14
3030
triplet: arm64-osx
31-
platform-name: macos.x64
31+
platform-name: macos.arm64
3232
butler-url: https://broth.itch.ovh/butler/darwin-amd64/LATEST/archive/default
3333
- os: ubuntu-24.04
3434
triplet: x64-linux
@@ -128,7 +128,7 @@ jobs:
128128
tag: ${{ github.ref }}
129129
overwrite: true
130130
- name: Install Butler
131-
if: github.ref == 'refs/heads/main'
131+
if: github.ref == 'refs/heads/main' && matrix.butler-url
132132
run: |
133133
mkdir ~/bin
134134
cd ~/bin
@@ -138,7 +138,72 @@ jobs:
138138
echo "~/bin" >> $GITHUB_PATH
139139
~/bin/butler -V
140140
- name: Upload to Itch
141-
if: github.ref == 'refs/heads/main'
141+
if: github.ref == 'refs/heads/main' && matrix.butler-url
142142
env:
143143
BUTLER_API_KEY: ${{ secrets.BUTLER_API_KEY }}
144144
run: butler push dist/${{ env.archive-name }} hexdecimal/${{ env.project-name }}:${{ matrix.platform-name }}-latest
145+
146+
emscripten:
147+
runs-on: ubuntu-24.04
148+
env:
149+
EM_VERSION: 4.0.5
150+
EM_CACHE_FOLDER: "emsdk-cache"
151+
steps:
152+
- uses: actions/checkout@v4
153+
with:
154+
submodules: true
155+
- name: Restore vcpkg and its artifacts
156+
uses: actions/cache@v4
157+
with:
158+
path: |
159+
build/vcpkg_installed/
160+
${{ env.VCPKG_ROOT }}
161+
!${{ env.VCPKG_ROOT }}/buildtrees
162+
!${{ env.VCPKG_ROOT }}/packages
163+
!${{ env.VCPKG_ROOT }}/downloads
164+
key: wasm32-emscripten-${{ hashFiles('vcpkg.json', '.git/modules/vcpkg/HEAD') }}
165+
- name: Setup cache
166+
id: cache-system-libraries
167+
uses: actions/cache@v4
168+
with:
169+
path: ${{env.EM_CACHE_FOLDER}}
170+
key: ${{env.EM_VERSION}}-${{ runner.os }}
171+
- uses: mymindstorm/setup-emsdk@v14
172+
with:
173+
version: ${{env.EM_VERSION}}
174+
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
175+
- name: Verify
176+
run: emcc -v
177+
- uses: lukka/get-cmake@latest
178+
- name: Configure
179+
run: emcmake cmake -S . -B build -G Ninja
180+
-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE="${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake"
181+
-DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake
182+
-DVCPKG_TARGET_TRIPLET=wasm32-emscripten
183+
-DCMAKE_BUILD_TYPE="${{ env.BUILD_TYPE }}"
184+
- name: Build
185+
run: cmake --build build
186+
- name: Show contents of the build directory
187+
run: find build
188+
- uses: actions/upload-artifact@v4
189+
with:
190+
name: emscripten-builds
191+
path: build/bin
192+
retention-days: 7
193+
if-no-files-found: error
194+
compression-level: 6
195+
- name: Install Butler
196+
if: github.ref == 'refs/heads/main'
197+
run: |
198+
mkdir ~/bin
199+
cd ~/bin
200+
curl -L -o butler.zip https://broth.itch.ovh/butler/linux-amd64/LATEST/archive/default
201+
unzip butler.zip
202+
chmod +x butler
203+
echo "~/bin" >> $GITHUB_PATH
204+
~/bin/butler -V
205+
- name: Upload to Itch
206+
if: github.ref == 'refs/heads/main'
207+
env:
208+
BUTLER_API_KEY: ${{ secrets.BUTLER_API_KEY }}
209+
run: butler push dist/${{ env.archive-name }} hexdecimal/${{ env.project-name }}:emscripten-latest

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ else()
3333
target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra)
3434
endif()
3535

36+
if (EMSCRIPTEN)
37+
# Attach data folder to Emscripten builds.
38+
target_link_options(${PROJECT_NAME} PRIVATE --preload-file "${CMAKE_CURRENT_SOURCE_DIR}/data@data")
39+
target_link_options(${PROJECT_NAME} PRIVATE -lidbfs.js) # Enable IDBFS (browser file system.)
40+
configure_file(
41+
${PROJECT_SOURCE_DIR}/emscripten/index.html
42+
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/index.html
43+
)
44+
endif()
45+
3646
target_compile_definitions(${PROJECT_NAME} PRIVATE _USE_MATH_DEFINES) # For M_PI
3747
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_SOUND)
3848
target_compile_definitions(${PROJECT_NAME} PRIVATE NO_LUA)

emscripten/index.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!doctype HTML>
2+
<html lang=en-us>
3+
4+
<head>
5+
<meta charset=utf-8>
6+
<title>Pyromancer</title>
7+
<style>
8+
body {
9+
background-color: #000;
10+
margin: 0;
11+
padding: none;
12+
}
13+
14+
.center {
15+
display: flex;
16+
justify-content: center;
17+
align-items: center;
18+
}
19+
20+
canvas {
21+
display: contents;
22+
width: calc(min(100vw, 80 / 60 * 100vh));
23+
}
24+
</style>
25+
</head>
26+
27+
<body onload=window.focus()>
28+
<div class=center>
29+
<canvas id=canvas oncontextmenu=event.preventDefault() tabindex=-1 onclick=window.focus()></canvas>
30+
</div>
31+
<script>
32+
var Module = {
33+
print(...args) { console.log("%s", ...args); },
34+
canvas: document.getElementById('canvas'),
35+
};
36+
</script>
37+
<script async src=${PROJECT_NAME}.js></script>
38+
</body>
39+
40+
</html>

0 commit comments

Comments
 (0)