Skip to content

Commit

Permalink
[toolchain] Bundle bender and pulp as part of Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
zero9178 committed May 19, 2024
1 parent 9a90f14 commit f066d70
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 27 deletions.
42 changes: 38 additions & 4 deletions runtime/toolchain/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 && \
Expand All @@ -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
23 changes: 0 additions & 23 deletions runtime/toolchain/phase1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]=])
25 changes: 25 additions & 0 deletions runtime/toolchain/phase2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
]=])

0 comments on commit f066d70

Please sign in to comment.