forked from seanmorris/php-wasm
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
112 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Simple workflow for deploying static content to GitHub Pages | ||
name: Deploy static content to Pages | ||
|
||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
|
||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
# Single deploy job since we're just deploying | ||
deploy: | ||
environment: | ||
name: github-pages | ||
url: ${{ steps.deployment.outputs.page_url }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- | ||
name: Build PHP WASM | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
push: false | ||
tags: soyuka/php-wasm:latest | ||
cache-from: type=gha | ||
cache-to: type=gha,mode=max | ||
- name: Setup Pages | ||
uses: actions/configure-pages@v3 | ||
- name: Build website | ||
working-directory: demo | ||
run: | | ||
docker create --name=php-wasm soyuka/php-wasm:latest | ||
mkdir -p public/ dist/ | ||
docker cp php-wasm:/build/php-web.mjs ./dist | ||
docker cp php-wasm:/build/php-web.wasm ./public | ||
docker run -v $(pwd)/src:/src -v $(pwd)/public:/public -v $(pwd)/dist:/dist php-wasm python3 /emsdk/upstream/emscripten/tools/file_packager.py /public/php-web.data --use-preload-cache --lz4 --preload "/src" --js-output=/dist/php-web.data.js --no-node --exclude '*/.*' --export-name=createPhpModule | ||
sed '/--pre-js/r dist/php-web.data.js' dist/php-web.mjs > public/php-web.mjs | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v2 | ||
with: | ||
path: 'demo/public' | ||
- name: Deploy to GitHub Pages | ||
id: deployment | ||
uses: actions/deploy-pages@v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist/ | ||
public/ | ||
!public/index.html | ||
public/php-web.mjs | ||
public/php-web.data | ||
public/php-web.wasm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,43 @@ | ||
<iframe id="output"></iframe> | ||
<iframe id="output" width="100%" height="50%" frameBorder="0"></iframe> | ||
<script type="module"> | ||
import Module from "./php-web.mjs"; | ||
const STR = "string"; | ||
const output = document.getElementById('output'); | ||
const buffer = '' | ||
import phpBinary from "./php-web.mjs"; | ||
|
||
Module({ | ||
print(data) { | ||
buffer += data; | ||
// output.setAttribute('srcdoc', data); | ||
}, | ||
printErr(data) { | ||
if (data) { | ||
console.log("stderr: ", data); | ||
async function main() { | ||
const output = document.getElementById('output') | ||
const buffer = []; | ||
const {ccall, FS} = await phpBinary({ | ||
print(data) { | ||
buffer.push(data); | ||
} | ||
}, | ||
}).then(({ ccall, FS, IDBFS }) => { | ||
console.log(ccall("phpw_exec", STR, [STR], ["phpversion();"])); | ||
}) | ||
|
||
// Note that `/src` is the path we used when preloading! | ||
// ccall("phpw", null, [STR], ["/src/index.php"]); | ||
console.log(ccall("phpw_exec", "string", ["string"], ["phpversion();"])); | ||
|
||
window.FS = FS; | ||
window.run = () => { | ||
// Note that `/src` is the path we used when preloading! | ||
ccall("phpw", null, ["string"], ["/src/index.php"]); | ||
output.contentWindow.document.body.innerHTML = buffer.join(''); | ||
buffer.length = 0; | ||
} | ||
|
||
run(); | ||
} | ||
|
||
main(); | ||
</script> | ||
<div id="monaco" style="min-height: 100px"></div> | ||
<script type="module"> | ||
import * as monaco from 'https://cdn.jsdelivr.net/npm/monaco-editor@0.39.0/+esm'; | ||
const editor = monaco.editor.create(document.getElementById('monaco')); | ||
// FS is documented at https://emscripten.org/docs/api_reference/Filesystem-API.html | ||
// everything is synchronous | ||
const model = editor.getModel(); | ||
model.setLanguage('php'); | ||
model.setValue(window.FS.readFile('/src/index.php', {encoding: 'utf8'}).toString()); | ||
model.onDidChangeContent((v) => { | ||
window.FS.unlink('/src/index.php') | ||
window.FS.writeFile('/src/index.php', model.getValue()); | ||
window.run(); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
<?php | ||
|
||
phpinfo(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters