From ddfcce3988b33ea5a3dd8eb70dae115666159476 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 9 Oct 2024 15:58:15 +0300 Subject: [PATCH 1/2] Add riscv64 support --- .github/workflows/snapshot-build.yml | 2 ++ Dockerfile-bootstrap-node | 13 +++++++++- Dockerfile-farmer | 38 +++++++++++++++++++++------- Dockerfile-node | 13 +++++++++- Dockerfile-runtime | 13 +++++++++- 5 files changed, 67 insertions(+), 12 deletions(-) diff --git a/.github/workflows/snapshot-build.yml b/.github/workflows/snapshot-build.yml index 2486bb6693..6cf7804ae9 100644 --- a/.github/workflows/snapshot-build.yml +++ b/.github/workflows/snapshot-build.yml @@ -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 }} diff --git a/Dockerfile-bootstrap-node b/Dockerfile-bootstrap-node index 8e7e62949f..c7803064d5 100644 --- a/Dockerfile-bootstrap-node +++ b/Dockerfile-bootstrap-node @@ -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 @@ -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 \ diff --git a/Dockerfile-farmer b/Dockerfile-farmer index 0b9ee87dc4..9d67ffd4f5 100644 --- a/Dockerfile-farmer +++ b/Dockerfile-farmer @@ -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 @@ -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 \ @@ -111,13 +122,22 @@ 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 diff --git a/Dockerfile-node b/Dockerfile-node index 48c71ca580..27b0934bb0 100644 --- a/Dockerfile-node +++ b/Dockerfile-node @@ -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 @@ -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 \ diff --git a/Dockerfile-runtime b/Dockerfile-runtime index 463cbbae6c..a67841e323 100644 --- a/Dockerfile-runtime +++ b/Dockerfile-runtime @@ -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 @@ -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 \ From a4845b40afca4d7f9604c8e10baaf77131d1a533 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 9 Oct 2024 17:26:04 +0300 Subject: [PATCH 2/2] Fix ROCm libraries installation in a container --- Dockerfile-farmer | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile-farmer b/Dockerfile-farmer index 9d67ffd4f5..3175abe62e 100644 --- a/Dockerfile-farmer +++ b/Dockerfile-farmer @@ -143,6 +143,9 @@ RUN \ 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