Skip to content

Commit

Permalink
wasm: add wasmer, lucet modes. Update wasmtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
kanaka committed Aug 10, 2019
1 parent dafae29 commit 1e9eb42
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 46 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ matrix:
- {env: IMPL=vb, services: [docker]}
- {env: IMPL=vhdl NO_SELF_HOST_PERF=1, services: [docker]} # perf timeout
- {env: IMPL=vimscript, services: [docker]}
- {env: IMPL=wasm wasm_MODE=wasmtime NO_SELF_HOST_PERF=1, services: [docker]} # mac stack overflow
- {env: IMPL=wasm wasm_MODE=wax NO_SELF_HOST_PERF=1, services: [docker]} # mac stack overflow
- {env: IMPL=wasm wasm_MODE=node NO_SELF_HOST_PERF=1, services: [docker]} # mac stack overflow
- {env: IMPL=wasm wasm_MODE=wace_libc NO_SELF_HOST_PERF=1, services: [docker]} # mac stack overflow
- {env: IMPL=wasm wasm_MODE=warpy NO_SELF_HOST_PERF=1, services: [docker]} # mac stack overflow
# no self-host perf for wasm due to mac stack overflow
- {env: IMPL=wasm wasm_MODE=wasmtime NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=wasmer NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=lucet NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=wax NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=node NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=warpy NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=wasm wasm_MODE=wace_libc NO_SELF_HOST_PERF=1, services: [docker]}
- {env: IMPL=yorick, services: [docker]}

script:
Expand Down
2 changes: 1 addition & 1 deletion .travis_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fi
case "${ACTION}" in
build)
# rpython often fails on step9 in compute_vars_longevity
# so build step9, then continue wit the full build
# so build step9, then continue with the full build
if [ "${BUILD_IMPL}" = "rpython" ]; then
${MAKE} -C "${BUILD_IMPL}" step9_try || true
fi
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ matlab_MODE = octave
python_MODE = python
# scheme (chibi, kawa, gauche, chicken, sagittarius, cyclone, foment)
scheme_MODE = chibi
# wasmtime js node wace_libc wace_fooboot
# wasmtime wasmer lucet wax node js wace_fooboot warpy wace_libc
wasm_MODE = wasmtime

# Path to loccount for counting LOC stats
Expand Down Expand Up @@ -259,7 +259,7 @@ vala_STEP_TO_PROG = vala/$($(1))
vb_STEP_TO_PROG = vb/$($(1)).exe
vhdl_STEP_TO_PROG = vhdl/$($(1))
vimscript_STEP_TO_PROG = vimscript/$($(1)).vim
wasm_STEP_TO_PROG = wasm/$($(1)).wasm
wasm_STEP_TO_PROG = wasm/$($(1)).$(if $(filter lucet,$(wasm_MODE)),so,wasm)
yorick_STEP_TO_PROG = yorick/$($(1)).i


Expand Down
95 changes: 75 additions & 20 deletions wasm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ RUN git clone https://github.com/WebAssembly/binaryen/ && \
cd .. && \
rm -r binaryen

#########################################################################
FROM base as build_runtimes
###########################################################################
FROM base as build_tools
###########################################################################

#
# clang/LLVM and rust (for building wasmtime)
#
RUN apt-get -y install llvm-3.9-dev libclang-3.9-dev clang-3.9
RUN apt-get -y install curl && \
RUN apt-get -y install curl && \
curl https://sh.rustup.rs -sSf > /tmp/rustup.sh && \
sh /tmp/rustup.sh -y
ENV PATH $PATH:/root/.cargo/bin
Expand Down Expand Up @@ -101,14 +102,32 @@ RUN apt-get -y install software-properties-common && \
#
# wasi-sdk (C/C++ -> wasm+wasi)
#
RUN curl -LO https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-3/wasi-sdk_3.0_amd64.deb && \
dpkg -i wasi-sdk_3.0_amd64.deb && \
rm wasi-sdk_3.0_amd64.deb
RUN curl -LO https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-5/wasi-sdk_5.0_amd64.deb && \
dpkg -i wasi-sdk_5.0_amd64.deb && \
rm wasi-sdk_5.0_amd64.deb

