Skip to content

Commit

Permalink
Add support for RISC-V code cross compilation test
Browse files Browse the repository at this point in the history
Add steps needed for RISC-V specific code to cross-compile.

Signed-off-by: Ruoqing He <[email protected]>
  • Loading branch information
TimePrinciple committed May 16, 2024
1 parent 30fa4e3 commit 1521c36
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ ARG RUST_TOOLCHAIN="1.75.0"

# Adding rust binaries to PATH.
ENV PATH="$PATH:/root/.cargo/bin"
# Adding riscv cross compilation toolchain to PATH.
ENV PATH="$PATH:/opt/riscv/bin"

COPY build_container.sh /opt/src/scripts/build_container.sh
RUN /opt/src/scripts/build_container.sh
25 changes: 24 additions & 1 deletion build_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
autoconf autoconf-archive automake libtool \
libclang-dev iproute2 \
libasound2 libasound2-dev \
debhelper-compat libdbus-1-dev libglib2.0-dev meson ninja-build dbus
debhelper-compat libdbus-1-dev libglib2.0-dev meson ninja-build dbus \

# Needed for x86_64 to cross compile RISC-V code
if [ "$ARCH" = "x86_64" ]; then
DEBIAN_FRONTEND="noninteractive" apt-get install --no-install-recommends -y \
autotools-dev libmpc-dev libmpfr-dev libgmp-dev gawk build-essential \
texinfo gperf patchutils zlib1g-dev libexpat-dev libslirp-dev \
qemu-user-static
fi

# cleanup
apt-get clean && rm -rf /var/lib/apt/lists/*
Expand Down Expand Up @@ -47,6 +55,8 @@ rustup component add llvm-tools-preview # needed for coverage

# Install other rust targets.
rustup target add $ARCH-unknown-linux-musl $ARCH-unknown-none
# For riscv64 cross-compilation
rustup target add riscv64gc-unknown-linux-gnu

cargo install cargo-llvm-cov

Expand All @@ -70,5 +80,18 @@ rm -rf pipewire-0.3.71
rm pipewire-0.3.71.tar.gz
popd

# Install RISC-V GNU Compiler Toolchain for riscv cross-compilation
if [ "$ARCH" = "x86_64" ]; then
pushd /opt
git clone https://github.com/riscv/riscv-gnu-toolchain
pushd riscv-gnu-toolchain
mkdir /opt/riscv
./configure --prefix=/opt/riscv
make linux
popd
rm -rf riscv-gnu-toolchain
popd
fi

# dbus-daemon expects this folder
mkdir /run/dbus

0 comments on commit 1521c36

Please sign in to comment.