GithubHelp home page GithubHelp logo

Comments (1)

aggstam avatar aggstam commented on September 16, 2024

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

from darkfi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.