Compare commits

..

10 Commits

13 changed files with 397 additions and 190 deletions

View File

@ -0,0 +1,26 @@
name: Build WASM Base Docker Image
on:
push:
branches: [disabled]
# branches: [main]
# paths:
# - ".gitea/workflows/wasm-docker.yaml"
# - "wasm-base.dockerfile"
jobs:
wasm-docker:
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to container registry
uses: docker/login-action@v3
with:
registry: gitea.vps.chriphost.de
username: ${{ secrets.CONTAINER_REGISTRY_USER }}
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
- name: Build WASM Base Docker Image
run: docker build --file wasm-base.dockerfile --tag gitea.vps.chriphost.de/christoph/wasm-base:latest .
- name: Push WASM Base Docker Image
run: docker push gitea.vps.chriphost.de/christoph/wasm-base:latest

View File

@ -1,8 +1,14 @@
docker:
docker build -t wasm-base -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
docker build -t gitea.vps.chriphost.de/christoph/wasm-base:latest -f wasm-base.dockerfile . --build-arg CACHE_DATE="$(shell date)"
run:
docker run --rm -it wasm-base:latest /usr/bin/fish
docker run --rm -it gitea.vps.chriphost.de/christoph/wasm-base:latest /usr/bin/fish
run-external:
docker run --rm -it -v "./examples:/home/ubuntu/examples" wasm-base:latest /usr/bin/fish
docker run --rm -it -v "./examples:/home/ubuntu/examples" gitea.vps.chriphost.de/christoph/wasm-base:latest /usr/bin/fish
bochs:
bochs -f ./examples/arch/bochs/bochsrc-docker.txt -q
bochs-host:
nix shell nixpkgs#bochs --command sh -c "bochs -f ./examples/arch/bochs/bochsrc-host.txt -q"

View File

