|
| 1 | +# Docker image with a build toolchain and environment variables set to use |
| 2 | +# the wasi-sdk sysroot. The SDK distribution must have first been built, |
| 3 | +# for example using docker_build.sh |
| 4 | + |
| 5 | +# Extract built SDK archive to copy out the sysroot. We use an initial build |
| 6 | +# stage to do this to make sure it is only the sysroot, not the entire SDK |
| 7 | +# with binaries, that is included in the final image since we install those |
| 8 | +# separately. |
| 9 | +FROM ubuntu:22.04 as dist |
| 10 | + |
| 11 | +ADD dist/wasi-sdk-*.*-linux.tar.gz / |
| 12 | + |
| 13 | +# Move versioned folder to unversioned to using bash glob to allow |
| 14 | +# this file to be independent of major version number. |
| 15 | +RUN mv /wasi-sdk-* /wasi-sdk |
| 16 | + |
| 17 | +FROM ubuntu:22.04 |
| 18 | + |
| 19 | +ENV LLVM_VERSION 15 |
| 20 | + |
| 21 | +# Install build toolchain including clang, ld, make, autotools, ninja, and cmake |
| 22 | +RUN apt-get update && \ |
| 23 | + # Temporarily install to setup apt repositories |
| 24 | + apt-get install -y curl gnupg && \ |
| 25 | +\ |
| 26 | + curl -sS https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor > /etc/apt/trusted.gpg.d/llvm.gpg && \ |
| 27 | + echo "deb [signed-by=/etc/apt/trusted.gpg.d/llvm.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${LLVM_VERSION} main" >> /etc/apt/sources.list.d/llvm.list && \ |
| 28 | + echo "deb-src [signed-by=/etc/apt/trusted.gpg.d/llvm.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-${LLVM_VERSION} main" >> /etc/apt/sources.list.d/llvm.list && \ |
| 29 | +\ |
| 30 | + apt-get update && \ |
| 31 | + apt-get install -y clang-${LLVM_VERSION} lld-${LLVM_VERSION} cmake ninja-build make autoconf autogen automake libtool && \ |
| 32 | + apt-get remove -y curl gnupg && \ |
| 33 | + rm -rf /var/lib/apt/lists/* |
| 34 | + |
| 35 | +COPY --from=dist /wasi-sdk/share/wasi-sysroot/ /wasi-sysroot/ |
| 36 | +# The path to the rt directory contains the LLVM patch version which is not reflected in the LLVM apt repository |
| 37 | +# or package. To make adding the RT robust to changing patch versions without needing to duplicate the folder |
| 38 | +# content, we symlink after extracting using a bash glob to resolve the patch version |
| 39 | +ADD dist/libclang_rt.builtins-wasm32-wasi-*.*.tar.gz /wasi-sysroot-clang_rt |
| 40 | +RUN ln -s /wasi-sysroot-clang_rt/lib/wasi/ $(echo /usr/lib/llvm-${LLVM_VERSION}/lib/clang/${LLVM_VERSION}.*)/lib/wasi |
| 41 | + |
| 42 | +ADD docker/wasi-sdk.cmake /usr/share/cmake/wasi-sdk.cmake |
| 43 | +ENV CMAKE_TOOLCHAIN_FILE /usr/share/cmake/wasi-sdk.cmake |
| 44 | +ADD cmake/Platform/WASI.cmake /usr/share/cmake/Modules/Platform/WASI.cmake |
| 45 | + |
| 46 | +ENV CC clang-${LLVM_VERSION} |
| 47 | +ENV CXX clang++-${LLVM_VERSION} |
| 48 | +ENV LD wasm-ld-${LLVM_VERSION} |
| 49 | +ENV AR llvm-ar-${LLVM_VERSION} |
| 50 | +ENV RANLIB llvm-ranlib-${LLVM_VERSION} |
| 51 | + |
| 52 | +ENV CFLAGS --target=wasm32-wasi --sysroot=/wasi-sysroot |
| 53 | +ENV CXXFLAGS --target=wasm32-wasi --sysroot=/wasi-sysroot |
| 54 | +ENV LDFLAGS --target=wasm32-wasi --sysroot=/wasi-sysroot |
0 commit comments