riscv.Dockerfile 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #TODO: only darkirc has been tested, have to check rest binaries to add deps and ports.
  10. ARG BINS=darkirc
  11. # When changing riscv target, don't forget to also update the linker
  12. ARG RISCV_TARGET=riscv64gc-unknown-linux-gnu
  13. ARG RISCV_LINKER=riscv64-linux-gnu-gcc
  14. # Environment setup
  15. FROM debian:${DEBIAN_VER} as builder
  16. ## Arguments import
  17. ARG SQL_VER
  18. ARG RUST_VER
  19. ARG RISCV_TARGET
  20. ARG RISCV_LINKER
  21. ARG BINS
  22. ## Install system dependencies
  23. RUN apt-get update
  24. RUN apt-get install -y make gcc pkg-config gcc-riscv64-linux-gnu wget
  25. ## Build sqlite3 for Risc-V
  26. RUN wget https://www.sqlite.org/2023/sqlite-autoconf-${SQL_VER}.tar.gz && \
  27. tar xvfz sqlite-autoconf-${SQL_VER}.tar.gz && \
  28. rm sqlite-autoconf-${SQL_VER}.tar.gz && \
  29. mv sqlite-autoconf-${SQL_VER} sqlite3 && \
  30. cd sqlite3 && \
  31. ./configure --host=riscv64-linux-gnu CC=/bin/${RISCV_LINKER} && \
  32. make
  33. ## Rust installation
  34. RUN wget -O install-rustup.sh https://sh.rustup.rs && \
  35. sh install-rustup.sh -yq --default-toolchain none && \
  36. rm install-rustup.sh
  37. ENV PATH "${PATH}:/root/.cargo/bin/"
  38. RUN rustup default ${RUST_VER}
  39. RUN rustup target add ${RISCV_TARGET}
  40. # Build binaries
  41. FROM builder as rust_builder
  42. WORKDIR /opt/darkfi
  43. COPY . /opt/darkfi
  44. # Risc-V support is highly experimental so we have to add some hack patches,
  45. # at the end of Cargo.toml where [patch.crates-io] exists.
  46. RUN echo 'ring = {git="https://github.com/aggstam/ring"} \n\
  47. rustls = {git="https://github.com/aggstam/rustls", branch="risc-v"} \n\
  48. rcgen = {git="https://github.com/aggstam/rcgen"} \n\
  49. ' >> Cargo.toml
  50. RUN sed -i Cargo.toml -e "s|0.11.3|0.11.1|g"
  51. # Add hacked dependencies into each crate that uses them
  52. RUN sed -i bin/darkirc/Cargo.toml \
  53. -e "s|\[dependencies\]|\[dependencies\]\nring = \"0.16.20\"|g"
  54. RUN cargo update
  55. ENV RUSTFLAGS="-C linker=/bin/${RISCV_LINKER} -L/sqlite3/.libs/"
  56. ENV TARGET_PRFX="--target=" RUST_TARGET="${RISCV_TARGET}"
  57. RUN make ${BINS} && mkdir compiled-bins && \
  58. (if [ -e zkas ]; then cp -a zkas compiled-bins/; fi;) && \
  59. (if [ -e darkfid ]; then cp -a darkfid compiled-bins/; fi;) && \
  60. (if [ -e faucetd ]; then cp -a faucetd compiled-bins/; fi;) && \
  61. (if [ -e darkirc ]; then cp -a darkirc compiled-bins/; fi;) && \
  62. (if [ -e "genev-cli" ]; then cp -a genev-cli compiled-bins/; fi;) && \
  63. (if [ -e genevd ]; then cp -a genevd compiled-bins/; fi;) && \
  64. (if [ -e lilith ]; then cp -a lilith compiled-bins/; fi;) && \
  65. (if [ -e "tau-cli" ]; then cp -a tau-cli compiled-bins/; fi;) && \
  66. (if [ -e taud ]; then cp -a taud compiled-bins/; fi;) && \
  67. (if [ -e vanityaddr ]; then cp -a vanityaddr compiled-bins/; fi;)
  68. # Export binaries from rust builder
  69. FROM scratch
  70. COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./