standalone: Add wasmer to makefile

This commit is contained in:
Remko Tronçon 2022-05-26 19:33:06 +02:00
parent 15d8d91fdc
commit d40dcc1b4d
2 changed files with 37 additions and 12 deletions

View file

@ -33,13 +33,16 @@ document](doc/Design.md).
## Standalone shell
Although WAForth is typically used in a web environment (browser, Node.JS), there also is a standalone
command-line shell. You can download a pre-built binary of the standalone shell from
Although WebAssembly (and therefore WAForth) is typically used in a web environment
(web browsers, Node.js), WAForth also has a standalone command-line shell.
You can download a pre-built binary of the standalone shell from
[the Releases page](https://github.com/remko/waforth/releases).
The standalone shell is built using [wasmtime](https://wasmtime.dev),
but can easily be adapted to be built using other WASM libraries that support the
[WebAssembly C API](https://github.com/WebAssembly/wasm-c-api).
but the build configuration can easily be adapted to build using any
WebAssembly engine that supports the
[WebAssembly C API](https://github.com/WebAssembly/wasm-c-api) (although some
have [known issues](https://github.com/remko/waforth/issues/6#issue-326830993)).
## Using WAForth in a JavaScript application

View file

@ -1,19 +1,44 @@
UNAME_S=$(shell uname -s)
UNAME_P=$(shell uname -p)
.DEFAULT_GOAL := all
################################################
# WebAssembly engine configuration
################################################
# Wasmer (https://wasmer.io)
# WARNING! Loading compiled words does not work
ifeq ($(WASMER),1)
WASMER_DIR=$(HOME)/.wasmer
CFLAGS=-I$(WASMER_DIR)/include
LIBS:=$(WASMER_DIR)/lib/libwasmer.a
else
# Wasmtime (https://wasmtime.dev)
ifeq ($(UNAME_S),Darwin)
WASMTIME_DIR=wasmtime-v0.37.0-x86_64-macos-c-api
WASMTIME_RELEASE_URL=https://github.com/bytecodealliance/wasmtime/releases/download/v0.37.0/wasmtime-v0.37.0-x86_64-macos-c-api.tar.xz
PACKAGE_SUFFIX=x86_64-macos
else
WASMTIME_DIR=wasmtime-v0.37.0-x86_64-linux-c-api
WASMTIME_RELEASE_URL=https://github.com/bytecodealliance/wasmtime/releases/download/v0.37.0/wasmtime-v0.37.0-x86_64-linux-c-api.tar.xz
LIBS=-lpthread -lm -ldl
PACKAGE_SUFFIX=x86_64-linux
endif
CFLAGS=-I$(WASMTIME_DIR)/include
LIBS:=$(WASMTIME_DIR)/lib/libwasmtime.a $(LIBS)
install-deps:
-rm -rf wasmtime-*
curl -L -s $(WASMTIME_RELEASE_URL) | tar xJv
endif
CFLAGS=-I$(WASMTIME_DIR)/include
LDFLAGS=
LIBS:=$(WASMTIME_DIR)/lib/libwasmtime.a $(LIBS)
################################################
ifeq ($(UNAME_S),Darwin)
PACKAGE_SUFFIX=x86_64-macos
else
PACKAGE_SUFFIX=x86_64-linux
endif
VERSION?=$(shell cat ../../package.json | grep '"version"' | sed -e 's/.*:.*"\(.*\)".*/\1/')
BIN2H=../../scripts/bin2h
@ -37,9 +62,6 @@ waforth_core.h: waforth_core.wasm
$(BIN2H) $< $@
.PHONY: install-deps
install-deps:
-rm -rf wasmtime-*
curl -L -s $(WASMTIME_RELEASE_URL) | tar xJv
.PHONY: package
package: waforth