@ -1,86 +0,0 @@
# This makefile embeds an application compiled to WASM into a native C program.
# The WASM module will be loaded by the WASM runtime.
# Paths
WAMR_ROOT := /opt/wamr
WAMRC := /opt/wamr-wamrc/wamrc
IWASM := /opt/wamr-iwasm/iwasm
WAMRC_LIB := /opt/wamr-libvmlib
IWASM_LIB := /opt/wamr-libiwasm
WASI_ROOT := /opt/wasi-sdk
WASI_CC := $(WASI_ROOT)/bin/clang
WASI_CFLAGS := --target=wasm32-wasi \
--sysroot=$(WASI_ROOT)/share/wasi-sysroot \
-O0 -g -Wall
# Embedding
EMBED_CC := gcc
EMBED_INCL := -I$(WAMR_ROOT)/core/iwasm/include \
-I$(WAMR_ROOT)/core/iwasm/common \
-I$(WAMR_ROOT)/core/shared/platform/linux \
-I$(WAMR_ROOT)/core/shared/utils \
-I$(WAMR_ROOT)/core/shared/utils/uncommon
EMBED_SOURCES := $(WAMR_ROOT)/core/shared/utils/uncommon/bh_read_file.c # Not used when reading from buffer
EMBED_CFLAGS := -O0 -g -Wall $(EMBED_INCL)
AOT_LDFLAGS := -Wl,-rpath,$(WAMRC_LIB)
AOT_LDLIBS := -L$(WAMRC_LIB) -lvmlib -lm
INTER_LDFLAGS := -Wl,-rpath,$(IWASM_LIB)
INTER_LDLIBS := -L$(IWASM_LIB) -liwasm -lm
XXD := busybox xxd
# Files
SRCS := $(wildcard *.c)
WASMS := $(SRCS:.c=.wasm)
CWASMS := $(SRCS:.c=_wasm.c)
AOTS := $(SRCS:.c=.aot)
OBJS := $(SRCS:.c=.o)
DEPS := $(SRCS:.c=.d)
HOSTS := $(SRCS:.c=_host.elf)
.PHONY: all build-wasms build-aots build-cwasms build-hosts clean
all: build-wasms build-aots build-cwasms build-hosts
# Compile to wasm bytecode using wasi-sdk
build-wasms: $(WASMS)
%.wasm: %.c
$(WASI_CC) $(WASI_CFLAGS) $< -o $@
# Compile ahead-of-time module using wamrc
build-aots: $(AOTS)
%.aot: %.wasm
$(WAMRC) -o $@ $<
# Convert the .aot files to C-style arrays (to embed them into the resulting host binary)
build-cwasms: $(CWASMS)
%_wasm.c: %.aot
$(XXD) -i $< > $@
# Compile the host that will load and run the compiled wasm module
# The compiled wasm module is embedded as C-style array
build-hosts: $(HOSTS)
# The C-style array is called %_aot, e.g. test_aot
# We have to modify the host to refer to that with the correct name
%_host.elf: %_wasm.c
cp embed/host.c embed/$*_host.c
sed -i \
-e "s@__WASM_ARRAY_FILE__@../$*_wasm.c@g" \
-e "s@__WASM_ARRAY__@$*_aot@g" \
-e "s@__WASM_ARRAY_LEN__@$*_aot_len@g" \
embed/$*_host.c
$(EMBED_CC) $(EMBED_CFLAGS) embed/$*_host.c -o $@ $(INTER_LDFLAGS) $(INTER_LDLIBS)
clean:
rm -f *.wasm
rm -f *.aot
rm -f *_wasm.c
rm -f *.d
rm -f *.o
rm -f embed/*_host.c
rm -f *_host.elf

View File

@ -1,36 +1,51 @@
# C -> WASM
WASI_ROOT := /opt/wasi-sdk
WASI_CC := ${WASI_ROOT}/bin/clang
WASI_CFLAGS := --target=wasm32 \
WASI_CFLAGS := \
--target=wasm32 \
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
-z stack-size=4096 \
-O0 \
-nostdlib \
-O0 -g -Wall \
-Wl,--no-entry \
-Wl,--initial-memory=65536 \
-Wl,--export-all \
-Wl,--no-gc-sections \
-Wl,--initial-memory=65536 \
-Wl,--export=__heap_base \
-Wl,--export=__data_end
# WASM -> Baremetal
WAMR := /opt/wamr
IWASM_LIB := /opt/wamr-libiwasm
CC := gcc
CFLAGS := -I. -include arch/${ARCH}/lib.c -O0 -g -m32 -fomit-frame-pointer
LDFLAGS := -Wl,-T linker.ld $^ -Wl,--build-id=none -static -nostdlib -m32 \
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm
INCL := -I${WAMR}/core/iwasm/include \
-I${WAMR}/core/iwasm/common \
-I${WAMR}/core/shared/platform/include \
-I${WAMR}/core/shared/platform/linux \
-I${WAMR}/core/shared/mem-alloc \
CC := /opt/crosscompiler/bin/i686-elf-gcc
# NOTE: When compiling I get "error: bp cannot be used in asm here"
# I could remove "ebp" from the clobber list (ARCH_ASM_CLOBBER_ALL) or
# use the -fomit-frame-pointer flag to tell gcc it shouldn't rely on ebp for enter/leave...
CFLAGS := \
-I. \
-O0 \
-m32 \
-ffunction-sections \
-fomit-frame-pointer
LDFLAGS = \
-Wl,-T linker.ld \
$^ \
-Wl,--build-id=none \
-static \
-nostdlib \
-m32 \
-Wl,-rpath,${IWASM_LIB} \
-L${IWASM_LIB} \
-liwasm \
-lc \
-lgcc
INCL := \
-I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/utils/uncommon
-I${WAMR}/core/shared/platform/baremetal \
-I/opt/crosscompiler/i686-elf/include
WAMRC := /opt/wamr-wamrc/wamrc
WAMRCFLAGS := --target=i386 --format=object
XXD := busybox xxd
WASM2C := wasm2c
################################################################
# C -> WASM
@ -38,19 +53,17 @@ ${BUILD_DIR}/%/module.wasm: %.c
mkdir -p $(shell dirname $@)
${WASI_CC} ${WASI_CFLAGS} $< -o $@
################################################################
# WASM -> Native Object File
# ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module.wasm
# ${WAMRC} ${WAMRCFLAGS} -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
# ${WAMRC} --target=i386 --format=object -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
#
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
# ${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
# ${CC} $< ${CFLAGS} -c -o $@
#
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
# ${CC} ${LDFLAGS} -o $@
################################################################
# WASM -> AOT -> Loaded by Runtime
${BUILD_DIR}/%/module.aot: ${BUILD_DIR}/%/module.wasm
@ -66,12 +79,15 @@ ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
-e "s/__WASM_ARRAY__/build_bochs_$*_module_aot/g" \
-e "s/__WASM_ARRAY_LEN__/build_bochs_$*_module_aot_len/g" \
${BUILD_DIR}/$*/module_host.c
${CC} ${CFLAGS} ${INCL} -c -ffunction-sections ${BUILD_DIR}/$*/module_host.c -o $@
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host.c -o $@
${BUILD_DIR}/startup.o: arch/bochs/startup.s
${CC} $< ${CFLAGS} -c -ffunction-sections -o $@
${CC} $< ${CFLAGS} -c -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
${BUILD_DIR}/syscalls.o: syscalls.c
${CC} $< ${CFLAGS} -c -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/syscalls.o ${BUILD_DIR}/startup.o
${CC} ${LDFLAGS} -o $@
################################################################
@ -83,7 +99,6 @@ ${BUILD_DIR}/%/system.iso: ${BUILD_DIR}/%/system.elf
cp $< $(shell dirname $<)/grub/boot/system.elf
grub-mkrescue -o $@ $(shell dirname $<)/grub
BOCHS_RUNNER_ARGS = \
-V arch/bochs/vgabios.bin \
-b arch/bochs/BIOS-bochs-latest \
@ -91,8 +106,8 @@ BOCHS_RUNNER_ARGS = \
${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} -1 \
-f ${FAIL_TRACE} \
-e $(shell dirname $<)/system.elf \
-i $(shell dirname $<)/system.iso \
-e $(shell dirname $<)/$*/system.elf \
-i $(shell dirname $<)/$*/system.iso \
-- \
-Wf,--state-file=$(shell dirname $<)/state \
-Wf,--trace-file=$(shell dirname $<)/trace.pb \
@ -100,7 +115,6 @@ ${BUILD_DIR}/%/trace.pb: ${BUILD_DIR}/%/system.iso
-Wf,--end-symbol=stop_trace \
-Wf,--check-bounds
client-%:
${BOCHS_RUNNER} ${BOCHS_RUNNER_ARGS} \
-f ${FAIL_INJECT} \
@ -144,11 +158,13 @@ import-arch-%: ${BUILD_DIR}/%/trace.pb ${HOME}/.my.cnf
${FAIL_IMPORT} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b ip -t $< -e $(shell dirname $<)/system.elf -i RegisterImporter --no-gp --ip
${FAIL_PRUNE} -v ${ARCH}/$(patsubst import-arch-%,%,$@) -b %% --overwrite
define arch-make-targets
build-$1: ${BUILD_DIR}/$1/system.iso
trace-$1: ${BUILD_DIR}/$1/trace.pb
objdump-$1:
objdump --disassemble --disassembler-options intel --disassembler-color=on --source ${BUILD_DIR}/$1/system.elf
endef