##
## Rust wasm support
##
#RUN rustup default nightly
#RUN rustup target add wasm32-unknown-wasi --toolchain nightly
##RUN cargo +nightly build --target wasm32-unknown-wasi
#
## TODO: Do this when we install rust instead
#RUN mv /root/.cargo /opt/cargo && mv /root/.rustup /opt/rustup
#RUN chmod -R a+r /opt/cargo && chmod -R a+rw /opt/rustup
#ENV CARGO_HOME /opt/cargo
#ENV RUSTUP_HOME /opt/rustup
#ENV PATH $PATH:/opt/cargo/bin

###########################################################################
FROM build_tools as runtimes
###########################################################################

#
# warpy
#
RUN git clone https://github.com/kanaka/warpy/ && \
RUN git clone https://github.com/kanaka/warpy/ && \
cd warpy && \
make warpy-nojit && \
cp warpy-nojit /usr/bin/warpy
Expand All @@ -121,23 +140,59 @@ RUN git clone https://github.com/kanaka/wac/ && \
make USE_SDL= wac wax wace && \
cp wac wax wace /usr/bin

#
# wasmer
#

RUN curl https://get.wasmer.io -sSfL | sh && \
cp /root/.wasmer/bin/wasmer /usr/bin/wasmer && \
cp /root/.wasmer/bin/wapm /usr/bin/wapm

#RUN git clone --recursive https://github.com/wasmerio/wasmer && \
# cd wasmer && \
# cargo build --release && \
# cp target/release/wasmer /usr/bin/

#
# lucet
#

RUN git clone --recursive https://github.com/fastly/lucet && \
cd lucet && \
make install

#
# wasmtime
#
RUN git clone --recursive https://github.com/CraneStation/wasmtime && \
cd wasmtime && \
cargo build --release && \
cp target/release/wasmtime /usr/bin/ && \
cp target/release/wasm2obj /usr/bin/

RUN curl -L https://github.com/CraneStation/wasmtime/releases/download/dev/wasmtime-dev-x86_64-linux.tar.xz | tar xvJf - && \
cp wasmtime-dev-x86_64-linux/wasmtime /usr/bin/wasmtime && \
cp wasmtime-dev-x86_64-linux/wasm2obj /usr/bin/wasm2obj

#RUN git clone --recursive https://github.com/CraneStation/wasmtime && \
# cd wasmtime && \
# sed -i 's/c3994bf57b5d2f1f973b0e4e37bc385695aa4ed2/8ea7a983d8b1364e5f62d2adf0e74b3b8db1c9b3/' Cargo.toml && \
# cargo build --release && \
# cp target/release/wasmtime /usr/bin/ && \
# cp target/release/wasm2obj /usr/bin/

#########################################################################
FROM base as wasm

COPY --from=build_runtimes /usr/bin/wac /usr/bin/wac
COPY --from=build_runtimes /usr/bin/wax /usr/bin/wax
COPY --from=build_runtimes /usr/bin/wace /usr/bin/wace
COPY --from=build_runtimes /usr/bin/warpy /usr/bin/warpy
COPY --from=build_runtimes /usr/bin/wasmtime /usr/bin/wasmtime
COPY --from=build_runtimes /usr/bin/wasm2obj /usr/bin/wasm2obj
###########################################################################
FROM base as wasm
###########################################################################

COPY --from=runtimes /usr/bin/wac /usr/bin/wac
COPY --from=runtimes /usr/bin/wax /usr/bin/wax
COPY --from=runtimes /usr/bin/wace /usr/bin/wace
COPY --from=runtimes /usr/bin/warpy /usr/bin/warpy
COPY --from=runtimes /usr/bin/wasmtime /usr/bin/wasmtime
COPY --from=runtimes /usr/bin/wasm2obj /usr/bin/wasm2obj

RUN mkdir -p /opt/lucet/bin
COPY --from=runtimes /opt/lucet/ /opt/lucet
RUN ln -sf /opt/lucet/bin/lucetc-wasi /usr/bin/lucetc-wasi
RUN ln -sf /opt/lucet/bin/lucet-wasi /usr/bin/lucet-wasi

COPY --from=runtimes /usr/bin/wasmer /usr/bin/wasmer
COPY --from=runtimes /usr/bin/wapm /usr/bin/wapm

