# 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=i386-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 in the gcc prefix - don't need to specify include paths 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/Berlin apt-get install -y --no-install-recommends \ build-essential \ gcc-multilib \ g++-multilib \ libgcc-11-dev \ lib32gcc-11-dev \ libc6-dev-i386 \ busybox \ git \ ca-certificates \ cmake \ ccache \ python3-minimal \ python3-pip \ ninja-build \ wget \ && apt-get clean RUN python3 -m pip config set global.break-system-packages true # Clone WAMR RUN git clone https://gitea.vps.chriphost.de/christoph/wamr \ && cd wamr \ && git checkout WAMR-2.4.4 # Build WAMR iwasm (vmcore standalone interpreter) 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 \ && cmake \ -DWAMR_BUILD_PLATFORM=linux \ -DWAMR_BUILD_TARGET=X86_64 \ -DWAMR_BUILD_AOT=0 \ -DWAMR_BUILD_WAMR_COMPILER=1 \ -DWAMR_BUILD_INTERP=0 \ -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) # The libs might change often, so re-clone the repository each time. # We don't want this for iwasm/wamrc because their builds take longer. ARG CACHE_DATE=1970-01-01 # Clone WAMR WORKDIR / RUN git clone https://gitea.vps.chriphost.de/christoph/wamr wamrlib \ && cd wamrlib \ && git checkout WAMR-2.4.4 # 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++" \ # && mkdir build_libvmlib && cd build_libvmlib \ # && cmake \ # -DWAMR_BUILD_PLATFORM=baremetal \ # -DWAMR_BUILD_TARGET=X86_32 \ # -DWAMR_BUILD_AOT=1 \ # -DWAMR_BUILD_WAMR_COMPILER=0 \ # -DWAMR_BUILD_INTERP=0 \ # -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 \ # .. \ # && make -j$(nproc) # Build WAMR libiwasm (vmcore interpreter runtime - to run wasm modules embedded in a native application) # TODO: Should probably put the cross-compilation definitions in a toolchain file COPY --from=compiler-builder /opt/crosscompiler /opt/crosscompiler WORKDIR /wamrlib RUN mkdir build_libiwasm && cd build_libiwasm \ && cmake \ -DCMAKE_SYSTEM_NAME=Generic \ -DCMAKE_SYSTEM_PROCESSOR=i386 \ -DCMAKE_C_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \ -DCMAKE_CXX_COMPILER=/opt/crosscompiler/bin/i386-elf-g++ \ -DCMAKE_ASM_COMPILER=/opt/crosscompiler/bin/i386-elf-gcc \ -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY \ -DCMAKE_BUILD_TYPE=Debug \ -DCMAKE_VERBOSE_MAKEFILE=ON \ -DWAMR_BUILD_PLATFORM=baremetal \ -DWAMR_BUILD_TARGET=X86_32 \ -DWAMR_BUILD_AOT=1 \ -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) # Build WAMR libiwasm for the host system WORKDIR /wamrlib RUN mkdir build_libiwasm_linux && cd build_libiwasm_linux \ && cmake \ -DWAMR_BUILD_PLATFORM=linux \ -DWAMR_BUILD_TARGET=X86_32 \ -DWAMR_BUILD_AOT=1 \ -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) # ============================================================================= FROM ghcr.io/webassembly/wasi-sdk:wasi-sdk-29 RUN apt-get update \ && DEBIAN_FRONTEND=noninteractive TZ=Europe/Berline apt-get install -y --no-install-recommends \ build-essential \ gcc-multilib \ busybox \ git \ ca-certificates \ wget \ neovim \ ranger \ wabt \ gdb \ valgrind \ fish \ grub-common \ xorriso \ grub-pc-bin \ bochs \ less \ && apt-get clean 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/wamr/wamr-compiler/build_libvmlib /opt/wamr-libvmlib \ && ln -sf /opt/wamr/build_libiwasm /opt/wamr-libiwasm \ && ln -sf /opt/wamr/build_libiwasm_linux /opt/wamr-libiwasm-linux RUN useradd fail \ && mkdir /home/fail && chown fail /home/fail \ && echo 'fail:fail' | chpasswd && chsh fail --shell /usr/bin/fish \ && adduser fail sudo COPY ./examples /home/fail/examples WORKDIR /home/fail/examples ENV PATH="$PATH:/opt/wasi-sdk/bin:/opt/wamr-iwasm:/opt/wamr-wamrc"