View File

@ -0,0 +1,9 @@
megs: 32
display_library: nogui
romimage: file=/home/ubuntu/examples/arch/bochs/BIOS-bochs-latest
vgaromimage: file=/home/ubuntu/examples/arch/bochs/vgabios.bin
ata0-master: type=cdrom, path=/home/ubuntu/examples/build-bochs/sum/system.iso, status=inserted
boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000

View File

@ -0,0 +1,10 @@
megs: 32
display_library: nogui
romimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/bochs/BIOS-bochs-latest"
vgaromimage: file="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/arch/bochs/vgabios.bin"
ata0-master: type=cdrom, path="/home/christoph/Notes/TU/MastersThesis/3 Wasm/examples/build-bochs/sum/system.iso", status=inserted
boot: cdrom
log: bochslog.txt
clock: sync=realtime, time0=local
cpu: count=1, ips=1000000
sound: driver=dummy

View File

@ -1,4 +0,0 @@
#pragma once
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"

84
examples/arch/linux.mk Normal file
View File

@ -0,0 +1,84 @@
# C -> WASM
WASI_ROOT := /opt/wasi-sdk
WASI_CC := ${WASI_ROOT}/bin/clang
WASI_CFLAGS := --target=wasm64 \
--sysroot=${WASI_ROOT}/share/wasi-sysroot \
-z stack-size=4096 \
-O0 -g -nostdlib \
-Wl,--no-entry \
-Wl,--initial-memory=65536 \
-Wl,--export-all \
-Wl,--export=__heap_base \
-Wl,--export=__data_end
# WASM -> Baremetal
WAMR := /opt/wamr
IWASM_LIB := /opt/wamr-libiwasm-64
CC := gcc
# NOTE: When compiling I get "error: bp cannot be used in asm here"
# I could remove "ebp" from the clobber list (ARCH_ASM_CLOBBER_ALL) or
# use the -fomit-frame-pointer flag to tell gcc it shouldn't rely on ebp for enter/leave...
CFLAGS := -I. -O0 -g -ffunction-sections -std=c11 -fomit-frame-pointer
LDFLAGS = $^ -Wl,--build-id=none -static -nostdlib \
-Wl,-rpath,${IWASM_LIB} -L${IWASM_LIB} -liwasm -lgcc
INCL := -I${WAMR}/core/iwasm/include \
-I${WAMR}/core/shared/utils \
-I${WAMR}/core/shared/platform/baremetal
WAMRC := /opt/wamr-wamrc/wamrc
WAMRCFLAGS := --target=i386 --format=object
XXD := busybox xxd
################################################################
# C -> WASM
${BUILD_DIR}/%/module.wasm: %.c
mkdir -p $(shell dirname $@)
${WASI_CC} ${WASI_CFLAGS} $< -o $@
################################################################
# WASM -> Native Object File
# ${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module.wasm
# ${WAMRC} ${WAMRCFLAGS} -o ${BUILD_DIR}/$*/system.o ${BUILD_DIR}/$*/module.wasm
#
# ${BUILD_DIR}/startup.o: arch/bochs/startup.s
# ${CC} $< ${CFLAGS} -c -o $@
#
# ${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
# ${CC} ${LDFLAGS} -o $@
################################################################
# WASM -> AOT -> Loaded by Runtime
${BUILD_DIR}/%/module.aot: ${BUILD_DIR}/%/module.wasm
${WAMRC} -o $@ $<
${BUILD_DIR}/%/module_wasm.c: ${BUILD_DIR}/%/module.aot
${XXD} -i $< > $@
${BUILD_DIR}/%/system.o: ${BUILD_DIR}/%/module_wasm.c
cp embed/host.c ${BUILD_DIR}/$*/module_host.c
sed -i \
-e "s/__WASM_ARRAY_FILE__/module_wasm.c/g" \
-e "s/__WASM_ARRAY__/build_linux_$*_module_aot/g" \
-e "s/__WASM_ARRAY_LEN__/build_linux_$*_module_aot_len/g" \
${BUILD_DIR}/$*/module_host.c
${CC} ${CFLAGS} ${INCL} -c ${BUILD_DIR}/$*/module_host.c -o $@
${BUILD_DIR}/startup.o: arch/bochs/startup.s
${CC} $< ${CFLAGS} -c -o $@
${BUILD_DIR}/%/system.elf: ${BUILD_DIR}/%/system.o ${BUILD_DIR}/startup.o
${CC} ${LDFLAGS} -o $@
define arch-make-targets
build-$1: ${BUILD_DIR}/$1/system.elf
gdb-$1:
gdb --tui ${BUILD_DIR}/$1/system.elf
valgrind-$1:
valgrind ${BUILD_DIR}/$1/system.elf
objdump-$1:
objdump --disassemble --start-address=0x401000 --stop-address=0x401200 --disassembler-options intel --disassembler-color=on --source ${BUILD_DIR}/$1/system.elf
endef

