Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multistage gcc build to docker #13

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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-*
Loading