examples: wamr example program
This commit is contained in:
@ -29,5 +29,9 @@ RUN apt-get update \
|
|||||||
&& apt-get clean
|
&& apt-get clean
|
||||||
|
|
||||||
COPY --from=wamr-builder /wasm-micro-runtime/product-mini/platforms/linux/build /opt/wasm-micro-runtime
|
COPY --from=wamr-builder /wasm-micro-runtime/product-mini/platforms/linux/build /opt/wasm-micro-runtime
|
||||||
|
RUN pwd
|
||||||
|
COPY ./examples /home/ubuntu/examples
|
||||||
|
|
||||||
|
WORKDIR /home/ubuntu/examples
|
||||||
|
|
||||||
ENV PATH="$PATH:/opt/wasi-sdk/bin:/opt/wasm-micro-runtime"
|
ENV PATH="$PATH:/opt/wasi-sdk/bin:/opt/wasm-micro-runtime"
|
||||||
|
|||||||
20
wasm-base/examples/Makefile
Normal file
20
wasm-base/examples/Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
WASI_SDK := /opt/wasi-sdk
|
||||||
|
CLANG := $(WASI_SDK)/bin/clang
|
||||||
|
SYSROOT := $(WASI_SDK)/share/wasi-sysroot
|
||||||
|
|
||||||
|
CFLAGS := --target=wasm32-wasi \
|
||||||
|
--sysroot=$(SYSROOT) \
|
||||||
|
-O2
|
||||||
|
|
||||||
|
SRCS := $(wildcard *.c)
|
||||||
|
WASMS := $(SRCS:.c=.wasm)
|
||||||
|
|
||||||
|
.PHONY: build-examples clean
|
||||||
|
|
||||||
|
build-examples: $(WASMS)
|
||||||
|
|
||||||
|
%.wasm: %.c
|
||||||
|
$(CLANG) $(CFLAGS) $< -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.wasm
|
||||||
24
wasm-base/examples/test.c
Normal file
24
wasm-base/examples/test.c
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/doc/build_wasm_app.md#user-content-build-wasm-applications-with-wasi-sdk
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
char *buf;
|
||||||
|
|
||||||
|
printf("Hello world!\n");
|
||||||
|
|
||||||
|
buf = malloc(1024);
|
||||||
|
if (!buf) {
|
||||||
|
printf("malloc buf failed\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("buf ptr: %p\n", buf);
|
||||||
|
|
||||||
|
sprintf(buf, "%s", "1234\n");
|
||||||
|
printf("buf: %s", buf);
|
||||||
|
|
||||||
|
free(buf);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user