From f066d70ed8cabc8d3d774690554dec0f059e65f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20B=C3=B6ck?= Date: Sun, 19 May 2024 15:38:50 +0100 Subject: [PATCH] [toolchain] Bundle bender and pulp as part of Dockerfile --- runtime/toolchain/Dockerfile | 42 ++++++++++++++++++++++++++++++---- runtime/toolchain/phase1.cmake | 23 ------------------- runtime/toolchain/phase2.cmake | 25 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/runtime/toolchain/Dockerfile b/runtime/toolchain/Dockerfile index 74ed832..77115ef 100644 --- a/runtime/toolchain/Dockerfile +++ b/runtime/toolchain/Dockerfile @@ -6,6 +6,7 @@ ARG SNITCH_CLUSTER_SHA=1f984781957520b3784b9ab17e5eeb34eec763f1 ARG VERILATOR_RELEASE=v4.228 ARG BENDER_RELEASE=0.27.1 ARG INSTALL_DIR=/opt +ARG PULP_TOOLCHAIN_RELEASE=0.12.0 FROM alpine:3.18 as toolchain-build @@ -73,19 +74,50 @@ RUN cd llvm-project/llvm/build && rm -rf * && \ -C /root/phase2.cmake && \ ninja install/strip +# Ubuntu as Rust has issues with alpine. +FROM ubuntu:24.04 as bender-build + +ARG BENDER_RELEASE +ARG INSTALL_DIR + +ENV RUSTFLAGS="-C target-feature=+crt-static" + +RUN apt-get update && apt-get install -y cargo +RUN cargo install bender --locked --version $BENDER_RELEASE --target x86_64-unknown-linux-gnu +RUN mkdir -p $INSTALL_DIR/quidditch-toolchain/bin/ +RUN cp /root/.cargo/bin/bender $INSTALL_DIR/quidditch-toolchain/bin/ + +FROM alpine:3.18 as pulp-build + +ARG INSTALL_DIR +ARG PULP_TOOLCHAIN_RELEASE + +RUN apk update && apk add --no-cache cmake git musl-dev clang clang-dev \ + python3 ninja + +RUN git clone --depth 1 https://github.com/pulp-platform/llvm-project -b $PULP_TOOLCHAIN_RELEASE +RUN cd llvm-project/llvm && mkdir build && cd build && \ + cmake .. -GNinja -DLLVM_BUILD_STATIC=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DLLVM_TARGETS_TO_BUILD="RISCV" -DCMAKE_BUILD_TYPE="Release" \ + -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf" \ + && ninja llvm-mc +RUN mkdir -p $INSTALL_DIR/quidditch-toolchain/bin +RUN cp llvm-project/llvm/build/bin/llvm-mc $INSTALL_DIR/quidditch-toolchain/bin/pulp-as +RUN strip $INSTALL_DIR/quidditch-toolchain/bin/pulp-as + FROM alpine:3.18 as verilator-build ARG SNITCH_CLUSTER_SHA ARG VERILATOR_RELEASE -ARG BENDER_RELEASE ARG INSTALL_DIR WORKDIR $INSTALL_DIR -RUN apk update && apk add --no-cache py3-pip git cargo autoconf flex-dev bison make clang coreutils dtc patch +RUN apk update && apk add --no-cache py3-pip git autoconf flex-dev bison make musl-dev clang coreutils dtc patch + +ENV PATH=/root:$PATH +COPY --from=bender-build $INSTALL_DIR/quidditch-toolchain/bin/bender /root -RUN cargo install bender --locked --version $BENDER_RELEASE -ENV PATH=$PATH:/root/.cargo/bin COPY requirements.txt /root/ RUN pip install --break-system-packages -r /root/requirements.txt RUN git clone https://github.com/pulp-platform/snitch_cluster && \ @@ -108,4 +140,6 @@ FROM alpine:3.18 ARG INSTALL_DIR COPY --from=toolchain-build $INSTALL_DIR/quidditch-toolchain $INSTALL_DIR/quidditch-toolchain +COPY --from=bender-build $INSTALL_DIR/quidditch-toolchain/bin/bender $INSTALL_DIR/quidditch-toolchain/bin +COPY --from=pulp-build $INSTALL_DIR/quidditch-toolchain/bin/pulp-as $INSTALL_DIR/quidditch-toolchain/bin COPY --from=verilator-build $INSTALL_DIR/quidditch-toolchain/bin/snitch_cluster.vlt $INSTALL_DIR/quidditch-toolchain/bin diff --git a/runtime/toolchain/phase1.cmake b/runtime/toolchain/phase1.cmake index f1be9ed..1e4306f 100644 --- a/runtime/toolchain/phase1.cmake +++ b/runtime/toolchain/phase1.cmake @@ -51,26 +51,3 @@ file(WRITE ${CMAKE_INSTALL_PREFIX}/bin/clang++.cfg [=[ -lc++ -lc++abi ]=]) -file(WRITE ${CMAKE_INSTALL_PREFIX}/ToolchainFile.cmake [=[ -set(QUIDDITCH_TOOLCHAIN_ROOT ${CMAKE_CURRENT_LIST_DIR}) - -# Without that flag CMake is not able to pass test compilation check -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE INTERNAL "") - -set(CMAKE_SYSTEM_NAME Generic CACHE INTERNAL "") -set(CMAKE_SYSTEM_PROCESSOR riscv32 CACHE INTERNAL "") - -set(CMAKE_AR ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-ar${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_ASM_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_C_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_CXX_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang++${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_OBJCOPY ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-objcopy${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_RANLIB ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_SIZE ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-size${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_STRIP ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-strip${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") -set(CMAKE_CROSSCOMPILING_EMULATOR ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/snitch_cluster.vlt CACHE INTERNAL "") - -set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) -set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) -set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) -]=]) diff --git a/runtime/toolchain/phase2.cmake b/runtime/toolchain/phase2.cmake index 450da48..572163f 100644 --- a/runtime/toolchain/phase2.cmake +++ b/runtime/toolchain/phase2.cmake @@ -36,3 +36,28 @@ set(RUNTIMES_${LLVM_DEFAULT_TARGET_TRIPLE}_LIBCXX_ENABLE_WIDE_CHARACTERS OFF CAC set(RUNTIMES_${LLVM_DEFAULT_TARGET_TRIPLE}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "") set(RUNTIMES_${LLVM_DEFAULT_TARGET_TRIPLE}_LIBCXX_ENABLE_UNICODE OFF CACHE BOOL "") set(RUNTIMES_${LLVM_DEFAULT_TARGET_TRIPLE}_LIBCXX_USE_COMPILER_RT ON CACHE BOOL "") + +file(WRITE ${CMAKE_INSTALL_PREFIX}/ToolchainFile.cmake [=[ +set(QUIDDITCH_TOOLCHAIN_ROOT ${CMAKE_CURRENT_LIST_DIR} CACHE INTERNAL "") + +# Without that flag CMake is not able to pass test compilation check +set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE INTERNAL "") + +set(CMAKE_SYSTEM_NAME Generic CACHE INTERNAL "") +set(CMAKE_SYSTEM_PROCESSOR riscv32 CACHE INTERNAL "") + +set(CMAKE_AR ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-ar${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_ASM_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_C_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_CXX_COMPILER ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/clang++${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_OBJCOPY ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-objcopy${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_RANLIB ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-ranlib${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_SIZE ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-size${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_STRIP ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/llvm-strip${CMAKE_EXECUTABLE_SUFFIX} CACHE INTERNAL "") +set(CMAKE_CROSSCOMPILING_EMULATOR ${QUIDDITCH_TOOLCHAIN_ROOT}/bin/snitch_cluster.vlt CACHE INTERNAL "") + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_PROGRAM_PATH "${QUIDDITCH_TOOLCHAIN_ROOT}/bin;${CMAKE_PROGRAM_PATH}") +]=])