Skip to content

Commit

Permalink
Add multistage gcc build to docker
Browse files Browse the repository at this point in the history
  • Loading branch information
lukamac committed Dec 18, 2024
1 parent 6e539c4 commit 8fcd01d
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 9 deletions.
70 changes: 61 additions & 9 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
ARG TOOLCHAIN_DIR=/toolchain
ARG TOOLCHAIN_GNU_INSTALL_DIR=${TOOLCHAIN_DIR}/gnu

# Build stage
FROM ubuntu:22.04 AS builder

# Needed to have the arguments in the stage
ARG TOOLCHAIN_DIR
ARG TOOLCHAIN_GNU_INSTALL_DIR

RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
autoconf \
automake \
autotools-dev \
bc \
bison \
build-essential \
ca-certificates \
curl \
flex \
gawk \
git \
gperf \
libexpat-dev \
libgmp-dev \
libmpc-dev \
libmpfr-dev \
libtool \
patchutils \
python3 \
texinfo \
zlib1g-dev \
&& apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Build gnu toolchain
ENV TOOLCHAIN_GNU_INSTALL_DIR=${TOOLCHAIN_GNU_INSTALL_DIR}
COPY docker/clone_riscv_gnu_toolchain.sh ./
RUN ./clone_riscv_gnu_toolchain.sh
COPY docker/build_riscv_gnu_toolchain.sh ./
RUN ./build_riscv_gnu_toolchain.sh

# Build pulp-sdk
COPY docker/requirements-pulp-sdk.txt ./
RUN pip3 install --no-cache-dir -r requirements-pulp-sdk.txt
ENV PULP_RISCV_GCC_TOOLCHAIN=${TOOLCHAIN_GNU_INSTALL_DIR}
COPY docker/get_pulp_sdk.sh ./
RUN ./get_pulp_sdk.sh


# Minimal image
FROM ubuntu:22.04

# Needed to have the arguments in the stage
ARG TOOLCHAIN_DIR
ARG TOOLCHAIN_GNU_INSTALL_DIR

RUN DEBIAN_FRONTEND=noninteractive \
apt-get update && \
apt-get upgrade && \
Expand All @@ -8,10 +66,7 @@ RUN DEBIAN_FRONTEND=noninteractive \
ca-certificates \
cmake \
curl \
gcc \
git \
git-lfs \
g++ \
make \
python3 \
python3-pip \
Expand All @@ -24,10 +79,7 @@ COPY requirements-pip.txt docker/requirements-pulp-sdk.txt ./
RUN pip3 install --no-cache-dir -r requirements-pip.txt -r requirements-pulp-sdk.txt --extra-index-url https://download.pytorch.org/whl/cpu

ENV PULP_SDK_HOME="/pulp-sdk"
ENV PULP_RISCV_GCC_TOOLCHAIN="/toolchains/pulp-riscv-gnu-toolchain"

COPY docker/get_pulp_riscv_gnu_toolchain.sh ./
RUN ./get_pulp_riscv_gnu_toolchain.sh
ENV PULP_RISCV_GCC_TOOLCHAIN=${TOOLCHAIN_GNU_INSTALL_DIR}

COPY docker/get_pulp_sdk.sh ./
RUN ./get_pulp_sdk.sh
COPY --from=builder ${TOOLCHAIN_GNU_INSTALL_DIR} ${TOOLCHAIN_GNU_INSTALL_DIR}
COPY --from=builder /pulp-sdk ./
9 changes: 9 additions & 0 deletions test/docker/build_riscv_gnu_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -euo pipefail

# Build and install
mkdir -p $TOOLCHAIN_GNU_INSTALL_DIR
cd riscv-gnu-toolchain
./configure --prefix=$TOOLCHAIN_GNU_INSTALL_DIR --with-arch=rv32imfcxpulpv3 --with-abi=ilp32 --enable-multilib
make
9 changes: 9 additions & 0 deletions test/docker/clone_riscv_gnu_toolchain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -euo pipefail

# Clone and get all submodules except qemu
git clone https://github.com/pulp-platform/riscv-gnu-toolchain.git \
--branch=v2.6.0 --depth=1
cd riscv-gnu-toolchain
git submodule update --init --recursive --depth=1 --recommend-shallow riscv-*

0 comments on commit 8fcd01d

Please sign in to comment.