Skip to content

Commit

Permalink
Merge pull request #3109 from autonomys/riscv64-support
Browse files Browse the repository at this point in the history
Add riscv64 support
  • Loading branch information
nazar-pc authored Oct 9, 2024
2 parents 8f12ce4 + a4845b4 commit bda8801
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/snapshot-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ jobs:
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0
with:
file: Dockerfile-${{ matrix.image }}
# TODO: Add `linux/riscv64` once https://github.com/paritytech/polkadot-sdk/issues/5996 is resolved and ring
# 0.16.x is no longer in dependencies
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
13 changes: 12 additions & 1 deletion Dockerfile-bootstrap-node
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ RUN \
libc6-dev-arm64-cross \
; fi

RUN \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
g++-riscv64-linux-gnu \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
; fi

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION && \
/root/.cargo/bin/rustup target add wasm32-unknown-unknown
Expand All @@ -54,10 +62,13 @@ RUN \
if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=aarch64-linux-gnu-gcc" \
; fi && \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=riscv64-linux-gnu-gcc" \
; fi && \
if [ $TARGETARCH = "amd64" ] && [ $RUSTFLAGS = ""]; then \
export RUSTFLAGS="-C target-cpu=skylake" \
; fi && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g") && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g" | sed "s/riscv64/riscv64gc/g") && \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
Expand Down
41 changes: 32 additions & 9 deletions Dockerfile-farmer
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ RUN \
libc6-dev-arm64-cross \
; fi

RUN \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
g++-riscv64-linux-gnu \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
; fi

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION && \
/root/.cargo/bin/rustup target add wasm32-unknown-unknown
Expand Down Expand Up @@ -96,11 +104,14 @@ RUN \
if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=aarch64-linux-gnu-gcc" \
; fi && \
if [ $TARGETARCH = "amd64" ] && [ $RUSTFLAGS = ""]; then \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=riscv64-linux-gnu-gcc" \
; fi && \
if [ $TARGETARCH = "amd64" ] && [ $RUSTFLAGS = "" ]; then \
export RUSTFLAGS="-C target-cpu=skylake" \
; fi && \
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}} && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g") && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g" | sed "s/riscv64/riscv64gc/g") && \
if [ $BUILDARCH = "amd64" ] && [ $TARGETARCH = "amd64" ]; then \
NVCC=off /root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
Expand All @@ -111,18 +122,30 @@ RUN \
--target $RUSTC_TARGET_ARCH-unknown-linux-gnu && \
mv target/*/*/subspace-farmer subspace-farmer-rocm \
; fi && \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
--profile $PROFILE \
--bin subspace-farmer \
--features cuda \
--target $RUSTC_TARGET_ARCH-unknown-linux-gnu && \
if [ $(which nvcc) ]; then \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
--profile $PROFILE \
--bin subspace-farmer \
--features cuda \
--target $RUSTC_TARGET_ARCH-unknown-linux-gnu \
; else \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
--profile $PROFILE \
--bin subspace-farmer \
--target $RUSTC_TARGET_ARCH-unknown-linux-gnu \
; fi && \
mv target/*/*/subspace-farmer subspace-farmer && \
rm -rf target

FROM ubuntu:22.04

ARG BUILDARCH
ARG TARGETARCH

# Next block is for ROCm support
# ROCm is only used on x86-64 since they don't have other packages
ARG ROCM_VERSION=6.2.2
Expand Down
13 changes: 12 additions & 1 deletion Dockerfile-node
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ RUN \
libc6-dev-arm64-cross \
; fi

RUN \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
g++-riscv64-linux-gnu \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
; fi

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION && \
/root/.cargo/bin/rustup target add wasm32-unknown-unknown
Expand All @@ -56,10 +64,13 @@ RUN \
if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=aarch64-linux-gnu-gcc" \
; fi && \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=riscv64-linux-gnu-gcc" \
; fi && \
if [ $TARGETARCH = "amd64" ] && [ $RUSTFLAGS = ""]; then \
export RUSTFLAGS="-C target-cpu=skylake" \
; fi && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g") && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g" | sed "s/riscv64/riscv64gc/g") && \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
Expand Down
13 changes: 12 additions & 1 deletion Dockerfile-runtime
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ RUN \
libc6-dev-arm64-cross \
; fi

RUN \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
g++-riscv64-linux-gnu \
gcc-riscv64-linux-gnu \
libc6-dev-riscv64-cross \
; fi

RUN \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain $RUSTC_VERSION && \
/root/.cargo/bin/rustup target add wasm32-unknown-unknown
Expand All @@ -54,10 +62,13 @@ RUN \
if [ $BUILDARCH != "arm64" ] && [ $TARGETARCH = "arm64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=aarch64-linux-gnu-gcc" \
; fi && \
if [ $BUILDARCH != "riscv64" ] && [ $TARGETARCH = "riscv64" ]; then \
export RUSTFLAGS="$RUSTFLAGS -C linker=riscv64-linux-gnu-gcc" \
; fi && \
if [ $TARGETARCH = "amd64" ] && [ $RUSTFLAGS = ""]; then \
export RUSTFLAGS="-C target-cpu=skylake" \
; fi && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g") && \
RUSTC_TARGET_ARCH=$(echo $TARGETARCH | sed "s/amd64/x86_64/g" | sed "s/arm64/aarch64/g" | sed "s/riscv64/riscv64gc/g") && \
/root/.cargo/bin/cargo -Zgitoxide -Zgit build \
--locked \
-Z build-std \
Expand Down

0 comments on commit bda8801

Please sign in to comment.