Skip to content

Commit

Permalink
Compile to WebAssembly (experimental)
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 21, 2024
1 parent 83f4334 commit 36d1a3e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ jobs:
- name: Install git, linguist
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: git ruby-github-linguist
version: docs
packages: git ruby-github-linguist emscripten
version: docs2

- name: Build sphinx docs
run: make docs_dependencies html
Expand Down
17 changes: 12 additions & 5 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,17 @@ native_test: native

.PHONY: clean
clean:
@rm -rf build {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo
@rm -rf build dist {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo

.PHONY: wasm
wasm: ../LICENSE
@wget https://github.com/jedisct1/libclang_rt.builtins-wasm32.a -O wasm32.a
dist/lib.wasm: build/lib.c
@mkdir -p dist
@emcc build/lib.c -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/lib.js

build/lib.c: ../LICENSE
@mkdir -p build
@clang -DUNITY_END --target=wasm32-unknown-wasi --sysroot /tmp/wasi-libc -nostartfiles -Wl,--import-memory -Wl,--no-entry -Wl,--export-all -o build/c.wasm test.c
@> build/lib.c
@for file in src/p*.c; do \
if [ -f "$$file" ]; then \
echo "#include \"../$$file\"" >> build/lib.c; \
fi \
done
1 change: 0 additions & 1 deletion c/wasi-libc
Submodule wasi-libc deleted from 5d3c5e
15 changes: 14 additions & 1 deletion cplusplus/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ native_test: native

.PHONY: clean
clean:
@rm -rf build {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo
@rm -rf build dist {.,*,*/*}/{*.pyc,__pycache__,.mypy_cache,.pytest_cache,.benchmarks} || echo

dist/lib.wasm: build/lib.cpp
@mkdir -p dist
@emc++ build/lib.cpp -Wl,--whole-archive -DUNITY_END -O$(O) -o dist/lib.js

build/lib.cpp: ../LICENSE
@mkdir -p build
@> build/lib.cpp
@for file in src/p*.cpp; do \
if [ -f "$$file" ]; then \
echo "#include \"../$$file\"" >> build/lib.c; \
fi \
done
7 changes: 6 additions & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ _static/dist/bundle.js:
@mkdir -p _static/dist
@cp ../javascript/dist/bundle-js.js _static/dist/bundle-js.js

_static/dist/cplusplus-lib.js:
@$(MAKE) -C ../cplusplus dist/lib.js $(MFLAGS)
@cp ../c/dist/lib.js _static/dist/cp-lib.js
@cp ../c/dist/lib.wasm _static/dist/cp-lib.wasm

_static/dist/rust.js:
@cd ../rust && wasm-pack build --target web --out-dir ../docs/_static/dist/

Expand All @@ -48,7 +53,7 @@ _static/dist/python.tar.gz:

.PHONY: html
html:
@$(MAKE) _static/dist/bundle.js _static/dist/python.tar.gz _static/dist/rust.js $(MFLAGS) -j
@$(MAKE) _static/dist/bundle.js _static/dist/c-lib.js _static/dist/cplusplus-lib.js _static/dist/python.tar.gz _static/dist/rust.js $(MFLAGS) -j
@$(SPHINXBUILD) -M html "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

# Catch-all target: route all unknown targets to Sphinx using the new
Expand Down

0 comments on commit 36d1a3e

Please sign in to comment.