riscv.Dockerfile 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Usage(on repo root folder):
  2. # docker build . --pull --no-cache --shm-size=196m -t darkfi:riscv -f ./contrib/docker/riscv.Dockerfile -o riscv-bins
  3. # Optionally, add arguments like: --build-arg BINS=darkirc
  4. # If you want to keep building using the same builder, remove --no-cache option.
  5. # Arguments configuration
  6. ARG DEBIAN_VER=latest
  7. ARG SQL_VER=3420000
  8. ARG RUST_VER=nightly
  9. # When changing riscv target, don't forget to also update the linker
  10. ARG RISCV_TARGET=riscv64gc-unknown-linux-gnu
  11. ARG RISCV_LINKER=riscv64-linux-gnu-gcc
  12. # Environment setup
  13. FROM debian:${DEBIAN_VER} as builder
  14. ## Arguments import
  15. ARG SQL_VER
  16. ARG RUST_VER
  17. ARG RISCV_TARGET
  18. ARG RISCV_LINKER
  19. ARG BINS
  20. ## Install system dependencies
  21. RUN apt-get update
  22. RUN apt-get install -y make gcc pkg-config gcc-riscv64-linux-gnu wget
  23. ## Build sqlite3 for Risc-V
  24. RUN wget https://www.sqlite.org/2023/sqlite-autoconf-${SQL_VER}.tar.gz && \
  25. tar xvfz sqlite-autoconf-${SQL_VER}.tar.gz && \
  26. rm sqlite-autoconf-${SQL_VER}.tar.gz && \
  27. mv sqlite-autoconf-${SQL_VER} sqlite3 && \
  28. cd sqlite3 && \
  29. ./configure --host=riscv64-linux-gnu CC=/bin/${RISCV_LINKER} && \
  30. make
  31. ## Rust installation
  32. RUN wget -O install-rustup.sh https://sh.rustup.rs && \
  33. sh install-rustup.sh -yq --default-toolchain none && \
  34. rm install-rustup.sh
  35. ENV PATH "${PATH}:/root/.cargo/bin/"
  36. RUN rustup default "${RUST_VER}"
  37. RUN rustup target add "${RISCV_TARGET}"
  38. # Build binaries
  39. FROM builder as rust_builder
  40. WORKDIR /opt/darkfi
  41. COPY . /opt/darkfi
  42. # Risc-V support is highly experimental so we have to add some hack patches,
  43. # at the end of Cargo.toml where [patch.crates-io] exists.
  44. RUN echo 'ring = {git="https://github.com/aggstam/ring"} \n\
  45. rustls = {git="https://github.com/aggstam/rustls", branch="risc-v"} \n\
  46. rcgen = {git="https://github.com/aggstam/rcgen"} \n\
  47. ' >> /opt/darkfi/Cargo.toml
  48. ENV RUSTFLAGS="-C linker=/bin/${RISCV_LINKER} -L/sqlite3/.libs/"
  49. ENV TARGET_PRFX="--target=" RUST_TARGET="${RISCV_TARGET}"
  50. #TODO: only darkirc and zkas have been tested, have to check rest binaries to add deps and ports.
  51. RUN make ${BINS} && mkdir compiled-bins && \
  52. (if [ -e zkas ]; then cp -a zkas compiled-bins/; fi;) && \
  53. (if [ -e darkfid ]; then cp -a darkfid compiled-bins/; fi;) && \
  54. (if [ -e darkfid2 ]; then cp -a darkfid2 compiled-bins/; fi;) && \
  55. (if [ -e faucetd ]; then cp -a faucetd compiled-bins/; fi;) && \
  56. (if [ -e darkirc ]; then cp -a darkirc compiled-bins/; fi;) && \
  57. (if [ -e "genev-cli" ]; then cp -a genev-cli compiled-bins/; fi;) && \
  58. (if [ -e genevd ]; then cp -a genevd compiled-bins/; fi;) && \
  59. (if [ -e lilith ]; then cp -a lilith compiled-bins/; fi;) && \
  60. (if [ -e "tau-cli" ]; then cp -a tau-cli compiled-bins/; fi;) && \
  61. (if [ -e taud ]; then cp -a taud compiled-bins/; fi;) && \
  62. (if [ -e vanityaddr ]; then cp -a vanityaddr compiled-bins/; fi;)
  63. # Export binaries from rust builder
  64. FROM scratch
  65. COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./