View File

@ -1,18 +1,14 @@
// https://github.com/bytecodealliance/wasm-micro-runtime/blob/WAMR-2.4.4/doc/embed_wamr.md
// #include <stdio.h>
#include <string.h>
#include "lib.c"
// #include "bh_read_file.h"
#include "bh_platform.h"
#include "wasm_export.h"
#include "__WASM_ARRAY_FILE__"
#define STACK_SIZE (8 * 1024)
#define HEAP_SIZE (8 * 1024)
#define STACK_SIZE (4 * 1024)
#define HEAP_SIZE (4 * 1024)
// TODO: Set this up so the lsp actually finds the includes...
@ -22,14 +18,16 @@ MAIN() {
wasm_module_inst_t module_inst;
wasm_function_inst_t func;
wasm_exec_env_t exec_env;
uint32 stack_size = 8 * 1024;
uint32 heap_size = 8 * 1024;
/* initialize the wasm runtime */
static char global_heap_buf[HEAP_SIZE];
RuntimeInitArgs init_args;
memset(&init_args, 0, sizeof(init_args));
memset(&init_args, 0, sizeof(RuntimeInitArgs));
init_args.mem_alloc_type = Alloc_With_System_Allocator;
init_args.mem_alloc_type = Alloc_With_Pool;
init_args.mem_alloc_option.pool.heap_buf = global_heap_buf;
init_args.mem_alloc_option.pool.heap_size = sizeof(global_heap_buf);
init_args.max_thread_num = 1;
if (!wasm_runtime_full_init(&init_args)) {
return;
}
@ -39,14 +37,14 @@ MAIN() {
sizeof(error_buf));
/* create an instance of the WASM module (WASM linear memory is ready) */
module_inst = wasm_runtime_instantiate(module, stack_size, heap_size,
module_inst = wasm_runtime_instantiate(module, STACK_SIZE, HEAP_SIZE,
error_buf, sizeof(error_buf));
/* lookup a WASM function by its name, the function signature can NULL here */
func = wasm_runtime_lookup_function(module_inst, "wasm_module");
/* create an execution environment to execute arbitrary WASM functions */
exec_env = wasm_runtime_create_exec_env(module_inst, stack_size);
exec_env = wasm_runtime_create_exec_env(module_inst, STACK_SIZE);
/* arguments are always transferred in 32-bit element */
uint32 args[1];

View File

@ -6,6 +6,12 @@
#define __QUOTE(x) #x
#define QUOTE(x) __QUOTE(x)
#ifndef ARCH_ASM_CLOBBER_ALL
// TODO: Is my gcc to new? It won't let me clobber ebp unless I specify
// -fomit-frame-pointer
#define ARCH_ASM_CLOBBER_ALL "eax", "ebx", "ecx", "edx", "esi", "edi", "ebp"
#endif
#ifndef MARKER
#define MARKER(str) \
__asm__ volatile(QUOTE(str) ":" \

View File

@ -18,6 +18,7 @@ SECTIONS {
/* Code and readonly data */
.text : {
/* fill gaps with int3 opcode to detect invalid jumps */
/* TODO: This crashes bochs */
FILL(0xcc)
/* multiboot header */
@ -55,9 +56,20 @@ SECTIONS {
KEEP (*(".startup_stack"))
KEEP (*(".kernel_stack"))
*(".data*")
*(COMMON);
}
/* Uninitialized data */
.bss : {
_sbss = .;
*(.bss*)
*(COMMON)
_ebss = .;
}
/* Align and mark end of all sections — heap starts here */
. = ALIGN(4096);
_end = .;
/* Memory-mapped I/O APIC */
_sioapic = 0xFEC00000;
ioapic = 0xFEC00000;

35
examples/syscalls.c Normal file
View File

@ -0,0 +1,35 @@
#include <errno.h>
#include <sys/stat.h>
extern char _end; /* provided by linker script */
static char *heap_ptr = &_end;
void *sbrk(int incr) {
char *prev = heap_ptr;
heap_ptr += incr;
return prev;
}
int write(int fd, const char *buf, int len) { return len; }
int read(int fd, char *buf, int len) { return 0; }
int close(int fd) { return -1; }
int fstat(int fd, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
int isatty(int fd) { return 1; }
int lseek(int fd, int offset, int whence) { return 0; }
void _exit(int status) {
while (1)
;
}
void exit(int status) {
while (1)
;
}
int kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
int getpid(void) { return 1; }

View File

@ -1,7 +1,72 @@
# We need an old ubuntu version with an old enough gcc to build an old gcc...
# This gcc can't bootstrap itself because it's target is another platform.
FROM ubuntu:bionic AS compiler-builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berlin apt-get install -y --no-install-recommends \
build-essential \
git \
ca-certificates \
cmake \
bison \
flex \
libgmp3-dev \
libmpc-dev \
libmpfr-dev \
texinfo \
libisl-dev \
wget \
&& apt-get clean
ARG GCCVERSION=5.4.0
ARG BINUTILSVERSION=2.26.1
ARG CROSSPREFIX=/opt/crosscompiler
ARG CROSSTARGET=i686-elf
# Build Binutils for cross-compilation
WORKDIR /
RUN wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILSVERSION.tar.gz \
&& tar xf binutils-$BINUTILSVERSION.tar.gz
RUN mkdir binutils-build && cd binutils-build \
&& /binutils-$BINUTILSVERSION/configure --target=$CROSSTARGET --prefix="$CROSSPREFIX" --with-sysroot --disable-nls --disable-werror \
&& make -j$(nproc) \
&& make install
# Build GCC for cross-compilation
WORKDIR /
RUN wget https://ftp.gnu.org/gnu/gcc/gcc-$GCCVERSION/gcc-$GCCVERSION.tar.gz \
&& tar xf gcc-$GCCVERSION.tar.gz \
&& cd gcc-$GCCVERSION \
&& contrib/download_prerequisites
RUN mkdir gcc-build && cd gcc-build \
&& PATH="$CROSSPREFIX/bin:$PATH" /gcc-$GCCVERSION/configure --target=$CROSSTARGET --prefix="$CROSSPREFIX" --disable-nls --enable-languages=c,c++ --without-headers --disable-hosted-libstdcxx --disable-libsanitizer --disable-threads \
&& PATH="$CROSSPREFIX/bin:$PATH" make all-gcc -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make all-target-libgcc -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make install-gcc \
&& PATH="$CROSSPREFIX/bin:$PATH" make install-target-libgcc
# && PATH="$CROSSPREFIX/bin:$PATH" make all-target-libstdc++-v3 -j$(nproc) \
# && PATH="$CROSSPREFIX/bin:$PATH" make install-target-libstdc++-v3
# Build newlib
ARG NEWLIBVERSION=4.1.0
WORKDIR /
RUN wget ftp://sourceware.org/pub/newlib/newlib-$NEWLIBVERSION.tar.gz \
&& tar xf newlib-$NEWLIBVERSION.tar.gz
RUN mkdir newlib-build && cd newlib-build \
&& PATH="$CROSSPREFIX/bin:$PATH" /newlib-$NEWLIBVERSION/configure \
--target=$CROSSTARGET \
--prefix="$CROSSPREFIX" \
--disable-nls \
--disable-newlib-supplied-syscalls \
&& PATH="$CROSSPREFIX/bin:$PATH" make -j$(nproc) \
&& PATH="$CROSSPREFIX/bin:$PATH" make install
# =============================================================================
FROM ubuntu:noble AS wamr-builder
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berline apt-get install -y --no-install-recommends \
&& DEBIAN_FRONTEND=noninteractive TZ=Europe/Berlin apt-get install -y --no-install-recommends \
build-essential \
gcc-multilib \
g++-multilib \
@ -16,6 +81,7 @@ RUN apt-get update \
python3-minimal \
python3-pip \
ninja-build \
wget \
&& apt-get clean
# TODO: Can't find pthread on X86_32
@ -28,26 +94,27 @@ RUN python3 -m pip config set global.break-system-packages true
RUN git clone https://gitea.vps.chriphost.de/christoph/wamr \
&& cd wamr \
&& git checkout WAMR-2.4.4
WORKDIR /wamr
# Build WAMR iwasm (vmcore standalone interpreter)
# RUN cd product-mini/platforms/linux \
# && mkdir build_iwasm && cd build_iwasm \
# && cmake \
# -DWAMR_BUILD_PLATFORM=linux \
# -DWAMR_BUILD_TARGET=X86_64 \
# -DWAMR_BUILD_AOT=0 \
# -DWAMR_BUILD_WAMR_COMPILER=0 \
# -DWAMR_BUILD_INTERP=1 \
# -DWAMR_BUILD_FAST_INTERP=0 \
# -DWAMR_BUILD_JIT=0 \
# -DWAMR_BUILD_FAST_JIT=0 \
# -DWAMR_BUILD_LIBC_BUILTIN=1 \
# -DWAMR_BUILD_LIBC_WASI=1 \
# .. \
# && make -j$(nproc)
WORKDIR /wamr
RUN cd product-mini/platforms/linux \
&& mkdir build_iwasm && cd build_iwasm \
&& cmake \
-DWAMR_BUILD_PLATFORM=linux \
-DWAMR_BUILD_TARGET=X86_64 \
-DWAMR_BUILD_AOT=0 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=1 \
.. \
&& make -j$(nproc)
# Build WAMR wamrc (standalone compiler)
WORKDIR /wamr
RUN cd wamr-compiler \
&& ./build_llvm.sh \
&& mkdir build_wamrc && cd build_wamrc \
@ -74,9 +141,11 @@ WORKDIR /
RUN git clone https://gitea.vps.chriphost.de/christoph/wamr wamrlib \
&& cd wamrlib \
&& git checkout WAMR-2.4.4
WORKDIR /wamrlib
# TODO: Should this stuff not be compiled with the crosscompiler?
# Build WAMR libvmlib (compiler runtime - to compile wasm modules embedded in a native application)
# WORKDIR /wamrlib
# RUN cd wamr-compiler \
# && ./build_llvm.sh \
# # && ./build_llvm.sh --extra-cmake-flags "-DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 -DCMAKE_EXE_LINKER_FLAGS=-m32 -lstdc++" \
@ -97,6 +166,7 @@ WORKDIR /wamrlib
# && make -j$(nproc)
# Build WAMR libiwasm (vmcore interpreter runtime - to run wasm modules embedded in a native application)
WORKDIR /wamrlib
RUN mkdir build_libiwasm && cd build_libiwasm \
&& cmake \
-DWAMR_BUILD_PLATFORM=baremetal \
@ -110,6 +180,25 @@ RUN mkdir build_libiwasm && cd build_libiwasm \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
WORKDIR /wamrlib
RUN mkdir build_libiwasm_64 && cd build_libiwasm_64 \
&& cmake \
-DWAMR_BUILD_PLATFORM=baremetal \
-DWAMR_BUILD_TARGET=X86_64 \
-DWAMR_BUILD_AOT=0 \
-DWAMR_BUILD_WAMR_COMPILER=0 \
-DWAMR_BUILD_INTERP=1 \
-DWAMR_BUILD_FAST_INTERP=0 \
-DWAMR_BUILD_JIT=0 \
-DWAMR_BUILD_FAST_JIT=0 \
-DWAMR_BUILD_LIBC_BUILTIN=1 \
-DWAMR_BUILD_LIBC_WASI=0 \
-DWAMR_BUILD_SIMD=0 \
-DCMAKE_COLOR_DIAGNOSTICS=ON \
.. \
&& make -j$(nproc)
@ -128,18 +217,24 @@ RUN apt-get update \
neovim \
ranger \
wabt \
gdb \
valgrind \
fish \
grub-common \
xorriso \
grub-pc-bin \
bochs \
&& apt-get clean
COPY --from=wamr-builder /wamr /opt/wamr
COPY --from=wamr-builder /wamrlib /opt/wamrlib
COPY --from=compiler-builder /opt/crosscompiler /opt/crosscompiler
COPY --from=wamr-builder /wamrlib /opt/wamr
COPY --from=wamr-builder /wamr/wamr-compiler/build_wamrc /opt/wamr/wamr-compiler/build_wamrc
COPY --from=wamr-builder /wamr/product-mini/platforms/linux/build_iwasm /opt/wamr/product-mini/platforms/linux/build_iwasm
RUN ln -sf /opt/wamr/product-mini/platforms/linux/build_iwasm /opt/wamr-iwasm \
&& ln -sf /opt/wamr/wamr-compiler/build_wamrc /opt/wamr-wamrc \
&& ln -sf /opt/wamrlib/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
&& ln -sf /opt/wamrlib/build_libiwasm /opt/wamr-libiwasm
&& ln -sf /opt/wamr/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \
&& ln -sf /opt/wamr/build_libiwasm /opt/wamr-libiwasm \
&& ln -sf /opt/wamr/build_libiwasm_64 /opt/wamr-libiwasm-64
COPY ./examples /home/ubuntu/examples
WORKDIR /home/ubuntu/examples