From 0320a6ce02649b21715a63e0eced1ab6eb72dfc1 Mon Sep 17 00:00:00 2001 From: aggstam Date: Thu, 7 Sep 2023 19:07:42 +0300 Subject: [PATCH] contrib/docker: riscv builder added(highly experimental) --- .gitignore | 1 + contrib/docker/riscv.Dockerfile | 76 +++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 contrib/docker/riscv.Dockerfile diff --git a/.gitignore b/.gitignore index 527b67fe3..363d497ac 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ /darkwiki /darkwikid /zktool +/riscv-bins # tags, ctags, rusty-tags TAGS diff --git a/contrib/docker/riscv.Dockerfile b/contrib/docker/riscv.Dockerfile new file mode 100644 index 000000000..db9430cb5 --- /dev/null +++ b/contrib/docker/riscv.Dockerfile @@ -0,0 +1,76 @@ +# Usage(on repo root folder): +# docker build . --pull --no-cache --shm-size=196m -t darkfi:riscv -f ./contrib/docker/riscv.Dockerfile -o riscv-bins +# Optionally, add arguments like: --build-arg BINS=darkirc +# 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=nightly +# 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, +# at the end of Cargo.toml where [patch.crates-io] exists. +RUN echo '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\ +' >> /opt/darkfi/Cargo.toml + +ENV RUSTFLAGS="-C linker=/bin/${RISCV_LINKER} -L/sqlite3/.libs/" +ENV TARGET_PRFX="--target=" RUST_TARGET="${RISCV_TARGET}" +#TODO: only darkirc and zkas have been tested, have to check rest binaries to add deps and ports. +RUN make ${BINS} && mkdir compiled-bins && \ + (if [ -e zkas ]; then cp -a zkas compiled-bins/; fi;) && \ + (if [ -e darkfid ]; then cp -a darkfid compiled-bins/; fi;) && \ + (if [ -e darkfid2 ]; then cp -a darkfid2 compiled-bins/; fi;) && \ + (if [ -e faucetd ]; then cp -a faucetd compiled-bins/; fi;) && \ + (if [ -e darkirc ]; then cp -a darkirc compiled-bins/; fi;) && \ + (if [ -e "genev-cli" ]; then cp -a genev-cli compiled-bins/; fi;) && \ + (if [ -e genevd ]; then cp -a genevd compiled-bins/; fi;) && \ + (if [ -e lilith ]; then cp -a lilith compiled-bins/; fi;) && \ + (if [ -e "tau-cli" ]; then cp -a tau-cli compiled-bins/; fi;) && \ + (if [ -e taud ]; then cp -a taud compiled-bins/; fi;) && \ + (if [ -e vanityaddr ]; then cp -a vanityaddr compiled-bins/; fi;) + +# Export binaries from rust builder +FROM scratch +COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./