Skip to content

Enable System Emulation in Web Browsers #602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
132 changes: 110 additions & 22 deletions .github/workflows/deploy-wasm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,107 @@ on:
branches:
- master
repository_dispatch: # listening to rv32emu-prebuilt events
types: [deploy_wasm]
types: [deploy_user_wasm, deploy_system_wasm]

jobs:
wasm-deploy:
wasm-system-deploy:
if: github.event.pull_request.merged == true ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch'
github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm'
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
- name: install-dependencies
run: |
sudo apt-get update -q=2
sudo apt-get install -q=2 device-tree-compiler
- name: Verify if the JS or HTML files has been modified
id: changed-files
uses: tj-actions/changed-files@v46
with:
files: |
assets/wasm/html/system.html
assets/wasm/js/system-pre.js
# Files below may have a potential performance impact (reference from benchmark.yml)
src/devices/*.c
src/system.c
src/riscv.c
src/decode.c
src/emulate.c
src/rv32_template.c
src/rv32_constopt.c
- name: install emcc
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
run: |
git clone https://github.com/emscripten-core/emsdk -b 3.1.51
cd emsdk
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
echo "$PATH" >> $GITHUB_PATH
shell: bash
- name: fetch artifact
run: |
make artifact
# get from rv32emu-prebuilt
wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip"
unzip -d build/ build/shareware_doom_iwad.zip
- name: build with emcc and move application files to /tmp
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
run: |
make CC=emcc ENABLE_SYSTEM=1 ENABLE_SDL=1 INITRD_SIZE=32 -j
mkdir /tmp/rv32emu-system-demo
mv assets/wasm/html/system.html /tmp/rv32emu-system-demo/index.html
mv assets/wasm/js/coi-serviceworker.min.js /tmp/rv32emu-system-demo
mv build/rv32emu.js /tmp/rv32emu-system-demo
mv build/rv32emu.wasm /tmp/rv32emu-system-demo
mv build/rv32emu.worker.js /tmp/rv32emu-system-demo
ls -al /tmp/rv32emu-system-demo
- name: Check out the rv32emu-system-demo repo
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
repository: sysprog21/rv32emu-demo
- name: Create local changes
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
run: |
mkdir -p system
mv /tmp/rv32emu-system-demo/index.html ./system
mv /tmp/rv32emu-system-demo/coi-serviceworker.min.js ./system
mv /tmp/rv32emu-system-demo/rv32emu.js ./system
mv /tmp/rv32emu-system-demo/rv32emu.wasm ./system
mv /tmp/rv32emu-system-demo/rv32emu.worker.js ./system
- name: Commit files
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add system/
git commit -m "Add changes to system emulation"
- name: Push changes
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_system_wasm') }}
uses: ad-m/github-push-action@master
with:
repository: sysprog21/rv32emu-demo
github_token: ${{ secrets.RV32EMU_DEMO_TOKEN }}
branch: main
wasm-user-deploy:
needs: wasm-system-deploy # run jobs sequentially since two jobs operate on same reposity: rv32emu-demo
if: always() # ensures wasm-user-deploy runs regardless of the outcome or condition of wasm-system-deploy
runs-on: ubuntu-latest
steps:
- name: Check out the repo
Expand All @@ -26,8 +120,8 @@ jobs:
uses: tj-actions/changed-files@v46
with:
files: |
assets/wasm/html/index.html
assets/wasm/js/pre.js
assets/wasm/html/user.html
assets/wasm/js/user-pre.js
build/*.elf
tools/gen-elf-list-js.py
# Files below may have a potential performance impact (reference from benchmark.yml)
Expand All @@ -39,12 +133,10 @@ jobs:
- name: install emcc
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
run: |
git clone https://github.com/emscripten-core/emsdk.git
git clone https://github.com/emscripten-core/emsdk -b 3.1.51
cd emsdk
git pull
git checkout 3.1.51
./emsdk install latest
./emsdk activate latest
source ./emsdk_env.sh
Expand All @@ -53,21 +145,17 @@ jobs:
- name: fetch artifact
run: |
make artifact
# Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download
wget --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" \
--header="Referer: https://www.doomworld.com/" \
--header="Accept-Language: en-US,en;q=0.9" \
-O build/shareware_doom_iwad.zip \
"https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip"
# get from rv32emu-prebuilt
wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip"
unzip -d build/ build/shareware_doom_iwad.zip
- name: build with emcc and move application files to /tmp
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
run: |
make CC=emcc ENABLE_SDL=1
mkdir /tmp/rv32emu-demo
mv assets/wasm/html/index.html /tmp/rv32emu-demo
mv assets/wasm/html/user.html /tmp/rv32emu-demo/index.html
mv assets/wasm/js/coi-serviceworker.min.js /tmp/rv32emu-demo
mv build/elf_list.js /tmp/rv32emu-demo
mv build/rv32emu.js /tmp/rv32emu-demo
Expand All @@ -77,15 +165,15 @@ jobs:
- name: Check out the rv32emu-demo repo
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
uses: actions/checkout@v4
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token.
repository: sysprog21/rv32emu-demo
- name: Create local changes
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
run: |
mv /tmp/rv32emu-demo/index.html .
mv /tmp/rv32emu-demo/coi-serviceworker.min.js .
Expand All @@ -96,16 +184,16 @@ jobs:
- name: Commit files
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add --all
git commit -m "Add changes"
git commit -m "Add changes to user emulation"
- name: Push changes
if: ${{ steps.changed-files.outputs.any_modified == 'true' ||
github.event_name == 'workflow_dispatch' ||
github.event_name == 'repository_dispatch' }}
(github.event_name == 'repository_dispatch' && github.event.action == 'deploy_user_wasm') }}
uses: ad-m/github-push-action@master
with:
repository: sysprog21/rv32emu-demo
Expand Down
16 changes: 4 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,8 @@ jobs:
make artifact
make ENABLE_SYSTEM=1 artifact
make ENABLE_ARCH_TEST=1 artifact
# Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download
wget --header="User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" \
--header="Referer: https://www.doomworld.com/" \
--header="Accept-Language: en-US,en;q=0.9" \
-O build/shareware_doom_iwad.zip \
"https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip"
# get from rv32emu-prebuilt
wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip"
unzip -d build/ build/shareware_doom_iwad.zip
if: ${{ always() }}
- name: default build using emcc
Expand Down Expand Up @@ -394,12 +390,8 @@ jobs:
| head -n 1 \
| sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
make LATEST_RELEASE=$LATEST_RELEASE ENABLE_ARCH_TEST=1 artifact
# Hack Cloudflare 403 Forbidden on GitHub Runner for Doom artifact download
wget --header="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Safari/605.1.15" \
--header="Referer: https://www.doomworld.com/" \
--header="Accept-Language: en-US,en;q=0.9" \
-O build/shareware_doom_iwad.zip \
"https://www.doomworld.com/3ddownloads/ports/shareware_doom_iwad.zip"
# get from rv32emu-prebuilt
wget -O build/shareware_doom_iwad.zip "https://raw.githubusercontent.com/sysprog21/rv32emu-prebuilt/doom-artifact/shareware_doom_iwad.zip"
unzip -d build/ build/shareware_doom_iwad.zip
if: ${{ always() }}
- name: default build using emcc
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ $(OUT)/emulate.o: CFLAGS += -foptimize-sibling-calls -fomit-frame-pointer -fno-s

include mk/external.mk
include mk/artifact.mk
include mk/wasm.mk
include mk/system.mk
include mk/wasm.mk

all: config $(BUILD_DTB) $(BUILD_DTB2C) $(BIN)

Expand Down
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,25 @@ $ source ~/emsdk/emsdk_env.sh
Change the Emscripten SDK environment path if necessary.
At this point, you can build and start a web server service to serve WebAssembly by running:
- user space emulation:
```shell
$ make CC=emcc start-web
$ make CC=emcc start-web -j8
```
- system emulation:
```shell
$ make CC=emcc start-web ENABLE_SYSTEM=1 INITRD_SIZE=32 -j8
```
You would see the server's IP:PORT in your terminal. Copy and paste it to the browsers and
you just access the index page of `rv32emu`.
You would see a dropdown menu which you can use to select the ELF executable. Select one and
click the Run button to run it.
You would see a dropdown menu which you can use to select the ELF executable for user space emulation, select one and
click the 'Run' button to run it. For system emulation, click the 'Run Linux' button to boot Linux.
Alternatively, you may want to view a hosted `rv32emu` since building takes some time.
- [user space emulation demo page](https://sysprog21.github.io/rv32emu-demo/)
- [system emulation demo page](https://sysprog21.github.io/rv32emu-demo/system)
Alternatively, you may want to view a hosted `rv32emu` [demo page](https://sysprog21.github.io/rv32emu-demo/) since building takes some time.
Both pages can be easily switched using the navigation button.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
Expand Down
Loading
Loading