darkrenaissance / darkfi

Anonymous. Uncensored. Sovereign.

Home Page:https://dark.fi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not working on RISCV boards such as VisionFiveV2 because of ring dependency set low on some package

sdanfa opened this issue · comments

Hello,

One of the packges that are pulled when doing make ircd, it fails with ring package error since it's trying to use V0.16.x instead of V.0.17.X. Can you please fix this somehow? I would like to run ircd on riscv architecture. Everything else builds fine but fails at this.

Thanks!

Hello,

RISC-V support is highly experimental and we only actively develop for it on master branch, so don't expect future support on older tags.
For reference on how to build binaries for RISC-V you can check this docker build file.
If you are developing on a native RISC-V environment, you will find every step needed, like compiling sqlite and linking it to rust compile, to properly build for it.

For tag/v0.4.1/ircd you can use the following docker file using this steps:

  1. cargo clean on repo root folder
  2. save the file as ircd-riscv.Dockerfile inside contrib/docker
  3. build on repo root folder: docker build . --pull --no-cache --shm-size=196m -t darkfi:ircd-riscv -f ./contrib/docker/ircd-riscv.Dockerfile -o riscv-bins

No need to touch anything else.

ircd-riscv.Dockerfile:

# Usage(on repo root folder):
#   docker build . --pull --no-cache --shm-size=196m -t darkfi:ircd-riscv -f ./contrib/docker/ircd-riscv.Dockerfile -o riscv-bins
# If you want to keep building using the same builder, remove --no-cache option.

# Arguments configuration
ARG DEBIAN_VER=latest
ARG SQL_VER=3420000
ARG RUST_VER=stable
# When changing riscv target, don't forget to also update the linker
ARG RISCV_TARGET=riscv64gc-unknown-linux-gnu
ARG RISCV_LINKER=riscv64-linux-gnu-gcc

# Environment setup
FROM debian:${DEBIAN_VER} as builder

## Arguments import
ARG SQL_VER
ARG RUST_VER
ARG RISCV_TARGET
ARG RISCV_LINKER
ARG BINS

## Install system dependencies
RUN apt-get update
RUN apt-get install -y make gcc pkg-config gcc-riscv64-linux-gnu wget

## Build sqlite3 for Risc-V
RUN wget https://www.sqlite.org/2023/sqlite-autoconf-${SQL_VER}.tar.gz && \
    tar xvfz sqlite-autoconf-${SQL_VER}.tar.gz && \
    rm sqlite-autoconf-${SQL_VER}.tar.gz && \
    mv sqlite-autoconf-${SQL_VER} sqlite3 && \
    cd sqlite3 && \
    ./configure --host=riscv64-linux-gnu CC=/bin/${RISCV_LINKER} && \
    make

## Rust installation
RUN wget -O install-rustup.sh https://sh.rustup.rs && \
    sh install-rustup.sh -yq --default-toolchain none && \
    rm install-rustup.sh
ENV PATH "${PATH}:/root/.cargo/bin/"
RUN rustup default "${RUST_VER}"
RUN rustup target add "${RISCV_TARGET}"

# Build binaries
FROM builder as rust_builder

WORKDIR /opt/darkfi
COPY . /opt/darkfi

# Risc-V support is highly experimental so we have to add some hack patches.
RUN echo '[patch.crates-io] \n\
ring = {git="https://github.com/aggstam/ring"} \n\
rustls = {git="https://github.com/aggstam/rustls", branch="risc-v"} \n\
rcgen = {git="https://github.com/aggstam/rcgen"} \n\
' >> Cargo.toml
RUN sed -i Cargo.toml \
    -e """s|\[dependencies\]|\[dependencies\]\n\
    rustls = \"0.21.7\"\n\
    ring = \"0.16.20\"|g""" \
    -e "s|0.10.0|0.11.1|g" \
    -e "s|0.22.2|0.24.0|g"
RUN sed -i src/net/transport/upgrade_tls.rs \
    -e "s|DistinguishedNames|DistinguishedName|g" \
    -e "s|Option<DistinguishedName>|\&\[DistinguishedName]|g" \
    -e "s|Some(vec!\[\])|\&\[\]|g"
RUN cargo update

WORKDIR /opt/darkfi/bin/ircd
RUN sed -i Cargo.toml -e "s|0.22.2|0.24.0|g"
ENV RUSTFLAGS="-C linker=/bin/${RISCV_LINKER} -L/sqlite3/.libs/"
RUN RUSTFLAGS="${RUSTFLAGS}" cargo build --target=${RISCV_TARGET} --all-features --release

WORKDIR /opt/darkfi
RUN mkdir compiled-bins && cp target/${RISCV_TARGET}/release/ircd compiled-bins/ircd

# Export binaries from rust builder
FROM scratch
COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./

Builded binary will work without issues, as I constantly test it on a RISC-V board.
Let me know if you require extra help and/or information!

KR