Skip to content

Commit

Permalink
Add wasm deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
m110 committed Nov 23, 2023
1 parent fb35204 commit 9d72c30
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/deploy-web.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy Web
on:
push:
branches:
- master
permissions:
contents: read
pages: write
id-token: write
jobs:
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
with:
go-version: '^1.21'
- run: go build -o web/game.wasm
env:
GOOS: js
GOARCH: wasm
- run: cp $(go env GOROOT)/misc/wasm/wasm_exec.js web/

- uses: actions/configure-pages@v2
- uses: actions/upload-pages-artifact@v1
with:
path: web
- id: deployment
uses: actions/deploy-pages@v1
15 changes: 15 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<style>
body {
background-color: #000000;
}

iframe {
margin: 0 auto;
display: block;
border: 0;
}
</style>
<body>
<iframe src="main.html" width="800" height="600" allow="autoplay"></iframe>
</body>
16 changes: 16 additions & 0 deletions web/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<script src="wasm_exec.js"></script>
<script>
// Polyfill
if (!WebAssembly.instantiateStreaming) {
WebAssembly.instantiateStreaming = async (resp, importObject) => {
const source = await (await resp).arrayBuffer();
return await WebAssembly.instantiate(source, importObject);
};
}

const go = new Go();
WebAssembly.instantiateStreaming(fetch("game.wasm"), go.importObject).then(result => {
go.run(result.instance);
});
</script>

0 comments on commit 9d72c30

Please sign in to comment.