riscv.Dockerfile 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # This script uses QEMU emulation, so before execution pull the corresponding
  2. # images:
  3. # docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
  4. # Usage(on repo root folder):
  5. # docker build . --platform=linux/riscv64 --pull --no-cache --shm-size=196m -t darkfi:riscv -f ./contrib/docker/riscv2.Dockerfile -o riscv-bins
  6. # Optionally, add arguments like: --build-arg BINS=darkirc
  7. # If you want to keep building using the same builder, remove --no-cache option.
  8. # Arguments configuration
  9. ARG DEBIAN_VER=sid
  10. ARG RUST_VER=nightly-2025-04-10
  11. #TODO: only darkirc has been tested, have to check rest binaries to add deps and ports.
  12. ARG BINS=darkirc
  13. # Environment setup
  14. FROM --platform=$TARGETPLATFORM riscv64/debian:${DEBIAN_VER} as builder
  15. ## Arguments import
  16. ARG RUST_VER
  17. ARG BINS
  18. ## Install system dependencies
  19. RUN apt-get update
  20. RUN apt-get install -y git cmake make gcc g++ pkg-config \
  21. libasound2-dev libclang-dev libssl-dev libsqlcipher-dev \
  22. libsqlite3-dev wabt wget
  23. ## Rust installation
  24. RUN wget -O install-rustup.sh https://sh.rustup.rs && \
  25. sh install-rustup.sh -yq --default-toolchain none && \
  26. rm install-rustup.sh
  27. ENV PATH "${PATH}:/root/.cargo/bin/"
  28. RUN rustup default ${RUST_VER}
  29. RUN rustup target add wasm32-unknown-unknown --toolchain ${RUST_VER}
  30. # Build binaries
  31. FROM builder as rust_builder
  32. WORKDIR /opt/darkfi
  33. COPY . /opt/darkfi
  34. # Cleanup existing binaries
  35. RUN rm -rf zkas bin/zkas/zkas darkfid bin/darkfid/darkfid \
  36. darkirc bin/darkirc/darkirc lilith bin/lilith/lilith \
  37. taud bin/tau/taud/taud vanityaddr bin/vanityaddr/vanityaddr
  38. # Risc-V support is highly experimental so we have to add some hack patches
  39. # at Cargo.toml where [patch.crates-io] exists.
  40. RUN sed -i Cargo.toml -e '335iring = {git="https://github.com/aggstam/ring"} \n\
  41. rustls = {git="https://github.com/aggstam/rustls", branch="risc-v"} \n\
  42. rcgen = {git="https://github.com/aggstam/rcgen"} \n'
  43. # Add hacked dependencies into each crate that uses them
  44. RUN sed -i bin/darkirc/Cargo.toml \
  45. -e "s|\[dependencies\]|\[dependencies\]\nring = \"0.16.20\"|g"
  46. RUN cargo +${RUST_VER} update
  47. RUN sed -i rust-toolchain.toml -e "s|nightly|${RUST_VER}|g"
  48. RUN make CARGO="cargo +${RUST_VER}" ${BINS} && \
  49. mkdir compiled-bins && \
  50. (if [ -e zkas ]; then cp -a zkas compiled-bins/; fi;) && \
  51. (if [ -e darkfid ]; then cp -a darkfid compiled-bins/; fi;) && \
  52. (if [ -e darkirc ]; then cp -a darkirc compiled-bins/; fi;) && \
  53. (if [ -e lilith ]; then cp -a lilith compiled-bins/; fi;) && \
  54. (if [ -e taud ]; then cp -a taud compiled-bins/; fi;) && \
  55. (if [ -e vanityaddr ]; then cp -a vanityaddr compiled-bins/; fi;)
  56. # Export binaries from rust builder
  57. FROM scratch
  58. COPY --from=rust_builder /opt/darkfi/compiled-bins/* ./