From 4cf1c11586fa76f92e77b2c0b756eff5b4f8f100 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Wed, 9 Oct 2024 15:58:15 +0300 Subject: [PATCH] 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, 66 insertions(+), 13 deletions(-) diff --git a/.github/workflows/snapshot-build.yml b/.github/workflows/snapshot-build.yml index 2486bb6693f..d9c17110224 100644 --- a/.github/workflows/snapshot-build.yml +++ b/.github/workflows/snapshot-build.yml @@ -64,7 +64,7 @@ jobs: uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 # v6.9.0 with: file: Dockerfile-${{ matrix.image }} - platforms: linux/amd64,linux/arm64 + platforms: linux/amd64,linux/arm64,linux/riscv64 push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile-bootstrap-node b/Dockerfile-bootstrap-node index 8e7e62949f2..c7803064d57 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 0b9ee87dc40..b06e611b405 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 48c71ca580e..27b0934bb08 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 463cbbae6cd..a67841e3230 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 \