33 changes: 21 additions & 12 deletions wasm/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
MODE ?= $(strip \
$(if $(filter wasi wax wasmtime,$(wasm_MODE)),\
wasi,\
$(if $(filter wace_libc,$(wasm_MODE)),\
libc,\
$(if $(filter direct node js wace_fooboot warpy,$(wasm_MODE)),\
direct,\
libc)))
wasi)))

EXT = $(if $(filter lucet,$(wasm_MODE)),.so,.wasm)

WASM_AS ?= wasm-as
WAMP ?= node_modules/.bin/wamp
LUCETC ?= lucetc-wasi

STEP0_DEPS = $(WAMP) platform_$(MODE).wam string.wam printf.wam
STEP1_DEPS = $(STEP0_DEPS) types.wam mem.wam debug.wam reader.wam printer.wam
Expand All @@ -17,22 +20,28 @@ STEPS = step0_repl step1_read_print step2_eval step3_env \
step4_if_fn_do step5_tco step6_file step7_quote \
step8_macros step9_try stepA_mal

all: $(foreach s,$(STEPS),$(s).wasm)
all: $(foreach s,$(STEPS),$(s)$(EXT))

node_modules/.bin/wamp:
npm install

%.wasm: %.wam
%.wat: %.wam
$(WAMP) $(filter %.wam,$^) > $*.wat
$(WASM_AS) $*.wat -o $@

step0_repl.wasm: $(STEP0_DEPS)
step1_read_print.wasm step2_eval.wasm: $(STEP1_DEPS)
step3_env.wasm: $(STEP3_DEPS)
step4_if_fn_do.wasm step5_tco.wasm step6_file.wasm: $(STEP4_DEPS)
step7_quote.wasm step8_macros.wasm step9_try.wasm stepA_mal.wasm: $(STEP4_DEPS)
%.wasm: %.wat
$(WASM_AS) $< -o $@

# lucet object binaries
%.so: %.wasm
$(LUCETC) $< -o $@

step0_repl.wat: $(STEP0_DEPS)
step1_read_print.wat step2_eval.wat: $(STEP1_DEPS)
step3_env.wat: $(STEP3_DEPS)
step4_if_fn_do.wat step5_tco.wat step6_file.wat: $(STEP4_DEPS)
step7_quote.wat step8_macros.wat step9_try.wat stepA_mal.wat: $(STEP4_DEPS)

.PHONY: clean

clean:
rm -f *.wat *.wasm
rm -f *.wat *.wasm *.so
2 changes: 1 addition & 1 deletion wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"description": "Make a Lisp (mal) language implemented in WebAssembly",
"dependencies": {
"@kanaka/wamp": "1.0.8",
"@kanaka/wamp": "1.0.9",
"ffi-napi": "^2.4.4",
"text-encoding": "0.6.4"
}
Expand Down
1 change: 0 additions & 1 deletion wasm/platform_wasi.wam
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

(memory 256)
(export "memory" (memory 0))
(global $memoryBase i32 0)

(global $WASI_RIGHT_FD_READ i64 (i64.const 2))
(global $WASI_ESUCCESS i32 0)
Expand Down
12 changes: 8 additions & 4 deletions wasm/run
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,18 @@ STEP=${STEP:-stepA_mal}
case "${wasm_MODE}" in
wasmtime)
exec wasmtime --dir=./ --dir=../ --dir=/ $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
node|js)
exec ./run.js $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
lucet)
exec lucet-wasi --dir=./:./ --dir=../:../ --dir=/:/ $(dirname $0)/${STEP:-stepA_mal}.so -- "${@}" ;;
wasmer)
exec wasmer run --dir=./ --dir=../ --dir=/ $(dirname $0)/${STEP:-stepA_mal}.wasm -- "${@}" ;;
warpy)
exec warpy --argv --memory-pages 256 $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
wax)
exec wax $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
wace_libc)
exec wace $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
wace_fooboot)
echo >&2 "wace_fooboot mode not yet supported" ;;
wace_libc|*)
exec wace $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
node|js|*)
exec ./run.js $(dirname $0)/${STEP:-stepA_mal}.wasm "${@}" ;;
esac

0 comments on commit 1e9eb42

Please sign in to comment.